From b03f9cc854ea80e975c185e84e62d74c02d1a90c Mon Sep 17 00:00:00 2001 From: Manuel Candales Date: Thu, 11 Sep 2025 06:27:44 -0700 Subject: [PATCH] Test any_dims_out with empty dim list (#14007) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/14007 Reviewed By: SS-JIA Differential Revision: D81774097 --- kernels/test/op_any_test.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/kernels/test/op_any_test.cpp b/kernels/test/op_any_test.cpp index 7261be1b822..1853b96ab7d 100644 --- a/kernels/test/op_any_test.cpp +++ b/kernels/test/op_any_test.cpp @@ -176,3 +176,34 @@ TEST_F(OpAnyOutTest, EmptyInput) { op_any_dims_out(x, dim_list, /*keepdim=*/true, out); EXPECT_TENSOR_CLOSE(out, tfBool.make({2, 0, 1}, {})); } + +TEST_F(OpAnyOutTest, TestAnyDimsOutNullDimList) { + TensorFactory tfInt; + TensorFactory tfBool; + + Tensor self = tfInt.make({2, 6}, {0, 2, 0, 3, 0, 1, 5, 0, 2, 0, 4, 0}); + optional> opt_dim_list = std::nullopt; + bool keepdim = false; + Tensor out = tfBool.zeros({}); + Tensor out_expected = tfBool.make({}, {true}); + + op_any_dims_out(self, opt_dim_list, keepdim, out); + EXPECT_TENSOR_CLOSE(out, out_expected); +} + +TEST_F(OpAnyOutTest, TestAnyDimsOutEmptyDimList) { + TensorFactory tfInt; + TensorFactory tfBool; + + Tensor self = tfInt.make({2, 3}, {0, 2, 0, 0, 1, 5}); + int64_t dims[0] = {}; + size_t dims_size = 0; + optional> opt_dim_list{ArrayRef{dims, dims_size}}; + bool keepdim = false; + Tensor out = tfBool.zeros({2, 3}); + Tensor out_expected = + tfBool.make({2, 3}, {false, true, false, false, true, true}); + + op_any_dims_out(self, opt_dim_list, keepdim, out); + EXPECT_TENSOR_CLOSE(out, out_expected); +}