From b91f4448c33eff9707b707748bf8947ef9ef06b5 Mon Sep 17 00:00:00 2001
From: NAUD Maxence <maxence.naud@cea.fr>
Date: Mon, 27 Nov 2023 13:23:27 +0000
Subject: [PATCH] [Upd] Conv and ConvDepthWise tests

---
 unit_tests/operator/Test_ConvDepthWise_Op.cpp | 77 ++++++++++---------
 unit_tests/operator/Test_Conv_Op.cpp          |  8 +-
 2 files changed, 46 insertions(+), 39 deletions(-)

diff --git a/unit_tests/operator/Test_ConvDepthWise_Op.cpp b/unit_tests/operator/Test_ConvDepthWise_Op.cpp
index ef68c439d..cc138fa0a 100644
--- a/unit_tests/operator/Test_ConvDepthWise_Op.cpp
+++ b/unit_tests/operator/Test_ConvDepthWise_Op.cpp
@@ -22,47 +22,52 @@
 #include "aidge/utils/Types.h"
 
 namespace Aidge {
-// TEST_CASE("[core/operator] ConvDepthWise_Op(computeReceptiveField)", "[Operator][computeReceptiveFiled][ConvDepthWise]") {
-//     auto dataProvider = Producer({16, 3, 224, 224}, "dataProvider");
-//     auto conv1 = ConvDepthWise({5, 5}, "conv1");         // output dims: {16, 3, 220, 220}
-//     auto conv2 = ConvDepthWise({3, 3}, "conv2");         // output dims: {16, 3, 218, 218}
-//     auto conv3 = ConvDepthWise({2, 2}, "conv3", {2,2});  // output dims: {16, 3, 109, 109}
-//     auto conv4 = ConvDepthWise({1, 1}, "conv4");         // output dims: {16, 3, 109, 109}
+TEST_CASE("[core/operator] ConvDepthWise_Op(computeReceptiveField)", "[Operator][computeReceptiveFiled][ConvDepthWise]") {
+    auto dataProvider = Producer({16, 3, 224, 224}, "dataProvider");
+    auto conv1 = ConvDepthWise(3, {5, 5}, "conv1");         // output dims: {16, 3, 220, 220}
+    auto conv2 = ConvDepthWise(3, {3, 3}, "conv2");         // output dims: {16, 3, 218, 218}
+    auto conv3 = ConvDepthWise(3, {2, 2}, "conv3", {2,2});  // output dims: {16, 3, 109, 109}
+    auto conv4 = ConvDepthWise(3, {1, 1}, "conv4");         // output dims: {16, 3, 109, 109}
 
-//     auto g = std::make_shared<GraphView>("TestGraph");
+    auto g = std::make_shared<GraphView>("TestGraph");
 
-//     dataProvider->addChild(conv1, 0);
-//     g->add(conv1);
-//     g->addChild(conv2, conv1, 0);
-//     g->addChild(conv3, conv2, 0);
-//     g->addChild(conv4, conv3, 0);
+    dataProvider->addChild(conv1, 0);
+    g->add(conv1);
+    g->addChild(conv2, conv1, 0);
+    g->addChild(conv3, conv2, 0);
+    g->addChild(conv4, conv3, 0);
 
-//     g->forwardDims();
+    g->forwardDims();
 
-//     SECTION("Check individual receptive fields") {
-//         auto res1 = conv1->getOperator()->computeReceptiveField(0, {16,3,10,10});
-//         auto res2 = conv2->getOperator()->computeReceptiveField(conv2->getOperator()->output(0).getIdx({3,1,100,28}), {4,2,30,40});
-//         auto res3 = conv3->getOperator()->computeReceptiveField(0, {1,1,109,109});
-//         auto res4 = conv4->getOperator()->computeReceptiveField(conv4->getOperator()->input(0).getIdx({5,0,108,108}), {10,1,1,1});
+    auto op1 = std::dynamic_pointer_cast<OperatorTensor>(conv1 -> getOperator());
+    auto op2 = std::dynamic_pointer_cast<OperatorTensor>(conv2 -> getOperator());
+    auto op3 = std::dynamic_pointer_cast<OperatorTensor>(conv3 -> getOperator());
+    auto op4 = std::dynamic_pointer_cast<OperatorTensor>(conv4 -> getOperator());
 
-//         REQUIRE(((res1[0].first == 0) && (res1[0].second == std::vector<DimSize_t>({16, 3, 14, 14}))));
-//         REQUIRE(((res2[0].first == conv2->getOperator()->input(0).getIdx({3,1,100,28})) && (res2[0].second == std::vector<DimSize_t>({4, 2, 32, 42}))));
-//         REQUIRE(((res3[0].first == 0) && (res3[0].second == std::vector<DimSize_t>({1, 1, 218, 218}))));
-//         REQUIRE(((res4[0].first == conv4->getOperator()->input(0).getIdx({5, 0, 108, 108})) && (res4[0].second == std::vector<DimSize_t>({10, 1, 1, 1}))));
-//     }
+    SECTION("Check individual receptive fields") {
+        auto res1 = op1->computeReceptiveField(0, {16,3,10,10});
+        auto res2 = op2->computeReceptiveField(op2->getOutput(0)->getIdx({3,1,100,28}), {4,2,30,40});
+        auto res3 = op3->computeReceptiveField(0, {1,1,109,109});
+        auto res4 = op4->computeReceptiveField(op4->getInput(0)->getIdx({5,0,108,108}), {10,1,1,1});
 
-//     SECTION("Check receptive field propagation") {
-//         // input:  first-{5, 0, 50, 50}  dims-{1, 1, 1, 1}
-//         auto res4 = conv4->getOperator()->computeReceptiveField(conv4->getOperator()->input(0).getIdx({5,0,50,50}), {1,1,1,1});
-//         // conv4 RF:  first-{5, 0, 50, 50}  dims-{1, 1, 1, 1}
-//         auto res3 = conv3->getOperator()->computeReceptiveField(res4[0].first, res4[0].second);
-//         // conv3 RF:  first-{5, 0, 100, 100} dims-{1, 1, 2, 2}
-//         auto res2 = conv2->getOperator()->computeReceptiveField(res3[0].first, res3[0].second);
-//         // conv2 RF:  first-{5, 0, 100, 100} dims-{1, 1, 4, 4}
-//         auto res1 = conv1->getOperator()->computeReceptiveField(res2[0].first, res2[0].second);
-//         // conv1 RF:  first-{5, 0, 100, 100} dims-{1, 1, 8, 8}
+        REQUIRE(((res1[0].first == 0) && (res1[0].second == std::vector<DimSize_t>({16, 3, 14, 14}))));
+        REQUIRE(((res2[0].first == op2->getInput(0)->getIdx({3,1,100,28})) && (res2[0].second == std::vector<DimSize_t>({4, 2, 32, 42}))));
+        REQUIRE(((res3[0].first == 0) && (res3[0].second == std::vector<DimSize_t>({1, 1, 218, 218}))));
+        REQUIRE(((res4[0].first == op4->getInput(0)->getIdx({5, 0, 108, 108})) && (res4[0].second == std::vector<DimSize_t>({10, 1, 1, 1}))));
+    }
 
-//         REQUIRE(((res1[0].first == conv1->getOperator()->input(0).getIdx({5, 0, 100, 100})) && (res1[0].second == std::vector<DimSize_t>({1, 1, 8, 8}))));
-//     }
-// }
+    SECTION("Check receptive field propagation") {
+        // input:  first-{5, 0, 50, 50}  dims-{1, 1, 1, 1}
+        auto res4 = op4->computeReceptiveField(op4->getInput(0)->getIdx({5,0,50,50}), {1,1,1,1});
+        // conv4 RF:  first-{5, 0, 50, 50}  dims-{1, 1, 1, 1}
+        auto res3 = op3->computeReceptiveField(res4[0].first, res4[0].second);
+        // conv3 RF:  first-{5, 0, 100, 100} dims-{1, 1, 2, 2}
+        auto res2 = op2->computeReceptiveField(res3[0].first, res3[0].second);
+        // conv2 RF:  first-{5, 0, 100, 100} dims-{1, 1, 4, 4}
+        auto res1 = op1->computeReceptiveField(res2[0].first, res2[0].second);
+        // conv1 RF:  first-{5, 0, 100, 100} dims-{1, 1, 8, 8}
+
+        REQUIRE(((res1[0].first == op1->getInput(0)->getIdx({5, 0, 100, 100})) && (res1[0].second == std::vector<DimSize_t>({1, 1, 8, 8}))));
+    }
+}
 }  // namespace Aidge
