Add validation and unit tests AffineGrid
Merged
YU
8mo ago+220+220+012345678901234567890123456789-20-20-01234567890123456789
Description
This pull request improves the robustness and correctness of the AffineGrid operator in ONNX Runtime by adding stricter input validation and updating the implementation for better type safety. It also introduces comprehensive unit tests to verify error handling for invalid inputs.
Input validation enhancements
- Added explicit checks in
affine_grid.ccto ensure that the batch dimension insizematches the batch dimension intheta, and thatthetahas the correct shape for both 2D ([N, 2, 3]) and 3D ([N, 3, 4]) cases. This prevents silent errors due to shape mismatches. [1] [2]
Type safety and code clarity improvements
- Updated grid generation functions to use the template type
Tfor Eigen vector creation, replacing hardcodedfloattypes. This ensures correct behavior for different data types and improves code clarity. [1] [2] - Added clarifying comments to matrix and array initializations in affine grid generator functions to make the code easier to understand and maintain.
Test coverage improvements
- Added a series of unit tests in
affine_grid_test.ccto validate input shape checks, including cases for incorrect tensor dimensions, mismatched batch sizes, and invalidsizelengths. These tests ensure that the operator fails gracefully with informative error messages when given invalid inputs. - Ensured the required test utility header is included to support new tests.
Code cleanup
- Removed unused includes from
affine_grid.ccto tidy up the codebase.