blob: d0dcc8a57b81d987b5e4c85af09b9a6212810784 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
// Copyright (C) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
/**
* @brief a header file for describing property style structure used by CNNLayers
* @file ie_layers_property.h
*/
#pragma once
namespace InferenceEngine {
constexpr const int MAX_DIMS_NUMBER = 12;
enum eDIMS_AXIS : uint8_t {
X_AXIS = 0,
Y_AXIS,
Z_AXIS
};
template<class T, int N = MAX_DIMS_NUMBER>
class PropertyVector {
T _axises[N] = {};
bool _allocated[N] = {};
size_t _length = 0;
public:
PropertyVector() = default;
PropertyVector(size_t len, T val) {
if (len > N) {
THROW_IE_EXCEPTION << "Property size exceeed limit of: " << N;
}
for (int i = 0; i < len; i++) {
_axises[i] = val;
_allocated[i] = true;
}
_length = len;
}
/**
* @brief allows access up-to capacity size
* @param index
* @return
*/
T &at(int index) {
if (index >= N) {
THROW_IE_EXCEPTION << "Property index is out of bounds(" << index << "/" << N;
}
return _axises[index];
}
const T &operator[](size_t index) const {
if (index >= N ||!_allocated[index]) {
THROW_IE_EXCEPTION << "Property index ("<< index <<")is out of bounds";
}
return _axises[index];
}
T &operator[](size_t index) {
if (index >= N || !_allocated[index]) {
THROW_IE_EXCEPTION << "Property index ("<< index <<")is out of bounds";
}
return _axises[index];
}
PropertyVector &operator=(const PropertyVector &src) {
if (this != &src) {
_length = src.size();
for (size_t i = 0; i < N; i++) {
_allocated[i] = src._allocated[i];
if (_allocated[i]) {
_axises[i] = src[i];
}
}
}
return *this;
}
bool operator==(const PropertyVector& src) const {
if (this == &src) return true;
if (_length != src.size()) return false;
for (size_t i = 0; i < N; i++)
if ((_allocated[i] != src._allocated[i]) ||
(_allocated[i] && _axises[i] != src._axises[i])) return false;
return true;
}
size_t size() const {
return _length;
}
void insert(size_t axis, const T &val) {
if (axis < N) {
if (!_allocated[axis]) {
_allocated[axis] = true;
_length++;
}
_axises[axis] = val;
} else {
THROW_IE_EXCEPTION << "Layer Property insertion at(axis) should be in [0,"<< N<< ")";
}
}
void remove(size_t axis) {
if (axis < N && _allocated[axis]) {
_allocated[axis] = false;
_length--;
}
}
void clear() {
for (int i = 0; i != N; i++) {
_allocated[i] = 0;
}
_length = 0u;
}
bool exist(size_t axis) const {
return (axis < N && _allocated[axis]);
}
};
} // namespace InferenceEngine
|