2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "kernels/Slice.h"
18 #include "kernels/TestUtils.h"
20 namespace luci_interpreter
27 using namespace testing;
29 template <typename T> class SliceTest : public ::testing::Test
33 using DataTypes = ::testing::Types<float, uint8_t>;
34 TYPED_TEST_CASE(SliceTest, DataTypes);
36 TYPED_TEST(SliceTest, SimpleTest)
38 std::vector<TypeParam> input_data{1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6};
39 Shape input_shape{3, 2, 3, 1};
40 std::vector<int32_t> begin_data{1, 0, 0, 0};
42 std::vector<int32_t> size_data{2, 1, -1, 1};
44 std::vector<TypeParam> output_data{3, 3, 3, 5, 5, 5};
45 std::vector<int32_t> output_shape{2, 1, 3, 1};
47 Tensor input_tensor = makeInputTensor<getElementType<TypeParam>()>(input_shape, input_data);
48 Tensor begin_tensor = makeInputTensor<DataType::S32>(begin_shape, begin_data);
49 Tensor size_tensor = makeInputTensor<DataType::S32>(size_shape, size_data);
51 Tensor output_tensor = makeOutputTensor(getElementType<TypeParam>());
53 Slice kernel(&input_tensor, &begin_tensor, &size_tensor, &output_tensor);
57 EXPECT_THAT(extractTensorData<TypeParam>(output_tensor),
58 ::testing::ElementsAreArray(output_data));
59 EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray(output_shape));
63 } // namespace kernels
64 } // namespace luci_interpreter