Skip to content
Snippets Groups Projects
Commit e1d961d9 authored by Houssem ROUIS's avatar Houssem ROUIS Committed by Maxence Naud
Browse files

added test for both shape initializations

parent 0fef5757
No related branches found
No related tags found
No related merge requests found
......@@ -20,56 +20,109 @@ using namespace Aidge;
TEST_CASE("[cpu/operator] Reshape(forward)") {
SECTION("1D Tensor") {
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<float,2> {
{2, 3}
});
std::shared_ptr<Tensor> expectedOutput = std::make_shared<Tensor>(Array2D<float,2,3> {
{
{1.0, 2.0, 3.0},
{4.0, 5.0, 6.0}
}
});
SECTION("Shape As Input") {
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<float,2> {
{2, 3}
});
std::shared_ptr<Tensor> expectedOutput = std::make_shared<Tensor>(Array2D<float,2,3> {
{
{1.0, 2.0, 3.0},
{4.0, 5.0, 6.0}
}
});
std::shared_ptr<Node> myReshape = Reshape();
auto op = std::static_pointer_cast<OperatorTensor>(myReshape -> getOperator());
op->associateInput(0, input);
op->associateInput(1, shape);
op->setDataType(DataType::Float32);
op->setBackend("cpu");
myReshape->forward();
std::shared_ptr<Node> myReshape = Reshape();
auto op = std::static_pointer_cast<OperatorTensor>(myReshape -> getOperator());
op->associateInput(0, input);
op->associateInput(1, shape);
op->setDataType(DataType::Float32);
op->setBackend("cpu");
myReshape->forward();
REQUIRE(*(op->getOutput(0)) == *expectedOutput);
REQUIRE(*(op->getOutput(0)) == *expectedOutput);
}
SECTION("Shape As Input") {
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> expectedOutput = std::make_shared<Tensor>(Array2D<float,2,3> {
{
{1.0, 2.0, 3.0},
{4.0, 5.0, 6.0}
}
});
std::shared_ptr<Node> myReshape = Reshape({2, 3});
auto op = std::static_pointer_cast<OperatorTensor>(myReshape -> getOperator());
op->associateInput(0, input);
// TODO find a way to avoid connecting an empty tensor
op->associateInput(1, std::make_shared<Tensor>(Tensor({})));
op->setDataType(DataType::Float32);
op->setBackend("cpu");
myReshape->forward();
REQUIRE(*(op->getOutput(0)) == *expectedOutput);
}
}
SECTION("2D Tensor") {
std::shared_ptr<Tensor> input = std::make_shared<Tensor>(Array2D<float,2,3> {
{
{1.0, 2.0, 3.0},
{4.0, 5.0, 6.0}
}
SECTION("2D Tensor - Shape Input") {
SECTION("Shape As Input") {
std::shared_ptr<Tensor> input = std::make_shared<Tensor>(Array2D<float,2,3> {
{
{1.0, 2.0, 3.0},
{4.0, 5.0, 6.0}
}
});
std::shared_ptr<Tensor> shape = std::make_shared<Tensor>(Array1D<float,2> {
{3, 2}
});
std::shared_ptr<Tensor> expectedOutput = std::make_shared<Tensor>(Array2D<float,3,2> {
{
{1.0, 2.0},
{3.0, 4.0},
{5.0, 6.0}
}
});
std::shared_ptr<Node> myReshape = Reshape();
auto op = std::static_pointer_cast<OperatorTensor>(myReshape -> getOperator());
op->associateInput(0, input);
op->associateInput(1, shape);
op->setDataType(DataType::Float32);
op->setBackend("cpu");
myReshape->forward();
REQUIRE(*(op->getOutput(0)) == *expectedOutput);
}
SECTION("Shape As Attribute") {
std::shared_ptr<Tensor> input = std::make_shared<Tensor>(Array2D<float,2,3> {
{
{1.0, 2.0, 3.0},
{4.0, 5.0, 6.0}
}
});
std::shared_ptr<Tensor> shape = std::make_shared<Tensor>(Array1D<float,2> {
{3, 2}
});
std::shared_ptr<Tensor> expectedOutput = std::make_shared<Tensor>(Array2D<float,3,2> {
{
{1.0, 2.0},
{3.0, 4.0},
{5.0, 6.0}
}
});
});
std::shared_ptr<Tensor> expectedOutput = std::make_shared<Tensor>(Array2D<float,3,2> {
{
{1.0, 2.0},
{3.0, 4.0},
{5.0, 6.0}
}
});
std::shared_ptr<Node> myReshape = Reshape();
auto op = std::static_pointer_cast<OperatorTensor>(myReshape -> getOperator());
op->associateInput(0, input);
op->associateInput(1, shape);
op->setDataType(DataType::Float32);
op->setBackend("cpu");
myReshape->forward();
std::shared_ptr<Node> myReshape = Reshape({3, 2});
auto op = std::static_pointer_cast<OperatorTensor>(myReshape -> getOperator());
op->associateInput(0, input);
// TODO find a way to avoid connecting an empty tensor
op->associateInput(1, std::make_shared<Tensor>(Tensor({})));
op->setDataType(DataType::Float32);
op->setBackend("cpu");
myReshape->forward();
REQUIRE(*(op->getOutput(0)) == *expectedOutput);
REQUIRE(*(op->getOutput(0)) == *expectedOutput);
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment