Skip to content

Commit eefaf28

Browse files
Fix channels-last any test under ATen (pytorch#21978)
## Summary The channels-last `any` regression test aborts in the ATen variant because `TensorFactory<Bool>::channels_last_like` reads Bool storage as Byte. Build the expected tensor directly in channels-last order and replace the newly added C arrays with `std::array` to clear the associated lint failures. ## Test plan - ATen and portable `op_any` tests - `reduce_util` and `op_dequantize` tests - Android ATen `ChannelsLastMultiDimReduction` test - C++ lint
1 parent 56d1af2 commit eefaf28

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

‎kernels/portable/cpu/util/test/reduce_test.cpp‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include <gtest/gtest.h>
1717

18+
#include <array>
19+
1820
using namespace ::testing;
1921
using executorch::aten::ArrayRef;
2022
using executorch::aten::ScalarType;
@@ -443,8 +445,9 @@ TEST(ReduceUtilTest, ApplyOverDimListChannelsLast) {
443445
// here rather than written through, so an out-of-bounds index is reported
444446
// instead of corrupting memory.
445447
Tensor in = tf.zeros_channels_last({2, 2, 3, 3});
446-
int64_t dim_array_023[3] = {0, 2, 3};
447-
dim_list = optional<ArrayRef<int64_t>>(ArrayRef<int64_t>{dim_array_023, 3});
448+
const std::array<int64_t, 3> dim_array_023{0, 2, 3};
449+
dim_list = optional<ArrayRef<int64_t>>(
450+
ArrayRef<int64_t>{dim_array_023.data(), dim_array_023.size()});
448451

449452
const size_t numel = static_cast<size_t>(in.numel());
450453
std::vector<size_t> visits(numel, 0);

‎kernels/test/op_any_test.cpp‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include <gtest/gtest.h>
1919

20+
#include <array>
21+
2022
using namespace ::testing;
2123
using executorch::aten::ArrayRef;
2224
using executorch::aten::ScalarType;
@@ -227,10 +229,13 @@ TEST_F(OpAnyOutTest, ChannelsLastMultiDimReduction) {
227229
Tensor in = tf.channels_last_like(tf.make({2, 2, 3, 3}, data));
228230

229231
Tensor out = tf_bool.zeros_channels_last({1, 2, 1, 1});
230-
int64_t dims[3] = {0, 2, 3};
231-
op_any_dims_out(in, ArrayRef<int64_t>{dims, 3}, /*keepdim=*/true, out);
232-
233-
Tensor expected =
234-
tf_bool.channels_last_like(tf_bool.make({1, 2, 1, 1}, {false, true}));
232+
const std::array<int64_t, 3> dims{0, 2, 3};
233+
op_any_dims_out(
234+
in,
235+
ArrayRef<int64_t>{dims.data(), dims.size()},
236+
/*keepdim=*/true,
237+
out);
238+
239+
Tensor expected = tf_bool.make_channels_last({1, 2, 1, 1}, {false, true});
235240
EXPECT_TENSOR_EQ(out, expected);
236241
}

0 commit comments

Comments
 (0)