2 * Copyright (c) 2022 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/Shape.h"
18 #include "kernels/Utils.h"
20 namespace luci_interpreter
25 ShapeKernel::ShapeKernel(const Tensor *input, Tensor *output, const ShapeParams ¶ms)
26 : KernelWithParams<ShapeParams>({input}, {output}, params)
30 void ShapeKernel::configure()
32 LUCI_INTERPRETER_CHECK(output()->element_type() == DataType::S32 or
33 output()->element_type() == DataType::S64);
34 const auto input_shape = input()->shape();
36 Shape output_shape(1);
37 output_shape.dim(0) = input_shape.num_dims();
39 output()->resize(output_shape);
42 void ShapeKernel::execute() const
44 switch (params().out_type)
53 throw std::runtime_error("Unsupported type.");
57 template <typename T> void ShapeKernel::evalInt() const
59 const auto input_shape = input()->shape();
61 auto output_data = getTensorData<T>(output());
63 for (int i = 0; i < input_shape.num_dims(); ++i)
65 output_data[i] = input_shape.dim(i);
69 } // namespace kernels
70 } // namespace luci_interpreter