Fix GatherND division by zero when batch dimensions mismatch (#27090)
Fixes #23828
Added validation to check:
- num_batches is not zero
- num_slices is divisible by num_batches
Before this fix, mismatched batch dimensions caused a crash due to
division by zero.
### Description
<!-- Describe your changes. -->
This PR fixes a division by zero crash in the GatherND operator when
batch dimensions mismatch between input and indices tensors.
Changes made:
Added validation in gather_nd.cc to check that num_batches is not zero
before division
Added validation that num_slices is divisible by num_batches
Added a unit test to verify the fix
### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
Description
Fixes #23828
When batch_dims is set but the actual batch dimensions of the input
tensor and indices tensor don't align correctly, the code performs a
division that can result in division by zero, causing a crash.
For example, with:
Input shape: [2, 2, 2]
Indices shape: [2, 1]
batch_dims=1
The calculation num_slices / num_batches would crash if num_batches is
0, or produce unexpected results if they don't divide evenly.
This fix returns a clear error message instead of crashing.
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>