Skip to content

Commit 685a6db

Browse files
authored
Add ceil_mode test for max_pool2d_with_indices
Differential Revision: D67116327 Pull Request resolved: #7426
1 parent f370e78 commit 685a6db

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

kernels/test/op_max_pool2d_with_indices_test.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,74 @@ TEST_F(OpMaxPool2DWithIndicesOutTest, SanityTest3D) {
287287
EXPECT_TENSOR_CLOSE(out, out_expected);
288288
EXPECT_TENSOR_CLOSE(indices, indices_expected);
289289
}
290+
291+
TEST_F(OpMaxPool2DWithIndicesOutTest, CeilMode) {
292+
torch::executor::testing::TensorFactory<exec_aten::ScalarType::Float> tfFloat;
293+
torch::executor::testing::TensorFactory<exec_aten::ScalarType::Long> tfLong;
294+
295+
exec_aten::Tensor self = tfFloat.make(
296+
{2, 7, 7}, {-7, -9, -6, -8, -9, -9, -6, -10, -7, -6, -10, -7, -10,
297+
-7, -8, -10, -6, -8, -8, -10, -9, -8, -6, -8, -9, -8,
298+
-8, -8, -6, -9, -9, -8, -8, -8, -8, -7, -7, -6, -7,
299+
-8, -6, -8, -9, -7, -6, -10, -6, -9, -6,
300+
301+
-7, -8, -10, -10, -8, -8, -10, -10, -6, -10, -10, -7, -8,
302+
-6, -10, -8, -8, -8, -9, -6, -9, -7, -10, -7, -6, -9,
303+
-8, -9, -7, -8, -7, -10, -6, -6, -6, -7, -10, -8, -9,
304+
-6, -9, -9, -8, -8, -8, -9, -9, -10, -8});
305+
306+
::std::vector<int64_t> kernel_size_vec = {2, 2};
307+
exec_aten::ArrayRef<int64_t> kernel_size = exec_aten::ArrayRef<int64_t>(
308+
kernel_size_vec.data(), kernel_size_vec.size());
309+
::std::vector<int64_t> stride_vec = {2, 2};
310+
exec_aten::ArrayRef<int64_t> stride =
311+
exec_aten::ArrayRef<int64_t>(stride_vec.data(), stride_vec.size());
312+
::std::vector<int64_t> padding_vec = {0, 0};
313+
exec_aten::ArrayRef<int64_t> padding =
314+
exec_aten::ArrayRef<int64_t>(padding_vec.data(), padding_vec.size());
315+
::std::vector<int64_t> dilation_vec = {1, 1};
316+
exec_aten::ArrayRef<int64_t> dilation =
317+
exec_aten::ArrayRef<int64_t>(dilation_vec.data(), dilation_vec.size());
318+
319+
bool ceil_mode = true;
320+
exec_aten::Tensor out = tfFloat.zeros({2, 4, 4});
321+
exec_aten::Tensor indices = tfLong.zeros({2, 4, 4});
322+
exec_aten::Tensor out_expected = tfFloat.make(
323+
{2, 4, 4},
324+
{-7, -6, -7, -6, -6, -6, -8, -8, -6, -6, -6, -8, -7, -6, -6, -6,
325+
326+
-6, -10, -7, -6, -7, -6, -6, -9, -7, -7, -6, -6, -8, -8, -9, -8});
327+
328+
op_max_pool2d_with_indices_out(
329+
self, kernel_size, stride, padding, dilation, ceil_mode, out, indices);
330+
EXPECT_TENSOR_CLOSE(out, out_expected);
331+
332+
ceil_mode = false;
333+
out = tfFloat.zeros({2, 3, 3});
334+
indices = tfLong.zeros({2, 3, 3});
335+
out_expected = tfFloat.make(
336+
{2, 3, 3},
337+
{-7,
338+
-6,
339+
-7,
340+
-6,
341+
-6,
342+
-8,
343+
-6,
344+
-6,
345+
-6,
346+
347+
-6,
348+
-10,
349+
-7,
350+
-7,
351+
-6,
352+
-6,
353+
-7,
354+
-7,
355+
-6});
356+
357+
op_max_pool2d_with_indices_out(
358+
self, kernel_size, stride, padding, dilation, ceil_mode, out, indices);
359+
EXPECT_TENSOR_CLOSE(out, out_expected);
360+
}

0 commit comments

Comments
 (0)