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/Rsqrt.h"
18 #include "kernels/TestUtils.h"
19 #include "luci_interpreter/TestMemoryManager.h"
21 namespace luci_interpreter
28 using namespace testing;
30 void Check(std::initializer_list<int32_t> input_shape, std::initializer_list<int32_t> output_shape,
31 std::initializer_list<float> input_data, std::initializer_list<float> output_data)
33 std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>();
36 makeInputTensor<DataType::FLOAT32>(input_shape, input_data, memory_manager.get());
37 Tensor output_tensor = makeOutputTensor(DataType::FLOAT32);
39 Rsqrt kernel(&input_tensor, &output_tensor);
41 memory_manager->allocate_memory(output_tensor);
44 EXPECT_THAT(extractTensorData<float>(output_tensor), FloatArrayNear(output_data));
45 EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray(output_shape));
48 TEST(RsqrtTest, SimpleRsqrt)
51 /*input_shape=*/{1, 2, 4, 1}, /*output_shape=*/{1, 2, 4, 1},
59 0.44721360, 0.5, 0.35355339, 0.70710678, //
60 0.40824829, 0.36514837, 0.33333333, 1.8257419, //
64 TEST(RsqrtTest, Input_Output_Type_NEG)
66 std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>();
68 Tensor input_tensor = makeInputTensor<DataType::FLOAT32>({1}, {1.f}, memory_manager.get());
69 Tensor output_tensor = makeOutputTensor(DataType::S32);
71 Rsqrt kernel(&input_tensor, &output_tensor);
72 EXPECT_ANY_THROW(kernel.configure());
75 TEST(RsqrtTest, Invalid_Input_Type_NEG)
77 std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>();
79 Tensor input_tensor = makeInputTensor<DataType::S64>({1}, {1}, memory_manager.get());
80 Tensor output_tensor = makeOutputTensor(DataType::S64);
82 Rsqrt kernel(&input_tensor, &output_tensor);
84 memory_manager->allocate_memory(output_tensor);
85 EXPECT_ANY_THROW(kernel.execute());
89 } // namespace kernels
90 } // namespace luci_interpreter