From 55385a43291294c4b3c833ae5f992b47d0703a43 Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Thu, 5 Mar 2026 15:10:43 -0800 Subject: [PATCH 1/6] Add validation and unit tests --- .../core/providers/cpu/tensor/affine_grid.cc | 52 +++++++---- .../providers/cpu/tensor/affine_grid_test.cc | 91 +++++++++++++++++++ 2 files changed, 124 insertions(+), 19 deletions(-) diff --git a/onnxruntime/core/providers/cpu/tensor/affine_grid.cc b/onnxruntime/core/providers/cpu/tensor/affine_grid.cc index 15900ba553983..83762f7ef91ab 100644 --- a/onnxruntime/core/providers/cpu/tensor/affine_grid.cc +++ b/onnxruntime/core/providers/cpu/tensor/affine_grid.cc @@ -6,8 +6,6 @@ #include "core/common/common.h" #include "core/providers/op_kernel_type_control.h" #include "core/util/math_cpuonly.h" -#include -#include "Eigen/src/Core/Map.h" #include #include "core/common/eigen_common_wrapper.h" @@ -28,13 +26,14 @@ REGISTER_KERNEL_TYPED(double) template void generate_base_grid_2d(int64_t H, int64_t W, bool align_corners, Eigen::Matrix& base_grid) { - Eigen::VectorXf row_vec = Eigen::VectorXf::LinSpaced(static_cast(W), -1, 1); + using VectorT = Eigen::Matrix; + VectorT row_vec = VectorT::LinSpaced(static_cast(W), static_cast(-1), static_cast(1)); if (!align_corners) { - row_vec = row_vec * (W - 1) / W; + row_vec = row_vec * static_cast(W - 1) / static_cast(W); } - Eigen::VectorXf col_vec = Eigen::VectorXf::LinSpaced(static_cast(H), -1, 1); + VectorT col_vec = VectorT::LinSpaced(static_cast(H), static_cast(-1), static_cast(1)); if (!align_corners) { - col_vec = col_vec * (H - 1) / H; + col_vec = col_vec * static_cast(H - 1) / static_cast(H); } base_grid.resize(static_cast(H * W), 2); @@ -47,17 +46,18 @@ void generate_base_grid_2d(int64_t H, int64_t W, bool align_corners, Eigen::Matr template void generate_base_grid_3d(int64_t D, int64_t H, int64_t W, bool align_corners, Eigen::Matrix& base_grid) { - Eigen::VectorXf row_vec = Eigen::VectorXf::LinSpaced(static_cast(W), -1, 1); + using VectorT = Eigen::Matrix; + VectorT row_vec = VectorT::LinSpaced(static_cast(W), static_cast(-1), static_cast(1)); if (!align_corners) { - row_vec = row_vec * (W - 1) / W; + row_vec = row_vec * static_cast(W - 1) / static_cast(W); } - Eigen::VectorXf col_vec = Eigen::VectorXf::LinSpaced(static_cast(H), -1, 1); + VectorT col_vec = VectorT::LinSpaced(static_cast(H), static_cast(-1), static_cast(1)); if (!align_corners) { - col_vec = col_vec * (H - 1) / H; + col_vec = col_vec * static_cast(H - 1) / static_cast(H); } - Eigen::VectorXf slice_vec = Eigen::VectorXf::LinSpaced(static_cast(D), -1, 1); + VectorT slice_vec = VectorT::LinSpaced(static_cast(D), static_cast(-1), static_cast(1)); if (!align_corners) { - slice_vec = slice_vec * (D - 1) / D; + slice_vec = slice_vec * static_cast(D - 1) / static_cast(D); } base_grid.resize(static_cast(D * H * W), 3); @@ -75,13 +75,13 @@ void affine_grid_generator_2d(const Tensor* theta, const Eigen::MatrixData() + theta_batch_offset; - const Eigen::Matrix theta_R{{theta_data[0], theta_data[1]}, {theta_data[3], theta_data[4]}}; - const Eigen::Array theta_T(theta_data[2], theta_data[5]); + const Eigen::Matrix theta_R{{theta_data[0], theta_data[1]}, {theta_data[3], theta_data[4]}}; // 2x2 + const Eigen::Array theta_T(theta_data[2], theta_data[5]); // 2x1 auto grid_batch_offset = batch_num * H * W * 2; T* grid_data = grid->MutableData() + grid_batch_offset; Eigen::Map> grid_matrix(grid_data, narrow(H * W), 2); - grid_matrix = ((theta_R * base_grid_transposed).array().colwise() + theta_T).matrix().transpose(); + grid_matrix = ((theta_R * base_grid_transposed).array().colwise() + theta_T).matrix().transpose(); //(2x2 * 2xN).colwise() + 2x1).transpose() } template @@ -89,11 +89,13 @@ void affine_grid_generator_3d(const Tensor* theta, const Eigen::MatrixData() + theta_batch_offset; + const Eigen::Matrix theta_R{ {theta_data[0], theta_data[1], theta_data[2]}, {theta_data[4], theta_data[5], theta_data[6]}, - {theta_data[8], theta_data[9], theta_data[10]}}; - const Eigen::Array theta_T(theta_data[3], theta_data[7], theta_data[11]); + {theta_data[8], theta_data[9], theta_data[10]}}; // 3x3 + + const Eigen::Array theta_T(theta_data[3], theta_data[7], theta_data[11]); // 3x1 auto grid_batch_offset = batch_num * D * H * W * 3; T* grid_data = grid->MutableData() + grid_batch_offset; @@ -113,9 +115,15 @@ Status AffineGrid::Compute(OpKernelContext* context) const { const TensorShape& size_shape = size->Shape(); const int64_t* size_data = size->Data(); - if (size_shape.GetDims()[0] == 4 /*&& get_check_2d_grid_sample_consistency(theta_shape, size_shape, N, C, H, W)*/) { + if (size_shape.GetDims()[0] == 4) { int64_t N = size_data[0], H = size_data[2], W = size_data[3]; + ORT_RETURN_IF(N != theta_shape[0], + "AffineGrid: size[0] (", N, ") must equal theta batch dimension (", theta_shape[0], ")"); + ORT_RETURN_IF(theta_shape[1] != 2 || theta_shape[2] != 3, + "AffineGrid: theta shape must be [N, 2, 3] for 2D, got [", + theta_shape[0], ", ", theta_shape[1], ", ", theta_shape[2], "]"); + TensorShape grid_shape{N, H, W, 2}; auto grid = context->Output(0, grid_shape); @@ -128,9 +136,15 @@ Status AffineGrid::Compute(OpKernelContext* context) const { }; concurrency::ThreadPool::TryBatchParallelFor(context->GetOperatorThreadPool(), narrow(N), std::move(fn), 0); - } else if (size_shape.GetDims()[0] == 5 /*&& get_check_2d_grid_sample_consistency(theta_shape, size_shape, N, C, H, W)*/) { + } else if (size_shape.GetDims()[0] == 5) { int64_t N = size_data[0], D = size_data[2], H = size_data[3], W = size_data[4]; + ORT_RETURN_IF(N != theta_shape[0], + "AffineGrid: size[0] (", N, ") must equal theta batch dimension (", theta_shape[0], ")"); + ORT_RETURN_IF(theta_shape[1] != 3 || theta_shape[2] != 4, + "AffineGrid: theta shape must be [N, 3, 4] for 3D, got [", + theta_shape[0], ", ", theta_shape[1], ", ", theta_shape[2], "]"); + TensorShape grid_shape{N, D, H, W, 3}; auto grid = context->Output(0, grid_shape); diff --git a/onnxruntime/test/providers/cpu/tensor/affine_grid_test.cc b/onnxruntime/test/providers/cpu/tensor/affine_grid_test.cc index 1ffe6c73d4fa4..747accd7dc8a2 100644 --- a/onnxruntime/test/providers/cpu/tensor/affine_grid_test.cc +++ b/onnxruntime/test/providers/cpu/tensor/affine_grid_test.cc @@ -4,6 +4,7 @@ #include "core/util/math.h" #include "gtest/gtest.h" #include "test/providers/provider_test_utils.h" +#include "test/unittest_util/op_tester.h" // Ensure this include is present namespace onnxruntime { namespace test { @@ -178,5 +179,95 @@ TEST(AffineGridTest, test_3d_7) { test.SetOutputTolerance(0.0001f); test.Run(); } + +// Validation tests for input shape checks + +// Test: theta must be a 3D tensor +TEST(AffineGridTest, invalid_theta_not_3d) { + OpTester test("AffineGrid", 20); + // theta is 2D instead of 3D + test.AddInput("theta", {2, 6}, {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}); + test.AddInput("size", {4}, {2, 1, 2, 3}); + test.AddOutput("grid", {2, 2, 3, 2}, std::vector(24, 0.0f)); + test.Run(OpTester::ExpectResult::kExpectFailure, "AffineGrid : Input theta tensor dimension is not 3"); +} + +// Test: size length must be 4 or 5 +TEST(AffineGridTest, invalid_size_length_3) { + OpTester test("AffineGrid", 20); + test.AddInput("theta", {1, 2, 3}, {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}); + test.AddInput("size", {3}, {1, 1, 2}); + test.AddOutput("grid", {1, 2, 2}, std::vector(4, 0.0f)); + test.Run(OpTester::ExpectResult::kExpectFailure, "Length of input 'size' is 3. It must be 4 for 2D or 5 for 5D"); +} + +// Test: size length must be 4 or 5 (too long) +TEST(AffineGridTest, invalid_size_length_6) { + OpTester test("AffineGrid", 20); + test.AddInput("theta", {1, 2, 3}, {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}); + test.AddInput("size", {6}, {1, 1, 2, 3, 4, 5}); + test.AddOutput("grid", {1, 2, 3, 2}, std::vector(12, 0.0f)); + test.Run(OpTester::ExpectResult::kExpectFailure, "Length of input 'size' is 6. It must be 4 for 2D or 5 for 5D"); +} + +// Test: 2D - batch dimension mismatch between theta and size +TEST(AffineGridTest, invalid_2d_batch_mismatch) { + OpTester test("AffineGrid", 20); + // theta has N=1, but size has N=2 + test.AddInput("theta", {1, 2, 3}, {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}); + test.AddInput("size", {4}, {2, 1, 2, 3}); + test.AddOutput("grid", {2, 2, 3, 2}, std::vector(24, 0.0f)); + test.Run(OpTester::ExpectResult::kExpectFailure, "must equal theta batch dimension"); +} + +// Test: 2D - theta shape must be [N, 2, 3], wrong second dimension +TEST(AffineGridTest, invalid_2d_theta_wrong_dim1) { + OpTester test("AffineGrid", 20); + // theta is [1, 3, 3] but for 2D it must be [N, 2, 3] + test.AddInput("theta", {1, 3, 3}, {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}); + test.AddInput("size", {4}, {1, 1, 2, 3}); + test.AddOutput("grid", {1, 2, 3, 2}, std::vector(12, 0.0f)); + test.Run(OpTester::ExpectResult::kExpectFailure, "theta shape must be [N, 2, 3] for 2D"); +} + +// Test: 2D - theta shape must be [N, 2, 3], wrong third dimension +TEST(AffineGridTest, invalid_2d_theta_wrong_dim2) { + OpTester test("AffineGrid", 20); + // theta is [1, 2, 4] but for 2D it must be [N, 2, 3] + test.AddInput("theta", {1, 2, 4}, {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f}); + test.AddInput("size", {4}, {1, 1, 2, 3}); + test.AddOutput("grid", {1, 2, 3, 2}, std::vector(12, 0.0f)); + test.Run(OpTester::ExpectResult::kExpectFailure, "theta shape must be [N, 2, 3] for 2D"); +} + +// Test: 3D - batch dimension mismatch between theta and size +TEST(AffineGridTest, invalid_3d_batch_mismatch) { + OpTester test("AffineGrid", 20); + // theta has N=1, but size has N=2 + test.AddInput("theta", {1, 3, 4}, {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}); + test.AddInput("size", {5}, {2, 1, 2, 2, 3}); + test.AddOutput("grid", {2, 2, 2, 3, 3}, std::vector(72, 0.0f)); + test.Run(OpTester::ExpectResult::kExpectFailure, "must equal theta batch dimension"); +} + +// Test: 3D - theta shape must be [N, 3, 4], wrong second dimension +TEST(AffineGridTest, invalid_3d_theta_wrong_dim1) { + OpTester test("AffineGrid", 20); + // theta is [1, 2, 4] but for 3D it must be [N, 3, 4] + test.AddInput("theta", {1, 2, 4}, {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f}); + test.AddInput("size", {5}, {1, 1, 2, 2, 3}); + test.AddOutput("grid", {1, 2, 2, 3, 3}, std::vector(36, 0.0f)); + test.Run(OpTester::ExpectResult::kExpectFailure, "theta shape must be [N, 3, 4] for 3D"); +} + +// Test: 3D - theta shape must be [N, 3, 4], wrong third dimension +TEST(AffineGridTest, invalid_3d_theta_wrong_dim2) { + OpTester test("AffineGrid", 20); + // theta is [1, 3, 3] but for 3D it must be [N, 3, 4] + test.AddInput("theta", {1, 3, 3}, {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}); + test.AddInput("size", {5}, {1, 1, 2, 2, 3}); + test.AddOutput("grid", {1, 2, 2, 3, 3}, std::vector(36, 0.0f)); + test.Run(OpTester::ExpectResult::kExpectFailure, "theta shape must be [N, 3, 4] for 3D"); +} } // namespace test } // namespace onnxruntime From 1816e95b82eca4e227cec287cde730d9de185f7c Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Thu, 5 Mar 2026 15:26:35 -0800 Subject: [PATCH 2/6] Update onnxruntime/core/providers/cpu/tensor/affine_grid.cc Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- onnxruntime/core/providers/cpu/tensor/affine_grid.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/cpu/tensor/affine_grid.cc b/onnxruntime/core/providers/cpu/tensor/affine_grid.cc index 83762f7ef91ab..05000ececee12 100644 --- a/onnxruntime/core/providers/cpu/tensor/affine_grid.cc +++ b/onnxruntime/core/providers/cpu/tensor/affine_grid.cc @@ -81,7 +81,7 @@ void affine_grid_generator_2d(const Tensor* theta, const Eigen::MatrixMutableData() + grid_batch_offset; Eigen::Map> grid_matrix(grid_data, narrow(H * W), 2); - grid_matrix = ((theta_R * base_grid_transposed).array().colwise() + theta_T).matrix().transpose(); //(2x2 * 2xN).colwise() + 2x1).transpose() + grid_matrix = ((theta_R * base_grid_transposed).array().colwise() + theta_T).matrix().transpose(); // ((2x2 * 2xN).array().colwise() + 2x1).matrix().transpose() => Nx2 } template From 2ed48dbce391d79b912fb65b64c5cef678a52f3f Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Thu, 5 Mar 2026 15:27:02 -0800 Subject: [PATCH 3/6] Update onnxruntime/test/providers/cpu/tensor/affine_grid_test.cc Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- onnxruntime/test/providers/cpu/tensor/affine_grid_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/test/providers/cpu/tensor/affine_grid_test.cc b/onnxruntime/test/providers/cpu/tensor/affine_grid_test.cc index 747accd7dc8a2..ec56fd4b2c70c 100644 --- a/onnxruntime/test/providers/cpu/tensor/affine_grid_test.cc +++ b/onnxruntime/test/providers/cpu/tensor/affine_grid_test.cc @@ -4,7 +4,7 @@ #include "core/util/math.h" #include "gtest/gtest.h" #include "test/providers/provider_test_utils.h" -#include "test/unittest_util/op_tester.h" // Ensure this include is present +#include "test/unittest_util/op_tester.h" // Provides OpTester used in these tests namespace onnxruntime { namespace test { From 7b31b060376d759099bdba6b29951f58977257f5 Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Thu, 5 Mar 2026 15:29:47 -0800 Subject: [PATCH 4/6] Shorten substrings --- onnxruntime/test/providers/cpu/tensor/affine_grid_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/onnxruntime/test/providers/cpu/tensor/affine_grid_test.cc b/onnxruntime/test/providers/cpu/tensor/affine_grid_test.cc index ec56fd4b2c70c..41fbdcdbc8570 100644 --- a/onnxruntime/test/providers/cpu/tensor/affine_grid_test.cc +++ b/onnxruntime/test/providers/cpu/tensor/affine_grid_test.cc @@ -198,7 +198,7 @@ TEST(AffineGridTest, invalid_size_length_3) { test.AddInput("theta", {1, 2, 3}, {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}); test.AddInput("size", {3}, {1, 1, 2}); test.AddOutput("grid", {1, 2, 2}, std::vector(4, 0.0f)); - test.Run(OpTester::ExpectResult::kExpectFailure, "Length of input 'size' is 3. It must be 4 for 2D or 5 for 5D"); + test.Run(OpTester::ExpectResult::kExpectFailure, "Length of input 'size' is 3"); } // Test: size length must be 4 or 5 (too long) @@ -207,7 +207,7 @@ TEST(AffineGridTest, invalid_size_length_6) { test.AddInput("theta", {1, 2, 3}, {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}); test.AddInput("size", {6}, {1, 1, 2, 3, 4, 5}); test.AddOutput("grid", {1, 2, 3, 2}, std::vector(12, 0.0f)); - test.Run(OpTester::ExpectResult::kExpectFailure, "Length of input 'size' is 6. It must be 4 for 2D or 5 for 5D"); + test.Run(OpTester::ExpectResult::kExpectFailure, "Length of input 'size' is 6"); } // Test: 2D - batch dimension mismatch between theta and size From dcc9b574b1b05c2e241d8e8e1c3456200f47c854 Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Fri, 6 Mar 2026 15:06:32 -0800 Subject: [PATCH 5/6] Add positivity checks for H,W,D --- .../core/providers/cpu/tensor/affine_grid.cc | 5 ++ .../providers/cpu/tensor/affine_grid_test.cc | 90 +++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/onnxruntime/core/providers/cpu/tensor/affine_grid.cc b/onnxruntime/core/providers/cpu/tensor/affine_grid.cc index 05000ececee12..86e920989db1c 100644 --- a/onnxruntime/core/providers/cpu/tensor/affine_grid.cc +++ b/onnxruntime/core/providers/cpu/tensor/affine_grid.cc @@ -123,6 +123,8 @@ Status AffineGrid::Compute(OpKernelContext* context) const { ORT_RETURN_IF(theta_shape[1] != 2 || theta_shape[2] != 3, "AffineGrid: theta shape must be [N, 2, 3] for 2D, got [", theta_shape[0], ", ", theta_shape[1], ", ", theta_shape[2], "]"); + ORT_RETURN_IF(H <= 0, "AffineGrid: size[2] (H=", H, ") must be positive"); + ORT_RETURN_IF(W <= 0, "AffineGrid: size[3] (W=", W, ") must be positive"); TensorShape grid_shape{N, H, W, 2}; auto grid = context->Output(0, grid_shape); @@ -144,6 +146,9 @@ Status AffineGrid::Compute(OpKernelContext* context) const { ORT_RETURN_IF(theta_shape[1] != 3 || theta_shape[2] != 4, "AffineGrid: theta shape must be [N, 3, 4] for 3D, got [", theta_shape[0], ", ", theta_shape[1], ", ", theta_shape[2], "]"); + ORT_RETURN_IF(D <= 0, "AffineGrid: size[2] (D=", D, ") must be positive"); + ORT_RETURN_IF(H <= 0, "AffineGrid: size[3] (H=", H, ") must be positive"); + ORT_RETURN_IF(W <= 0, "AffineGrid: size[4] (W=", W, ") must be positive"); TensorShape grid_shape{N, D, H, W, 3}; auto grid = context->Output(0, grid_shape); diff --git a/onnxruntime/test/providers/cpu/tensor/affine_grid_test.cc b/onnxruntime/test/providers/cpu/tensor/affine_grid_test.cc index 41fbdcdbc8570..0136a53dd44eb 100644 --- a/onnxruntime/test/providers/cpu/tensor/affine_grid_test.cc +++ b/onnxruntime/test/providers/cpu/tensor/affine_grid_test.cc @@ -269,5 +269,95 @@ TEST(AffineGridTest, invalid_3d_theta_wrong_dim2) { test.AddOutput("grid", {1, 2, 2, 3, 3}, std::vector(36, 0.0f)); test.Run(OpTester::ExpectResult::kExpectFailure, "theta shape must be [N, 3, 4] for 3D"); } + +// Test: 2D - H must be positive (zero) +TEST(AffineGridTest, invalid_2d_H_zero) { + OpTester test("AffineGrid", 20); + test.AddInput("theta", {1, 2, 3}, {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}); + test.AddInput("size", {4}, {1, 1, 0, 3}); + test.AddOutput("grid", {1, 0, 3, 2}, std::vector(0, 0.0f)); + test.Run(OpTester::ExpectResult::kExpectFailure, "size[2] (H=0) must be positive"); +} + +// Test: 2D - H must be positive (negative) +TEST(AffineGridTest, invalid_2d_H_negative) { + OpTester test("AffineGrid", 20); + test.AddInput("theta", {1, 2, 3}, {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}); + test.AddInput("size", {4}, {1, 1, -1, 3}); + test.AddOutput("grid", {1, 1, 3, 2}, std::vector(6, 0.0f)); + test.Run(OpTester::ExpectResult::kExpectFailure, "size[2] (H=-1) must be positive"); +} + +// Test: 2D - W must be positive (zero) +TEST(AffineGridTest, invalid_2d_W_zero) { + OpTester test("AffineGrid", 20); + test.AddInput("theta", {1, 2, 3}, {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}); + test.AddInput("size", {4}, {1, 1, 2, 0}); + test.AddOutput("grid", {1, 2, 0, 2}, std::vector(0, 0.0f)); + test.Run(OpTester::ExpectResult::kExpectFailure, "size[3] (W=0) must be positive"); +} + +// Test: 2D - W must be positive (negative) +TEST(AffineGridTest, invalid_2d_W_negative) { + OpTester test("AffineGrid", 20); + test.AddInput("theta", {1, 2, 3}, {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}); + test.AddInput("size", {4}, {1, 1, 2, -2}); + test.AddOutput("grid", {1, 2, 1, 2}, std::vector(4, 0.0f)); + test.Run(OpTester::ExpectResult::kExpectFailure, "size[3] (W=-2) must be positive"); +} + +// Test: 3D - D must be positive (zero) +TEST(AffineGridTest, invalid_3d_D_zero) { + OpTester test("AffineGrid", 20); + test.AddInput("theta", {1, 3, 4}, {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}); + test.AddInput("size", {5}, {1, 1, 0, 2, 3}); + test.AddOutput("grid", {1, 0, 2, 3, 3}, std::vector(0, 0.0f)); + test.Run(OpTester::ExpectResult::kExpectFailure, "size[2] (D=0) must be positive"); +} + +// Test: 3D - D must be positive (negative) +TEST(AffineGridTest, invalid_3d_D_negative) { + OpTester test("AffineGrid", 20); + test.AddInput("theta", {1, 3, 4}, {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}); + test.AddInput("size", {5}, {1, 1, -1, 2, 3}); + test.AddOutput("grid", {1, 1, 2, 3, 3}, std::vector(18, 0.0f)); + test.Run(OpTester::ExpectResult::kExpectFailure, "size[2] (D=-1) must be positive"); +} + +// Test: 3D - H must be positive (zero) +TEST(AffineGridTest, invalid_3d_H_zero) { + OpTester test("AffineGrid", 20); + test.AddInput("theta", {1, 3, 4}, {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}); + test.AddInput("size", {5}, {1, 1, 2, 0, 3}); + test.AddOutput("grid", {1, 2, 0, 3, 3}, std::vector(0, 0.0f)); + test.Run(OpTester::ExpectResult::kExpectFailure, "size[3] (H=0) must be positive"); +} + +// Test: 3D - H must be positive (negative) +TEST(AffineGridTest, invalid_3d_H_negative) { + OpTester test("AffineGrid", 20); + test.AddInput("theta", {1, 3, 4}, {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}); + test.AddInput("size", {5}, {1, 1, 2, -3, 3}); + test.AddOutput("grid", {1, 2, 1, 3, 3}, std::vector(18, 0.0f)); + test.Run(OpTester::ExpectResult::kExpectFailure, "size[3] (H=-3) must be positive"); +} + +// Test: 3D - W must be positive (zero) +TEST(AffineGridTest, invalid_3d_W_zero) { + OpTester test("AffineGrid", 20); + test.AddInput("theta", {1, 3, 4}, {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}); + test.AddInput("size", {5}, {1, 1, 2, 3, 0}); + test.AddOutput("grid", {1, 2, 3, 0, 3}, std::vector(0, 0.0f)); + test.Run(OpTester::ExpectResult::kExpectFailure, "size[4] (W=0) must be positive"); +} + +// Test: 3D - W must be positive (negative) +TEST(AffineGridTest, invalid_3d_W_negative) { + OpTester test("AffineGrid", 20); + test.AddInput("theta", {1, 3, 4}, {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}); + test.AddInput("size", {5}, {1, 1, 2, 3, -4}); + test.AddOutput("grid", {1, 2, 3, 1, 3}, std::vector(18, 0.0f)); + test.Run(OpTester::ExpectResult::kExpectFailure, "size[4] (W=-4) must be positive"); +} } // namespace test } // namespace onnxruntime From 6e7f328aee2509ac81b693312abab700b13262bf Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Mon, 9 Mar 2026 12:10:57 -0700 Subject: [PATCH 6/6] Disable a test that timesout --- onnxruntime/test/contrib_ops/matmul_bnb4_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/test/contrib_ops/matmul_bnb4_test.cc b/onnxruntime/test/contrib_ops/matmul_bnb4_test.cc index a155e24800644..47422eac216b7 100644 --- a/onnxruntime/test/contrib_ops/matmul_bnb4_test.cc +++ b/onnxruntime/test/contrib_ops/matmul_bnb4_test.cc @@ -115,7 +115,7 @@ void RunTest(int64_t quant_type, int64_t M, int64_t N, int64_t K, int64_t block_ } } -TEST(MatMulBnb4, Float32) { +TEST(MatMulBnb4, DISABLED_Float32) { for (auto qt : {0, 1}) { for (auto M : {1, 2, 100}) { for (auto N : {1, 2, 32, 288}) {