diff --git a/include/aidge/backend/cpu/operator/ReshapeImpl_forward_kernels.hpp b/include/aidge/backend/cpu/operator/ReshapeImpl_forward_kernels.hpp index d47476c456de8e60dc68e90e0d9ae28c59a73811..cefdab57ee41ffab0b98a87698d95f5d89a0206d 100644 --- a/include/aidge/backend/cpu/operator/ReshapeImpl_forward_kernels.hpp +++ b/include/aidge/backend/cpu/operator/ReshapeImpl_forward_kernels.hpp @@ -20,13 +20,13 @@ namespace Aidge { template <class I, class O> void ReshapeImpl_cpu_forward_kernel(std::size_t inputLength, - const void* input1_, + const void* input_, void* output_) { - const I* input_1 = static_cast<const I*>(input1_); + const I* input = static_cast<const I*>(input_); O* output = static_cast<O*>(output_); - std::copy_n(input_1, inputLength, output); + std::copy_n(input, inputLength, output); } namespace { diff --git a/src/operator/ReshapeImpl.cpp b/src/operator/ReshapeImpl.cpp index 0e1d92cf3fc535826c063088b3ea1f6a6b5fbab6..02dea1da3d4422abf37b62193bba83e83c87a83f 100644 --- a/src/operator/ReshapeImpl.cpp +++ b/src/operator/ReshapeImpl.cpp @@ -10,10 +10,6 @@ ********************************************************************************/ #include <cassert> -#include <chrono> // std::chrono::milliseconds -#include <numeric> // std::accumulate -#include <thread> // std::this_thread::sleep_for -#include <vector> #include "aidge/operator/Reshape.hpp" #include "aidge/utils/Types.h" @@ -27,17 +23,9 @@ Aidge::NbElts_t Aidge::ReshapeImpl_cpu::getNbRequiredProtected(const Aidge::IOIn } void Aidge::ReshapeImpl_cpu::forward() { - - std::size_t outputSize = 1; - - int* shape = static_cast<int*>(std::static_pointer_cast<Tensor>(mOp.getRawInput(1))->getImpl()->rawPtr()); - for(std::size_t i= 0; i<std::static_pointer_cast<Tensor>(mOp.getRawInput(1))->size(); ++i) - { - assert(shape[i]>0 && "all input #1 elements must be >0"); - outputSize *= shape[i]; - } - assert((std::static_pointer_cast<Tensor>(mOp.getRawInput(0))->size() == outputSize) && - "the shape given in input #1 must give the same size of input #0"); + assert(std::static_pointer_cast<Tensor>(mOp.getRawInput(0))->size() == + std::static_pointer_cast<Tensor>(mOp.getRawOutput(0))->size() + && "input must have the same overall size as shape"); // Find the correct kernel type auto kernelFunc = Registrar<ReshapeImplForward_cpu>::create({ diff --git a/unit_tests/operator/Test_ReshapeImpl.cpp b/unit_tests/operator/Test_ReshapeImpl.cpp index af0f4476cafc59d26ab7a17875578385173b672c..1fee1f4cd132acf9ee39a86759f2e628317fce19 100644 --- a/unit_tests/operator/Test_ReshapeImpl.cpp +++ b/unit_tests/operator/Test_ReshapeImpl.cpp @@ -25,7 +25,6 @@ TEST_CASE("[cpu/operator] Reshape(forward)") { std::shared_ptr<Tensor> input = std::make_shared<Tensor>(Array1D<float,6> { {1.0, 2.0, 3.0, 4.0, 5.0, 6.0} }); - std::shared_ptr<Tensor> shape = std::make_shared<Tensor>(Array1D<int,2>{{2, 3}}); std::shared_ptr<Tensor> expectedOutput = std::make_shared<Tensor>(Array2D<float,2,3> { { {1.0, 2.0, 3.0}, @@ -33,10 +32,9 @@ TEST_CASE("[cpu/operator] Reshape(forward)") { } }); - std::shared_ptr<Node> myReshape = Reshape(); + std::shared_ptr<Node> myReshape = Reshape({2, 3}); auto op = std::static_pointer_cast<OperatorTensor>(myReshape -> getOperator()); op->associateInput(0, input); - op->associateInput(1, shape); op->setDataType(DataType::Float32); op->setBackend("cpu"); op->computeOutputDims(); @@ -52,7 +50,6 @@ TEST_CASE("[cpu/operator] Reshape(forward)") { } }); - std::shared_ptr<Tensor> shape = std::make_shared<Tensor>(Array1D<int,2>{{3, 2}}); std::shared_ptr<Tensor> expectedOutput = std::make_shared<Tensor>(Array2D<float,3,2> { { {1.0, 2.0}, @@ -61,10 +58,9 @@ TEST_CASE("[cpu/operator] Reshape(forward)") { } }); - std::shared_ptr<Node> myReshape = Reshape(); + std::shared_ptr<Node> myReshape = Reshape({3, 2}); auto op = std::static_pointer_cast<OperatorTensor>(myReshape -> getOperator()); op->associateInput(0, input); - op->associateInput(1, shape); op->setDataType(DataType::Float32); op->setBackend("cpu"); op->computeOutputDims();