Skip to content

Commit 81746ef

Browse files
GregoryComerfacebook-github-bot
authored andcommitted
Add ceil_mode test for max_pool2d_with_indices
Summary: Add a test for ceil_mode for max_pool2d_with_indices. All existing tests appear to only cover ceil_mode=False. Differential Revision: D67116327
1 parent 82763a9 commit 81746ef

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

kernels/test/op_max_pool2d_with_indices_test.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,81 @@ 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},
297+
{
298+
-7, -9, -6, -8, -9, -9, -6,
299+
-10, -7, -6, -10, -7, -10, -7,
300+
-8, -10, -6, -8, -8, -10, -9,
301+
-8, -6, -8, -9, -8, -8, -8,
302+
-6, -9, -9, -8, -8, -8, -8,
303+
-7, -7, -6, -7, -8, -6, -8,
304+
-9, -7, -6, -10, -6, -9, -6,
305+
306+
-7, -8, -10, -10, -8, -8, -10,
307+
-10, -6, -10, -10, -7, -8, -6,
308+
-10, -8, -8, -8, -9, -6, -9,
309+
-7, -10, -7, -6, -9, -8, -9,
310+
-7, -8, -7, -10, -6, -6, -6,
311+
-7, -10, -8, -9, -6, -9, -9,
312+
-8, -8, -8, -9, -9, -10, -8
313+
});
314+
315+
::std::vector<int64_t> kernel_size_vec = {2, 2};
316+
exec_aten::ArrayRef<int64_t> kernel_size = exec_aten::ArrayRef<int64_t>(
317+
kernel_size_vec.data(), kernel_size_vec.size());
318+
::std::vector<int64_t> stride_vec = {2, 2};
319+
exec_aten::ArrayRef<int64_t> stride =
320+
exec_aten::ArrayRef<int64_t>(stride_vec.data(), stride_vec.size());
321+
::std::vector<int64_t> padding_vec = {0, 0};
322+
exec_aten::ArrayRef<int64_t> padding =
323+
exec_aten::ArrayRef<int64_t>(padding_vec.data(), padding_vec.size());
324+
::std::vector<int64_t> dilation_vec = {1, 1};
325+
exec_aten::ArrayRef<int64_t> dilation =
326+
exec_aten::ArrayRef<int64_t>(dilation_vec.data(), dilation_vec.size());
327+
328+
bool ceil_mode = true;
329+
exec_aten::Tensor out = tfFloat.zeros({2, 4, 4});
330+
exec_aten::Tensor indices = tfLong.zeros({2, 4, 4});
331+
exec_aten::Tensor out_expected = tfFloat.make(
332+
{2, 4, 4},
333+
{
334+
-7, -6, -7, -6,
335+
-6, -6, -8, -8,
336+
-6, -6, -6, -8,
337+
-7, -6, -6, -6,
338+
339+
-6, -10, -7, -6,
340+
-7, -6, -6, -9,
341+
-7, -7, -6, -6,
342+
-8, -8, -9, -8
343+
});
344+
345+
op_max_pool2d_with_indices_out(
346+
self, kernel_size, stride, padding, dilation, ceil_mode, out, indices);
347+
EXPECT_TENSOR_CLOSE(out, out_expected);
348+
349+
ceil_mode = false;
350+
out = tfFloat.zeros({2, 3, 3});
351+
indices = tfLong.zeros({2, 3, 3});
352+
out_expected = tfFloat.make(
353+
{2, 3, 3},
354+
{
355+
-7, -6, -7,
356+
-6, -6, -8,
357+
-6, -6, -6,
358+
359+
-6, -10, -7,
360+
-7, -6, -6,
361+
-7, -7, -6
362+
});
363+
364+
op_max_pool2d_with_indices_out(
365+
self, kernel_size, stride, padding, dilation, ceil_mode, out, indices);
366+
EXPECT_TENSOR_CLOSE(out, out_expected);
367+
}

0 commit comments

Comments
 (0)