ONE - On-device Neural Engine
Loading...
Searching...
No Matches
CircleRange.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 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
18
19#include "CircleCloneNode.h"
21
22#include <cmath>
23
24namespace luci
25{
26
28{
29 return _graph->nodes()->create<luci::CircleRange>();
30}
31
32namespace sinf
33{
34
36{
38 output_shape.rank(1);
39
40 auto start_node = dynamic_cast<luci::CircleConst *>(node->start());
41 auto limit_node = dynamic_cast<luci::CircleConst *>(node->limit());
42 auto delta_node = dynamic_cast<luci::CircleConst *>(node->delta());
43
44 if (start_node == nullptr || limit_node == nullptr || delta_node == nullptr)
45 {
46 return output_shape;
47 }
48
49 double start = 0, limit = 0, delta = 0;
50
51#define GET_RANGE_PARAM(DT) \
52 start = start_node->scalar<DT>(); \
53 limit = limit_node->scalar<DT>(); \
54 delta = delta_node->scalar<DT>();
55
56 switch (start_node->dtype())
57 {
58 case loco::DataType::FLOAT32:
59 GET_RANGE_PARAM(loco::DataType::FLOAT32)
60 break;
61 case loco::DataType::S32:
62 GET_RANGE_PARAM(loco::DataType::S32)
63 break;
64 default:
65 INTERNAL_EXN("Range data type not supported");
66 }
67
68#undef GET_RANGE_PARAM
69
70 if (delta == 0)
71 INTERNAL_EXN("Delta can not be zero");
72
73 /*
74 * Pre-condition
75 * 'limit - start' and 'delta' have the same sign.
76 * c1. '(limit - start) >= 0' -> 'delta > 0'
77 * c2. '(limit - start) < 0' -> 'delta < 0'
78 * https://github.com/tensorflow/tensorflow/blob/da82fa9/tensorflow/lite/kernels/range.cc#L49-L50
79 */
80 assert((start >= limit && delta < 0) || (start <= limit && delta > 0));
81 output_shape.dim(0) = ceil((limit - start) / delta);
82
83 return output_shape;
84}
85
86} // namespace sinf
87
88} // namespace luci
#define INTERNAL_EXN(msg)
@ brief throw internal exception with message
Definition InternalExn.h:25
Class to build tensor data.
Definition CircleConst.h:35
RANGE in Circle.
Definition CircleRange.h:32
loco::Node * delta(void) const
Definition CircleRange.h:40
loco::Node * limit(void) const
Definition CircleRange.h:37
loco::Node * start(void) const
Definition CircleRange.h:34
loco::TensorShape visit(const luci::CircleNode *node) final
Default fallback.
const luci_interpreter::RuntimeShape output_shape
#define GET_RANGE_PARAM(DT)