-
Houssem ROUIS authoredHoussem ROUIS authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Test_ConcatImpl.cpp 2.02 KiB
/********************************************************************************
* Copyright (c) 2023 CEA-List
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
#include <catch2/catch_test_macros.hpp>
#include "aidge/data/Tensor.hpp"
#include "aidge/operator/Concat.hpp"
#include "aidge/backend/cpu.hpp"
#include <memory>
using namespace Aidge;
TEST_CASE("[cpu/operator] Concat(forward)") {
SECTION("2D Tensor") {
std::shared_ptr<Tensor> input1 = std::make_shared<Tensor>(Array2D<float,2,2> {
{
{0.00543531, 0.53726782},
{0.44371938, 0.93770550}
}
});
std::shared_ptr<Tensor> input2 = std::make_shared<Tensor>(Array2D<float,2,2> {
{
{0.87131297, 0.22378820},
{0.74409730, 0.72109798}
}
});
std::shared_ptr<Tensor> expectedOutput = std::make_shared<Tensor>(Array2D<float,2,4> {
{
{0.00543531, 0.53726782, 0.87131297, 0.22378820},
{0.44371938, 0.93770550, 0.74409730, 0.72109798}
}
});
std::shared_ptr<Node> myConcat = Concat(1);
myConcat->getOperator()->setDatatype(DataType::Float32);
myConcat->getOperator()->setBackend("cpu");
myConcat->getOperator()->associateInput(0,input1);
myConcat->getOperator()->associateInput(1,input2);
myConcat->getOperator()->computeOutputDims();
myConcat->forward();
float* resPtr = static_cast<float*>(myConcat->getOperator()->getOutput(0)->getImpl()->rawPtr());
float* expectedPtr = static_cast<float*>(expectedOutput->getImpl()->rawPtr());
for (std::size_t i = 0; i< 3; ++i) {
REQUIRE(std::abs(resPtr[i]-expectedPtr[i]) < 0.00001);
}
}
}