ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Index.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 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
22#ifndef __NNFW_MISC_TENSOR_INDEX_H__
23#define __NNFW_MISC_TENSOR_INDEX_H__
24
25#include <cstdint>
26#include <cstddef>
27
28#include <vector>
29#include <initializer_list>
30
31namespace nnfw
32{
33namespace misc
34{
35namespace tensor
36{
37
41struct Index
42{
43public:
48 Index(uint32_t rank) { _offsets.resize(rank); }
49
50public:
55 Index(std::initializer_list<int32_t> offsets) : _offsets{offsets}
56 {
57 // DO NOTHING
58 }
59
60public:
67 uint32_t rank(void) const { return static_cast<uint32_t>(_offsets.size()); }
68
69public:
75 int32_t at(uint32_t n) const { return _offsets.at(n); }
76
82 int32_t &at(uint32_t n) { return _offsets.at(n); }
83
84private:
85 std::vector<int32_t> _offsets;
86};
87
94inline static Index copy_reverse(const Index &origin)
95{
96 uint32_t rank = origin.rank();
97 Index target(rank);
98 for (uint32_t i = 0; i < rank; i++)
99 target.at(i) = origin.at(rank - 1 - i);
100 return target;
101}
102
103} // namespace tensor
104} // namespace misc
105} // namespace nnfw
106
107#endif // __NNFW_MISC_TENSOR_INDEX_H__
Definition topk_v2.h:30
Struct to represent index of each dimension of a tensor.
Definition Index.h:42
uint32_t rank(void) const
Get the rank.
Definition Index.h:67
Index(uint32_t rank)
Construct a new Index object.
Definition Index.h:48
int32_t at(uint32_t n) const
Get the index n'th dimension.
Definition Index.h:75
Index(std::initializer_list< int32_t > offsets)
Construct a new Index object.
Definition Index.h:55
int32_t & at(uint32_t n)
Get the reference of the index n'th dimension.
Definition Index.h:82