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 "ShapeLayer.h"
19 #include "OperationUtils.h"
30 ShapeLayer::ShapeLayer() : _input(nullptr), _output(nullptr)
35 template <typename T> void GetRawShape(const IPortableTensor *input, T *output_data)
37 auto shape = input->getShape();
38 for (int i = 0; i < shape.rank(); ++i)
40 output_data[i] = static_cast<T>(shape.dim(i));
44 void ShapeLayer::configure(const IPortableTensor *input, IPortableTensor *output)
50 void ShapeLayer::run()
52 if (_output->data_type() == OperandType::UINT32)
54 GetRawShape(_input, getBuffer<uint32_t>(_output));
56 else if (_output->data_type() == OperandType::INT32)
58 GetRawShape(_input, getBuffer<int32_t>(_output));
60 else if (_output->data_type() == OperandType::INT64)
62 GetRawShape(_input, getBuffer<int64_t>(_output));
66 throw std::runtime_error{"NYI : not supported output type for ShapeLayer"};
72 } // namespace backend