Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / runtime / onert / backend / cpu / ops / RankLayer.cc
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "RankLayer.h"
18
19 #include "OperationUtils.h"
20
21 namespace onert
22 {
23 namespace backend
24 {
25 namespace cpu
26 {
27 namespace ops
28 {
29
30 RankLayer::RankLayer() : _input(nullptr), _output(nullptr)
31 {
32   // DO NOTHING
33 }
34
35 void RankLayer::configure(const IPortableTensor *input, IPortableTensor *output)
36 {
37   _input = input;
38   _output = output;
39 }
40
41 void RankLayer::run()
42 {
43   if (_input->data_type() == OperandType::FLOAT32 || _input->data_type() == OperandType::INT32)
44   {
45     int32_t *output_data = reinterpret_cast<int32_t *>(_output->buffer());
46     output_data[0] = _input->num_dimensions();
47   }
48   else
49   {
50     throw std::runtime_error{"Rank : unsupported data type"};
51   }
52 }
53
54 } // namespace ops
55 } // namespace cpu
56 } // namespace backend
57 } // namespace onert