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
17#ifndef _MIR_INDEX_H_
18#define _MIR_INDEX_H_
19
20#include <initializer_list>
21#include <cstdint>
22#include <ostream>
23
24#include "mir/Common.h"
25
26#include "adtidas/SmallVector.h"
27
28namespace mir
29{
30
31class Index
32{
33public:
34 Index() = default;
35
36 Index(std::initializer_list<int32_t> &&l) noexcept : _indices(std::move(l))
37 {
38 // DO NOTHING
39 }
40
41 explicit Index(size_t rank) : _indices(rank) {}
42
43 int32_t rank() const { return static_cast<int32_t>(_indices.size()); }
44
51 Index &resize(int32_t size);
52
57 Index &fill(int32_t index);
58
64 int32_t &at(int32_t axis) { return _indices[wrap_index(axis, _indices.size())]; }
65
71 int32_t at(int32_t axis) const { return _indices[wrap_index(axis, _indices.size())]; }
72
73private:
75};
76
77std::ostream &operator<<(std::ostream &s, const Index &idx);
78
79} // namespace mir
80
81#endif //_MIR_INDEX_H_
vector with cheap memory allocation
Definition SmallVector.h:34
size_t size() const noexcept
Definition SmallVector.h:67
Index(std::initializer_list< int32_t > &&l) noexcept
Definition Index.h:36
Index(size_t rank)
Definition Index.h:41
int32_t rank() const
Definition Index.h:43
Index()=default
Index & resize(int32_t size)
resize index to given dimension number
Definition Index.cpp:24
int32_t at(int32_t axis) const
return position on given axis
Definition Index.h:71
Index & fill(int32_t index)
fill all axis with index
Definition Index.cpp:30
int32_t & at(int32_t axis)
return position on given axis
Definition Index.h:64
std::ostream & operator<<(std::ostream &s, const Index &idx)
Definition Index.cpp:36
constexpr std::size_t wrap_index(std::int32_t index, std::size_t limit) noexcept
Definition Common.h:30
int32_t size[5]
Definition Slice.cpp:35