diff --git a/unit_tests/operator/Test_SliceImpl.cpp b/unit_tests/operator/Test_SliceImpl.cpp index a513f73ac7a7e7d5bb19b23789fd8ff8405be8a9..2b9f89e62c09c04a7f848c362336418ef62aecce 100644 --- a/unit_tests/operator/Test_SliceImpl.cpp +++ b/unit_tests/operator/Test_SliceImpl.cpp @@ -228,4 +228,52 @@ TEST_CASE("[cpu/operator] Slice(forward)", "[Slice][CPU]") { REQUIRE(op->getOutput(0)->dims() == expectedOutput->dims()); 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()); + } }