ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Object.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
23#ifndef __NNFW_MISC_FEATURE_OBJECT_H__
24#define __NNFW_MISC_FEATURE_OBJECT_H__
25
26#include "misc/feature/Shape.h"
27#include "misc/feature/Index.h"
28#include "misc/feature/Reader.h"
29
30#include <vector>
31
32namespace nnfw
33{
34namespace misc
35{
36namespace feature
37{
38
42template <typename T> class Object final : public Reader<T>
43{
44public:
45 using Generator = std::function<T(const Shape &shape, const Index &index)>;
46
47public:
53 Object(const Shape &shape, const Generator &fn) : _shape{shape}
54 {
55 _value.resize(_shape.C * _shape.H * _shape.W);
56
57 for (int32_t ch = 0; ch < _shape.C; ++ch)
58 {
59 for (int32_t row = 0; row < _shape.H; ++row)
60 {
61 for (int32_t col = 0; col < _shape.W; ++col)
62 {
63 _value.at(offsetOf(ch, row, col)) = fn(_shape, Index{ch, row, col});
64 }
65 }
66 }
67 }
68
69public:
74 const Shape &shape(void) const { return _shape; }
75
76public:
84 T at(uint32_t ch, uint32_t row, uint32_t col) const override
85 {
86 return _value.at(offsetOf(ch, row, col));
87 }
88
89private:
97 uint32_t offsetOf(uint32_t ch, uint32_t row, uint32_t col) const
98 {
99 return ch * _shape.H * _shape.W + row * _shape.W + col;
100 }
101
102private:
106 Shape _shape;
110 std::vector<T> _value;
111};
112
113} // namespace feature
114} // namespace misc
115} // namespace nnfw
116
117#endif // __NNFW_MISC_FEATURE_OBJECT_H__
Class to have the index information for calculating the offset.
Definition Index.h:39
Class to have information of the operand for feature.
Definition Object.h:43
const Shape & shape(void) const
Get Shape of feature as the reference.
Definition Object.h:74
Object(const Shape &shape, const Generator &fn)
Construct Object object with Shape of feature and set value used by Generator.
Definition Object.h:53
std::function< T(const Shape &shape, const Index &index)> Generator
Definition Object.h:45
T at(uint32_t ch, uint32_t row, uint32_t col) const override
Get the value used by three indexes.
Definition Object.h:84
Definition topk_v2.h:30
This file contains Index class.
This file contains Reader class.
This file contains Shape class for feature.
Definition Shape.h:28
Class reads values of feature The interface class.
Definition Reader.h:40
Structure to have values of dimensions for feature.
Definition Shape.h:39