ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Index.cpp
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
#include "
nncc/core/ADT/tensor/Index.h
"
18
19
#include <stdexcept>
20
#include <algorithm>
21
22
namespace
nncc
23
{
24
namespace
core
25
{
26
namespace
ADT
27
{
28
namespace
tensor
29
{
30
31
Index::Index
(std::initializer_list<uint32_t> &&l) : _indices{l}
32
{
33
// DO NOTHING
34
}
35
36
uint32_t
Index::rank
(
void
)
const
{
return
_indices.size(); }
37
Index
&
Index::resize
(uint32_t
size
)
38
{
39
_indices.resize(
size
);
40
return
*
this
;
41
}
42
43
Index
&
Index::fill
(uint32_t index)
44
{
45
std::fill(_indices.begin(), _indices.end(), index);
46
return
(*
this
);
47
}
48
49
uint32_t &
Index::at
(uint32_t axis) {
return
_indices.at(axis); }
50
uint32_t
Index::at
(uint32_t axis)
const
{
return
_indices.at(axis); }
51
52
Index
operator+
(
const
Index
&lhs,
const
Index
&rhs)
53
{
54
if
(lhs.
rank
() != rhs.
rank
())
55
throw
std::runtime_error(
"Two tensors should have same rank"
);
56
57
Index
ret;
58
ret.
resize
(lhs.
rank
());
59
for
(uint32_t axis = 0; axis < lhs.
rank
(); axis++)
60
{
61
ret.
at
(axis) = lhs.
at
(axis) + rhs.
at
(axis);
62
}
63
return
ret;
64
}
65
66
bool
operator==
(
const
Index
&lhs,
const
Index
&rhs)
67
{
68
if
(lhs.
rank
() != rhs.
rank
())
69
return
false
;
70
for
(uint32_t axis = 0; axis < lhs.
rank
(); axis++)
71
{
72
if
(lhs.
at
(axis) != rhs.
at
(axis))
73
return
false
;
74
}
75
return
true
;
76
}
77
78
}
// namespace tensor
79
}
// namespace ADT
80
}
// namespace core
81
}
// namespace nncc
nncc::core::ADT::tensor::Index
Definition
Index.h:34
nncc::core::ADT::tensor::Index::resize
Index & resize(uint32_t size)
Definition
Index.cpp:37
nncc::core::ADT::tensor::Index::Index
Index()=default
nncc::core::ADT::tensor::Index::at
uint32_t & at(uint32_t axis)
Definition
Index.cpp:49
nncc::core::ADT::tensor::Index::fill
Index & fill(uint32_t index)
Definition
Index.cpp:43
nncc::core::ADT::tensor::Index::rank
uint32_t rank(void) const
Definition
Index.cpp:36
Index.h
GenH5RandomInputs.tensor
tensor
Definition
GenH5RandomInputs.py:61
nncc::core::ADT::tensor::operator==
bool operator==(const Index &lhs, const Index &rhs)
Definition
Index.cpp:66
nncc::core::ADT::tensor::operator+
Index operator+(const Index &lhs, const Index &rhs)
Definition
Index.cpp:52
nncc
Definition
Accessor.h:23
size
int32_t size[5]
Definition
Slice.cpp:35
compiler
angkor
src
ADT
tensor
Index.cpp
Generated by
1.9.8