a361d8dd2c2cabf535d08af5dc917d872c764896
[platform/core/ml/nnfw.git] / runtime / libs / misc / include / misc / feature / Index.h
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 /**
18  * @file     Index.h
19  * @brief    This file contains Index class
20  * @ingroup  COM_AI_RUNTIME
21  */
22
23 #ifndef __NNFW_MISC_FEATURE_INDEX_H__
24 #define __NNFW_MISC_FEATURE_INDEX_H__
25
26 #include <cstdint>
27
28 namespace nnfw
29 {
30 namespace misc
31 {
32 namespace feature
33 {
34
35 /**
36  * @brief  Class to have the index information for calculating the offset.
37  */
38 class Index
39 {
40 public:
41   /**
42    * @brief  Construct Index object using default constrcutor
43    */
44   Index() = default;
45
46 public:
47   /**
48    * @brief  Construct Index object with three indexes of dimensions
49    * @param[in]  ch    The depth index
50    * @param[in]  row   The heigth index
51    * @param[in]  col   The width index
52    */
53   Index(int32_t ch, int32_t row, int32_t col) : _batch{1}, _ch{ch}, _row{row}, _col{col}
54   {
55     // DO NOTHING
56   }
57   /**
58    * @brief  Construct Index object with four indexes of dimensions
59    * @param[in]  batch The batch index
60    * @param[in]  ch    The depth index
61    * @param[in]  row   The height index
62    * @param[in]  col   The width index
63    */
64   Index(int32_t batch, int32_t ch, int32_t row, int32_t col)
65       : _batch{batch}, _ch{ch}, _row{row}, _col{col}
66   {
67     // DO NOTHING
68   }
69
70 public:
71   /**
72    * @brief   Get the batch index
73    * @return  The batch index
74    */
75   int32_t batch(void) const { return _batch; }
76   /**
77    * @brief   Get the depth index
78    * @return  The depth index
79    */
80   int32_t ch(void) const { return _ch; }
81   /**
82    * @brief   Get the height index
83    * @return  The height index
84    */
85   int32_t row(void) const { return _row; }
86   /**
87    * @brief   Get the width index
88    * @return  The width index
89    */
90   int32_t col(void) const { return _col; }
91
92 public:
93   /**
94    * @brief   Get the batch index as the lvalue reference
95    * @return  The reference of the batch value
96    */
97   int32_t &batch(void) { return _batch; }
98   /**
99    * @brief   Get the depth index as the lvalue reference
100    * @return  The reference of the depth value
101    */
102   int32_t &ch(void) { return _ch; }
103   /**
104    * @brief   Get the height index as the lvalue reference
105    * @return  The reference of the height value
106    */
107   int32_t &row(void) { return _row; }
108   /**
109    * @brief   Get the width index as the lvalue reference
110    * @return  The reference of the width value
111    */
112   int32_t &col(void) { return _col; }
113
114 private:
115   /**
116    * @brief  The batch index
117    */
118   int32_t _batch;
119   /**
120    * @brief  The depth index
121    */
122   int32_t _ch;
123   /**
124    * @brief  The height index
125    */
126   int32_t _row;
127   /**
128    * @brief  The width index
129    */
130   int32_t _col;
131 };
132
133 } // namespace feature
134 } // namespace misc
135 } // namespace nnfw
136
137 #endif // __NNFW_MISC_FEATURE_INDEX_H__