diff --git a/unit_tests/operator/Test_AvgPoolingImpl.cpp b/unit_tests/operator/Test_AvgPoolingImpl.cpp index aaa2757830c245275d02792a7a5a2eb1db32d7b8..702c03505196ffe84f5cf3f7cdbd3f4c25c452e2 100644 --- a/unit_tests/operator/Test_AvgPoolingImpl.cpp +++ b/unit_tests/operator/Test_AvgPoolingImpl.cpp @@ -9,6 +9,7 @@ * ********************************************************************************/ +#include <aidge/utils/TensorUtils.hpp> #include <catch2/catch_test_macros.hpp> #include <memory> #include <cstdlib> @@ -100,11 +101,8 @@ TEST_CASE("[cpu/operator] AvgPooling(forward)", "[AvgPooling][CPU]") { op->setBackend("cpu"); myAvgPool->forward(); op->getOutput(0)->print(); - float* outPtr = static_cast<float*>(op->getOutput(0)->getImpl()->rawPtr()); - float* expectedOutPtr = static_cast<float*>(myOutput.getImpl()->rawPtr()); - for (std::size_t i = 0; i < 1; ++i) { - REQUIRE(std::abs(outPtr[i] - expectedOutPtr[i]) < 0.00001); - } + + REQUIRE(approxEq<float>(*(op->getOutput(0)), myOutput, 0, 1E-5)); } // std::cout << static_cast<Tensor>((*op)["weight"])[0][0][0][0] << std::endl; } \ No newline at end of file diff --git a/unit_tests/operator/Test_BatchNormImpl.cpp b/unit_tests/operator/Test_BatchNormImpl.cpp index 1b42c90dd09d63cd319f19bd29751da816db06c0..cd691f7047115845d127c8f4456f178e122db065 100644 --- a/unit_tests/operator/Test_BatchNormImpl.cpp +++ b/unit_tests/operator/Test_BatchNormImpl.cpp @@ -9,6 +9,7 @@ * ********************************************************************************/ +#include <aidge/utils/TensorUtils.hpp> #include <catch2/catch_test_macros.hpp> #include <memory> @@ -88,11 +89,6 @@ TEST_CASE("[cpu/operator] BatchNorm(forward)", "[BatchNorm][CPU]") { op->setBackend("cpu"); myBatchNorm->forward(); - float* resPtr = static_cast<float*>(op->getOutput(0)->getImpl()->rawPtr()); - float* expectedPtr = static_cast<float*>(myOutput->getImpl()->rawPtr()); - for (std::size_t i = 0; i< 54; ++i) { - REQUIRE(std::abs(resPtr[i]-expectedPtr[i]) < 0.00001); - } - + REQUIRE(approxEq<float>(*op->getOutput(0), *myOutput, 0, 1E-5)); // std::cout << static_cast<Tensor>((*op)["weight"])[0][0][0][0] << std::endl; } \ No newline at end of file diff --git a/unit_tests/operator/Test_ConvImpl.cpp b/unit_tests/operator/Test_ConvImpl.cpp index b52085139294021de2fe9d72e173ad74db028ea3..fd662ee472915c0c18416c3107f7b3c49064ebc7 100644 --- a/unit_tests/operator/Test_ConvImpl.cpp +++ b/unit_tests/operator/Test_ConvImpl.cpp @@ -9,6 +9,7 @@ * ********************************************************************************/ +#include <aidge/utils/TensorUtils.hpp> #include <catch2/catch_test_macros.hpp> #include <cstdlib> #include <memory> @@ -245,10 +246,6 @@ TEST_CASE("[cpu/operator] Conv(forward)", "[Conv][CPU]") { op->setBackend("cpu"); myConv->forward(); - float* resPtr = static_cast<float*>(op->getOutput(0)->getImpl()->rawPtr()); - float* expectedPtr = static_cast<float*>(expectedOutput.getImpl()->rawPtr()); - for (std::size_t i = 0; i< expectedOutput.size(); ++i) { - REQUIRE(std::abs(resPtr[i]-expectedPtr[i]) < 0.00001); - } + REQUIRE(approxEq<float>(*op->getOutput(0),expectedOutput, 0, 1E-5)); } } \ No newline at end of file diff --git a/unit_tests/operator/Test_ErfImpl.cpp b/unit_tests/operator/Test_ErfImpl.cpp index 2826b5b57d431cf8296a9869f88f7d642c59c963..099802230f06d41b0f99b047446719bd9165caeb 100644 --- a/unit_tests/operator/Test_ErfImpl.cpp +++ b/unit_tests/operator/Test_ErfImpl.cpp @@ -9,6 +9,7 @@ * ********************************************************************************/ +#include <aidge/utils/TensorUtils.hpp> #include <catch2/catch_test_macros.hpp> #include "aidge/data/Tensor.hpp" @@ -21,7 +22,7 @@ using namespace Aidge; -TEST_CASE("[cpu/operator] Erf(forward)") { +TEST_CASE("[cpu/operator] Erf(forward)", "[CPU][Erf]") { SECTION("1D Tensor") { std::shared_ptr<Tensor> input0 = std::make_shared<Tensor>(Array1D<float,10> { {0.41384590, 0.43120754, 0.93762982, 0.31049860, 0.77547199, 0.09514862, @@ -39,11 +40,7 @@ TEST_CASE("[cpu/operator] Erf(forward)") { op->setBackend("cpu"); myErf->forward(); - float* resPtr = static_cast<float*>(op->getOutput(0)->getImpl()->rawPtr()); - float* expectedPtr = static_cast<float*>(expectedOutput->getImpl()->rawPtr()); - for (std::size_t i = 0; i< expectedOutput->size(); ++i) { - REQUIRE(std::abs(resPtr[i]-expectedPtr[i]) < 0.00001); - } + REQUIRE(approxEq<float>(*(op->getOutput(0)), *(expectedOutput))); } SECTION("3D Tensor") { @@ -79,10 +76,6 @@ TEST_CASE("[cpu/operator] Erf(forward)") { op->setBackend("cpu"); myErf->forward(); - float* resPtr = static_cast<float*>(op->getOutput(0)->getImpl()->rawPtr()); - float* expectedPtr = static_cast<float*>(expectedOutput->getImpl()->rawPtr()); - for (std::size_t i = 0; i< expectedOutput->size(); ++i) { - REQUIRE(std::abs(resPtr[i]-expectedPtr[i]) < 0.00001); - } + REQUIRE(approxEq<float>(*(op->getOutput(0)), *(expectedOutput))); } } \ No newline at end of file diff --git a/unit_tests/operator/Test_MetaOperator.cpp b/unit_tests/operator/Test_MetaOperator.cpp index 271a1e2f9860d92f840916f6b2e396993b0bea39..f0611df40179efb4c51147287f1b030ab9215e65 100644 --- a/unit_tests/operator/Test_MetaOperator.cpp +++ b/unit_tests/operator/Test_MetaOperator.cpp @@ -182,11 +182,7 @@ TEST_CASE("[cpu/operator] MetaOperator", "[MetaOperator][CPU]") { myConv->forward(); convOp -> getOutput(0) -> print(); - double* computedOutput = static_cast<double*>(convOp->getOutput(0)->getImpl()->rawPtr()); - double* expectedOutput = static_cast<double*>(myOutput->getImpl()->rawPtr()); - for (std::size_t i = 0; i < myOutput->size(); ++i) { - REQUIRE(std::abs(computedOutput[i] - expectedOutput[i]) < 1e-5); - } + REQUIRE(approxEq<double>(*(convOp->getOutput(0)), *myOutput, 0, 1E-5)); std::shared_ptr<Node> myPaddedConv = PaddedConv(3, 4, {3, 3}, "myPaddedConv", {1, 1}, {1, 1, 1, 1}); diff --git a/unit_tests/operator/Test_SoftmaxImpl.cpp b/unit_tests/operator/Test_SoftmaxImpl.cpp index da6c6f0d35a1db9ad9099a40b7e83459e14a20f5..14081c03063a73cd24fdc88fc6c9b6eb5fd8c3c0 100644 --- a/unit_tests/operator/Test_SoftmaxImpl.cpp +++ b/unit_tests/operator/Test_SoftmaxImpl.cpp @@ -9,6 +9,7 @@ * ********************************************************************************/ +#include <aidge/utils/TensorUtils.hpp> #include <catch2/catch_test_macros.hpp> #include "aidge/data/Tensor.hpp" @@ -52,6 +53,7 @@ TEST_CASE("[cpu/operator] Softmax(forward)", "[Softmax][CPU]") { REQUIRE(std::abs(resPtr[i]-expectedPtr[i]) < 0.00001); } + REQUIRE(approxEq<float>(*op->getOutput(0), *expectedOutput, 0, 1E-5)); } SECTION("4D Tensor") { std::shared_ptr<Tensor> input = std::make_shared<Tensor>(Array4D<float,2,3,3,3> { @@ -114,10 +116,6 @@ TEST_CASE("[cpu/operator] Softmax(forward)", "[Softmax][CPU]") { op->setBackend("cpu"); mySoftmax->forward(); - float* resPtr = static_cast<float*>(op->getOutput(0)->getImpl()->rawPtr()); - float* expectedPtr = static_cast<float*>(expectedOutput->getImpl()->rawPtr()); - for (std::size_t i = 0; i< expectedOutput->size(); ++i) { - REQUIRE(std::abs(resPtr[i]-expectedPtr[i]) < 0.00001); - } + REQUIRE(approxEq<float>(*op->getOutput(0), *expectedOutput, 0, 1E-5)); } } \ No newline at end of file diff --git a/unit_tests/operator/Test_SqrtImpl.cpp b/unit_tests/operator/Test_SqrtImpl.cpp index d630c66c8b8085e6d382841da6b7cac2c88b1dd0..6c65b5e8198be8f86072efc3711f7dfba5d58730 100644 --- a/unit_tests/operator/Test_SqrtImpl.cpp +++ b/unit_tests/operator/Test_SqrtImpl.cpp @@ -9,6 +9,7 @@ * ********************************************************************************/ +#include <aidge/utils/TensorUtils.hpp> #include <catch2/catch_test_macros.hpp> #include "aidge/data/Tensor.hpp" @@ -42,12 +43,7 @@ TEST_CASE("[cpu/operator] Sqrt(forward)", "[Sqrt][CPU]") { mySqrt->getOperator()->setBackend("cpu"); mySqrt->forward(); - float* resPtr = static_cast<float*>(op->getOutput(0)->getImpl()->rawPtr()); - float* expectedPtr = static_cast<float*>(expectedOutput->getImpl()->rawPtr()); - for (std::size_t i = 0; i< 4; ++i) { - REQUIRE(std::abs(resPtr[i]-expectedPtr[i]) < 0.00001); - } - + REQUIRE(approxEq<float>(*op->getOutput(0), *expectedOutput, 0, 1E-5)); } SECTION("4D Tensor") { @@ -112,10 +108,6 @@ TEST_CASE("[cpu/operator] Sqrt(forward)", "[Sqrt][CPU]") { mySqrt->getOperator()->setBackend("cpu"); mySqrt->forward(); - float* resPtr = static_cast<float*>(op->getOutput(0)->getImpl()->rawPtr()); - float* expectedPtr = static_cast<float*>(expectedOutput->getImpl()->rawPtr()); - for (std::size_t i = 0; i< 54; ++i) { - REQUIRE(std::abs(resPtr[i]-expectedPtr[i]) < 0.00001); - } + REQUIRE(approxEq<float>(*op->getOutput(0), *expectedOutput, 0, 1E-5)); } -} \ No newline at end of file +} \ No newline at end of file