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"
19 #include "luci_interpreter/TestMemoryManager.h"
21 namespace luci_interpreter
28 using namespace testing;
30 template <typename T> class SliceTest : public ::testing::Test
34 using DataTypes = ::testing::Types<float, uint8_t>;
35 TYPED_TEST_CASE(SliceTest, DataTypes);
37 TYPED_TEST(SliceTest, SimpleTest)
39 std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>();
41 std::vector<TypeParam> input_data{1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6};
42 Shape input_shape{3, 2, 3, 1};
43 std::vector<int32_t> begin_data{1, 0, 0, 0};
45 std::vector<int32_t> size_data{2, 1, -1, 1};
47 std::vector<TypeParam> output_data{3, 3, 3, 5, 5, 5};
48 std::vector<int32_t> output_shape{2, 1, 3, 1};
51 makeInputTensor<getElementType<TypeParam>()>(input_shape, input_data, memory_manager.get());
53 makeInputTensor<DataType::S32>(begin_shape, begin_data, memory_manager.get());
54 Tensor size_tensor = makeInputTensor<DataType::S32>(size_shape, size_data, memory_manager.get());
56 Tensor output_tensor = makeOutputTensor(getElementType<TypeParam>());
58 Slice kernel(&input_tensor, &begin_tensor, &size_tensor, &output_tensor);
60 memory_manager->allocate_memory(output_tensor);
63 EXPECT_THAT(extractTensorData<TypeParam>(output_tensor),
64 ::testing::ElementsAreArray(output_data));
65 EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray(output_shape));
69 } // namespace kernels
70 } // namespace luci_interpreter