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 "luci/IR/Nodes/CircleConst.h"
24 template <loco::DataType DT> uint32_t CircleConst::size(void) const
26 assert(dtype() == DT);
27 assert(_data.size() % sizeof(typename loco::DataTypeImpl<DT>::Type) == 0);
28 return _data.size() / sizeof(typename loco::DataTypeImpl<DT>::Type);
31 template <loco::DataType DT> void CircleConst::size(uint32_t l)
33 assert(dtype() == DT);
34 _data.resize(l * sizeof(typename loco::DataTypeImpl<DT>::Type));
37 template <loco::DataType DT>
38 const typename loco::DataTypeImpl<DT>::Type &CircleConst::at(uint32_t n) const
40 assert(dtype() == DT);
41 assert(n < size<DT>());
42 return *(reinterpret_cast<const typename loco::DataTypeImpl<DT>::Type *>(_data.data()) + n);
45 template <loco::DataType DT> typename loco::DataTypeImpl<DT>::Type &CircleConst::at(uint32_t n)
47 assert(dtype() == DT);
48 assert(n < size<DT>());
49 return *(reinterpret_cast<typename loco::DataTypeImpl<DT>::Type *>(_data.data()) + n);
52 template <loco::DataType DT>
53 const typename loco::DataTypeImpl<DT>::Type &CircleConst::scalar(void) const
55 assert(dtype() == DT);
56 return *(reinterpret_cast<const typename loco::DataTypeImpl<DT>::Type *>(_data.data()));
59 template <loco::DataType DT> typename loco::DataTypeImpl<DT>::Type &CircleConst::scalar(void)
61 assert(dtype() == DT);
62 return *(reinterpret_cast<typename loco::DataTypeImpl<DT>::Type *>(_data.data()));
65 #define INSTANTIATE(DT) \
66 template uint32_t CircleConst::size<DT>(void) const; \
67 template void CircleConst::size<DT>(uint32_t); \
68 template const typename loco::DataTypeImpl<DT>::Type &CircleConst::at<DT>(uint32_t) const; \
69 template typename loco::DataTypeImpl<DT>::Type &CircleConst::at<DT>(uint32_t); \
70 template const typename loco::DataTypeImpl<DT>::Type &CircleConst::scalar<DT>(void) const; \
71 template typename loco::DataTypeImpl<DT>::Type &CircleConst::scalar<DT>(void);
73 INSTANTIATE(loco::DataType::S64);
74 INSTANTIATE(loco::DataType::S32);
75 INSTANTIATE(loco::DataType::S16);
76 INSTANTIATE(loco::DataType::FLOAT32);
77 INSTANTIATE(loco::DataType::U8);
78 INSTANTIATE(loco::DataType::BOOL);