From e7e7ac2a58e44b392d44ee959fefee7d84907af4 Mon Sep 17 00:00:00 2001 From: NAUD Maxence <maxence.naud@cea.fr> Date: Mon, 18 Nov 2024 10:41:02 +0000 Subject: [PATCH] fix padding of resize, remove cpp17 clamp functions --- .../cpu/operator/ResizeImpl_kernels.hpp | 4 +- src/data/Interpolation.cpp | 48 +++++++++---------- unit_tests/operator/Test_ResizeImpl.cpp | 11 ++--- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/include/aidge/backend/cpu/operator/ResizeImpl_kernels.hpp b/include/aidge/backend/cpu/operator/ResizeImpl_kernels.hpp index aac3dc64..94efc9cb 100644 --- a/include/aidge/backend/cpu/operator/ResizeImpl_kernels.hpp +++ b/include/aidge/backend/cpu/operator/ResizeImpl_kernels.hpp @@ -45,8 +45,8 @@ void ResizeImpl_cpu_forward_kernel( const IO *input = static_cast<const IO *>(input_); IO *output = static_cast<IO *>(output_); - DimSize_t outputLen = std::accumulate(outputDims.begin(), - outputDims.end(), + const DimSize_t outputLen = std::accumulate(outputDims.cbegin(), + outputDims.cend(), 1, std::multiplies<DimSize_t>()); std::vector<float> coordInApprox; diff --git a/src/data/Interpolation.cpp b/src/data/Interpolation.cpp index 2d5494f7..c5a881bd 100644 --- a/src/data/Interpolation.cpp +++ b/src/data/Interpolation.cpp @@ -112,31 +112,31 @@ InterpolationCPU::linearRecurse(const std::vector<float> &coordToInterpolate, // points have not been all discriminated and must be further split // so we call linearRecurse() switch (lowerPoints.size()) { - case 0: { - return linearRecurse(coordToInterpolate, upperPoints, alongDim + 1); - } - case 1: { - break; - } - default: { - lowerPoints = - linearRecurse(coordToInterpolate, lowerPoints, alongDim + 1); - break; - } + case 0: { + return linearRecurse(coordToInterpolate, upperPoints, alongDim + 1); + } + case 1: { + break; + } + default: { + lowerPoints = + linearRecurse(coordToInterpolate, lowerPoints, alongDim + 1); + break; + } } switch (upperPoints.size()) { - case 0: { - return linearRecurse(coordToInterpolate, lowerPoints, alongDim + 1); - } - case 1: { - break; - } - default: { - upperPoints = - linearRecurse(coordToInterpolate, upperPoints, alongDim + 1); - break; - } + case 0: { + return linearRecurse(coordToInterpolate, lowerPoints, alongDim + 1); + } + case 1: { + break; + } + default: { + upperPoints = + linearRecurse(coordToInterpolate, upperPoints, alongDim + 1); + break; + } } // At this point lowerPoints & upperPoints are garanteed to be @@ -164,8 +164,8 @@ InterpolationCPU::linearRecurse(const std::vector<float> &coordToInterpolate, // interpolate interpolatedPoint.first[alongDim] = 0; Log::debug("successfully returned from alongDim : {}", alongDim); - return std::set({interpolatedPoint}); -}; + return std::set<Point<T>>({interpolatedPoint}); +} template <typename T> T InterpolationCPU::linear(const std::vector<float> &coordToInterpolate, diff --git a/unit_tests/operator/Test_ResizeImpl.cpp b/unit_tests/operator/Test_ResizeImpl.cpp index b0073162..161a5094 100644 --- a/unit_tests/operator/Test_ResizeImpl.cpp +++ b/unit_tests/operator/Test_ResizeImpl.cpp @@ -9,20 +9,19 @@ * ********************************************************************************/ +#include <cstdint> +#include <memory> + #include <aidge/data/Data.hpp> #include <aidge/data/Interpolation.hpp> #include <aidge/data/half.hpp> #include <aidge/operator/Pad.hpp> #include <aidge/utils/ArrayHelpers.hpp> #include <catch2/catch_test_macros.hpp> -#include <cstdint> -#include <memory> #include "aidge/data/Tensor.hpp" #include "aidge/operator/OperatorTensor.hpp" - #include "aidge/operator/Resize.hpp" - #include "aidge/utils/TensorUtils.hpp" namespace Aidge { @@ -83,7 +82,7 @@ TEST_CASE("[cpu/operator] Resize(forward)", "[Resize][CPU]") { op, Interpolation::Linear, Interpolation::CoordinateTransformation::HalfPixel, - PadBorderType::Nearest, + PadBorderType::Edge, std::make_shared<Tensor>( Array4D<float, 1, 1, 1, 1>{{{{{0.417022}}}}}), nullptr, @@ -102,7 +101,7 @@ TEST_CASE("[cpu/operator] Resize(forward)", "[Resize][CPU]") { op, Interpolation::Linear, Interpolation::Asymmetric, - PadBorderType::Nearest, + PadBorderType::Edge, std::make_shared<Tensor>( Array4D<float, 1, 1, 5, 5>{{{{{7.20324516e-01, 1.14374816e-04, -- GitLab