Skip to content
Snippets Groups Projects

Fix Reshape

Merged Houssem ROUIS requested to merge hrouis/aidge_core:fix_reshape into dev
1 file
+ 98
45
Compare changes
  • Side-by-side
  • Inline
@@ -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
Loading