Skip to content
Snippets Groups Projects
Commit d3a367f6 authored by Houssem ROUIS's avatar Houssem ROUIS
Browse files

add unit test for Slice with different steps

parent 219a7d54
No related branches found
No related tags found
2 merge requests!73version 0.2.3,!65Add missing attributes to operators
...@@ -228,4 +228,52 @@ TEST_CASE("[cpu/operator] Slice(forward)", "[Slice][CPU]") { ...@@ -228,4 +228,52 @@ TEST_CASE("[cpu/operator] Slice(forward)", "[Slice][CPU]") {
REQUIRE(op->getOutput(0)->dims() == expectedOutput->dims()); REQUIRE(op->getOutput(0)->dims() == expectedOutput->dims());
REQUIRE(op->getOutput(0)->dataType() == expectedOutput->dataType()); REQUIRE(op->getOutput(0)->dataType() == expectedOutput->dataType());
} }
SECTION("Different Steps") {
std::shared_ptr<Tensor> input0 = std::make_shared<Tensor>(Array3D<int,4,2,8> {
{
{
{ 0, 1, 2,-3, 4,-5,-6,7},
{-5, 4, 2,-3, 4,-5,-6,-7}
},
{
{ 10, 11, 12,-13, 14,-15,-16,17},
{-15, 14, 12,-13, 14,-15,-16,-17}
},
{
{ 20, 21, 22,-23, 24,-25,-26,27},
{-25, 24, 22,-23, 24,-25,-26,-27}
},
{
{ 30, 31, 32,-33, 34,-35,-36,37},
{-35, 34, 32,-33, 34,-35,-36,-37}
}
}
});
std::shared_ptr<Tensor> expectedOutput = std::make_shared<Tensor>(Array3D<int,2,1,3> {
{
{
{ 7, 4, 1}
},
{
{ 27, 24, 21}
}
}
});
std::shared_ptr<Node> mySlice = Slice({0,0,7}, {4,1,0}, {0,1,2}, {2,1,-3});
// Steps are 2,1,-3 so the slice will be:
// on Axis 0: from 0 to 4 by step of 2
// on Axis 1: from 0 to 1 by step of 1
// on Axis 2: from 7 to 0 by step of -3 (reverse the order of elements)
auto op = std::static_pointer_cast<OperatorTensor>(mySlice -> getOperator());
mySlice->getOperator()->associateInput(0,input0);
mySlice->getOperator()->setDataType(DataType::Int32);
mySlice->getOperator()->setBackend("cpu");
mySlice->forward();
op->getOutput(0)->print();
REQUIRE(*(op->getOutput(0)) == *expectedOutput);
REQUIRE(op->getOutput(0)->dims() == expectedOutput->dims());
REQUIRE(op->getOutput(0)->dataType() == expectedOutput->dataType());
}
} }
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