Skip to content
Snippets Groups Projects
Commit 54988d11 authored by Houssem ROUIS's avatar Houssem ROUIS Committed by Maxence Naud
Browse files

add ceil_mode tests for Avg and Max Pooling

parent a814fc02
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <cmath> #include <cmath>
#include <tuple> #include <tuple>
#include "aidge/backend/cpu/operator/MaxPoolingImpl.hpp" #include "aidge/backend/cpu/operator/MaxPoolingImpl.hpp"
#include "aidge/backend/cpu/data/GetCPUPtr.h" #include "aidge/backend/cpu/data/GetCPUPtr.h"
#include "aidge/data/Data.hpp" #include "aidge/data/Data.hpp"
......
...@@ -144,4 +144,61 @@ TEST_CASE("[cpu/operator] AvgPooling(forward)", "[AvgPooling][CPU]") { ...@@ -144,4 +144,61 @@ TEST_CASE("[cpu/operator] AvgPooling(forward)", "[AvgPooling][CPU]") {
op->getOutput(0)->print(); op->getOutput(0)->print();
REQUIRE(*(op->getOutput(0)) == *myOutput3); 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
...@@ -115,4 +115,61 @@ TEST_CASE("[cpu/operator] MaxPooling(forward)", "[MaxPooling][CPU]") { ...@@ -115,4 +115,61 @@ TEST_CASE("[cpu/operator] MaxPooling(forward)", "[MaxPooling][CPU]") {
op->getOutput(0)->print(); op->getOutput(0)->print();
REQUIRE(*(op->getOutput(0)) == *myOutput); 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment