diff --git a/include/aidge/backend/cpu/operator/MaxPoolingImpl_kernels.hpp b/include/aidge/backend/cpu/operator/MaxPoolingImpl_kernels.hpp index d5ac02fe27ce20ee133e80d41f043ec4ead86711..027fc02a3e88d90082ade06bae53356f1a676094 100644 --- a/include/aidge/backend/cpu/operator/MaxPoolingImpl_kernels.hpp +++ b/include/aidge/backend/cpu/operator/MaxPoolingImpl_kernels.hpp @@ -16,6 +16,7 @@ #include <cmath> #include <tuple> + #include "aidge/backend/cpu/operator/MaxPoolingImpl.hpp" #include "aidge/backend/cpu/data/GetCPUPtr.h" #include "aidge/data/Data.hpp" diff --git a/unit_tests/operator/Test_AvgPoolingImpl.cpp b/unit_tests/operator/Test_AvgPoolingImpl.cpp index 21a7a680ccf51aad73f6bcc962f79092c495df2b..f116934cd61375d3498ecf4e9aeb54f1eea37d3f 100644 --- a/unit_tests/operator/Test_AvgPoolingImpl.cpp +++ b/unit_tests/operator/Test_AvgPoolingImpl.cpp @@ -144,4 +144,61 @@ TEST_CASE("[cpu/operator] AvgPooling(forward)", "[AvgPooling][CPU]") { op->getOutput(0)->print(); REQUIRE(*(op->getOutput(0)) == *myOutput3); } + SECTION("Ceil Mode") { + std::shared_ptr<Tensor> myInput4 = std::make_shared<Tensor>(Array4D<float,1,1,5,5> { // NCHW + { + { + { + { 1, 2, 3, 4, 5}, + { 6, 7, 8, 9, 10}, + {11, 12, 13, 14, 15}, + {16, 17, 18, 19, 20}, + {21, 22, 23, 24, 25} + } + } + } + }); + + // AvgPool with ceil_mode = true + std::shared_ptr<Node> myAvgPool1 = AvgPooling({2,2}, "mycdw", {2,2}, {1,1}, true); + auto op1 = std::static_pointer_cast<AvgPooling_Op<2>>(myAvgPool1 -> getOperator()); + + std::shared_ptr<Tensor> myOutput4 = std::make_shared<Tensor>(Array4D<float,1,1,3,3> { + { + { + { + { 4.0, 6.0, 7.5 }, + { 14.0, 16.0, 17.5 }, + { 21.5, 23.5, 25.0 } + } + } + } + }); + op1->associateInput(0, myInput4); + op1->setDataType(DataType::Float32); + op1->setBackend("cpu"); + myAvgPool1->forward(); + op1->getOutput(0)->print(); + REQUIRE(*(op1->getOutput(0)) == *myOutput4); + + // AvgPool with ceil_mode = false + std::shared_ptr<Node> myAvgPool2 = AvgPooling({2,2}, "mycdw", {2,2}, {1,1}, false); + auto op2 = std::static_pointer_cast<AvgPooling_Op<2>>(myAvgPool2 -> getOperator()); + std::shared_ptr<Tensor> myOutput5 = std::make_shared<Tensor>(Array4D<float,1,1,2,2> { + { + { + { + { 4.0, 6.0 }, + { 14.0, 16.0 } + } + } + } + }); + op2->associateInput(0, myInput4); + op2->setDataType(DataType::Float32); + op2->setBackend("cpu"); + myAvgPool2->forward(); + op2->getOutput(0)->print(); + REQUIRE(*(op2->getOutput(0)) == *myOutput5); + } } \ No newline at end of file diff --git a/unit_tests/operator/Test_MaxPoolingImpl.cpp b/unit_tests/operator/Test_MaxPoolingImpl.cpp index 6b7e6d2f66a1722fd33f3c070e096dc2561b6b90..d480fc3004957e12f72584138bb1c9dd10ee969a 100644 --- a/unit_tests/operator/Test_MaxPoolingImpl.cpp +++ b/unit_tests/operator/Test_MaxPoolingImpl.cpp @@ -115,4 +115,61 @@ TEST_CASE("[cpu/operator] MaxPooling(forward)", "[MaxPooling][CPU]") { op->getOutput(0)->print(); REQUIRE(*(op->getOutput(0)) == *myOutput); } + SECTION("Ceil Mode") { + std::shared_ptr<Tensor> myInput4 = std::make_shared<Tensor>(Array4D<float,1,1,5,5> { // NCHW + { + { + { + { 1, 2, 3, 4, 5}, + { 6, 7, 8, 9, 10}, + {11, 12, 13, 14, 15}, + {16, 17, 18, 19, 20}, + {21, 22, 23, 24, 25} + } + } + } + }); + + // MaxPool with ceil_mode = true + std::shared_ptr<Node> myMaxPool1 = MaxPooling({2,2}, "mycdw", {2,2}, {1,1}, true); + auto op1 = std::static_pointer_cast<OperatorTensor>(myMaxPool1 -> getOperator()); + + std::shared_ptr<Tensor> myOutput4 = std::make_shared<Tensor>(Array4D<float,1,1,3,3> { + { + { + { + { 7.0, 9.0, 10.0 }, + { 17.0, 19.0, 20.0 }, + { 22.0, 24.0, 25.0 } + } + } + } + }); + op1->associateInput(0, myInput4); + op1->setDataType(DataType::Float32); + op1->setBackend("cpu"); + myMaxPool1->forward(); + op1->getOutput(0)->print(); + REQUIRE(*(op1->getOutput(0)) == *myOutput4); + + // MaxPool with ceil_mode = false + std::shared_ptr<Node> myMaxPool2 = MaxPooling({2,2}, "mycdw", {2,2}, {1,1}, false); + auto op2 = std::static_pointer_cast<OperatorTensor>(myMaxPool2 -> getOperator()); + std::shared_ptr<Tensor> myOutput5 = std::make_shared<Tensor>(Array4D<float,1,1,2,2> { + { + { + { + { 7.0, 9.0 }, + { 17.0, 19.0 } + } + } + } + }); + op2->associateInput(0, myInput4); + op2->setDataType(DataType::Float32); + op2->setBackend("cpu"); + myMaxPool2->forward(); + op2->getOutput(0)->print(); + REQUIRE(*(op2->getOutput(0)) == *myOutput5); + } } \ No newline at end of file