\ No newline at end of file
diff --git a/unit_tests/operator/Test_Conv_Op.cpp b/unit_tests/operator/Test_Conv_Op.cpp
index 1a543ae64..a3e84999e 100644
--- a/unit_tests/operator/Test_Conv_Op.cpp
+++ b/unit_tests/operator/Test_Conv_Op.cpp
@@ -51,9 +51,11 @@ TEST_CASE("[core/operator] Conv_Op(computeReceptiveField)", "[Operator][computeR
         auto res4 = op4 -> computeReceptiveField(op4 -> getOutput(0)->getIdx({5,0,108,108}), {10,10,1,1});
 
         REQUIRE(((res1[0].first == 0) && (res1[0].second == std::vector<DimSize_t>({16, 3, 14, 14}))));
-        REQUIRE(((res2[0].first == op2->input(0).getIdx({3,0,100,28})) && (res2[0].second == std::vector<DimSize_t>({4, 32, 32, 42}))));
+        REQUIRE(((res1[1].first == 0) && (res1[1].second == std::vector<DimSize_t>({32, 3, 5, 5}))));
+        REQUIRE(((res1[2].first == 0) && (res1[2].second == std::vector<DimSize_t>({32}))));
+        REQUIRE(((res2[0].first == op2->getInput(0)->getIdx({3,0,100,28})) && (res2[0].second == std::vector<DimSize_t>({4, 32, 32, 42}))));
         REQUIRE(((res3[0].first == 0) && (res3[0].second == std::vector<DimSize_t>({1, 64, 218, 218}))));
-        REQUIRE(((res4[0].first == op4->input(0).getIdx({5, 0, 108, 108})) && (res4[0].second == std::vector<DimSize_t>({10, 10, 1, 1}))));
+        REQUIRE(((res4[0].first == op4->getInput(0)->getIdx({5, 0, 108, 108})) && (res4[0].second == std::vector<DimSize_t>({10, 10, 1, 1}))));
     }
 
     SECTION("Check receptive field propagation") {
@@ -67,7 +69,7 @@ TEST_CASE("[core/operator] Conv_Op(computeReceptiveField)", "[Operator][computeR
         auto res1 = op1->computeReceptiveField(res2[0].first, res2[0].second);
         // conv1 RF:  first-{5, 0, 100, 100} dims-{1, 3, 8, 8}
 
-        REQUIRE(((res1[0].first == op1->input(0).getIdx({5, 0, 100, 100})) && (res1[0].second == std::vector<DimSize_t>({1, 3, 8, 8}))));
+        REQUIRE(((res1[0].first == op1->getInput(0)->getIdx({5, 0, 100, 100})) && (res1[0].second == std::vector<DimSize_t>({1, 3, 8, 8}))));
 
 
         // std::cout << "conv1: {";
-- 
GitLab