Compute Library
 21.08
SimpleTensorAccessor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #ifndef ARM_COMPUTE_TEST_SIMPLE_TENSOR_ACCESSOR_H
25 #define ARM_COMPUTE_TEST_SIMPLE_TENSOR_ACCESSOR_H
26 
27 #include "SimpleTensor.h"
28 #include "tests/IAccessor.h"
29 
30 namespace arm_compute
31 {
32 namespace test
33 {
34 /** Accessor implementation for @ref SimpleTensor objects. */
35 template <typename T>
37 {
38 public:
39  /** Create an accessor for the given @p tensor.
40  *
41  * @param[in, out] tensor To be accessed tensor.
42  */
44 
45  /** Prevent instances of this class from being copy constructed */
47  /** Prevent instances of this class from being copied */
49  /** Allow instances of this class to be move constructed */
51  /** Allow instances of this class to be moved */
53 
54  /** Get the tensor data.
55  *
56  * @return a constant pointer to the tensor data.
57  */
58  const void *data() const;
59  /** Get the tensor data.
60  *
61  * @return a pointer to the tensor data.
62  */
63  void *data();
64 
65  // Inherited methods overridden:
66  TensorShape shape() const override;
67  size_t element_size() const override;
68  size_t size() const override;
69  Format format() const override;
70  DataLayout data_layout() const override;
71  DataType data_type() const override;
72  int num_channels() const override;
73  int num_elements() const override;
74  PaddingSize padding() const override;
75  QuantizationInfo quantization_info() const override;
76  const void *operator()(const Coordinates &coord) const override;
77  void *operator()(const Coordinates &coord) override;
78 
79 private:
80  SimpleTensor<T> &_tensor;
81 };
82 
83 template <typename T>
85  : _tensor{ tensor }
86 {
87 }
88 
89 template <typename T>
91 {
92  return _tensor.shape();
93 }
94 
95 template <typename T>
97 {
98  return _tensor.element_size();
99 }
100 
101 template <typename T>
102 inline size_t SimpleTensorAccessor<T>::size() const
103 {
104  return _tensor.num_elements() * _tensor.element_size();
105 }
106 
107 template <typename T>
109 {
110  return _tensor.format();
111 }
112 
113 template <typename T>
115 {
116  return _tensor.data_layout();
117 }
118 
119 template <typename T>
121 {
122  return _tensor.data_type();
123 }
124 
125 template <typename T>
127 {
128  return _tensor.num_channels();
129 }
130 
131 template <typename T>
133 {
134  return _tensor.num_elements();
135 }
136 
137 template <typename T>
139 {
140  return _tensor.padding();
141 }
142 
143 template <typename T>
145 {
146  return _tensor.quantization_info();
147 }
148 
149 template <typename T>
150 inline const void *SimpleTensorAccessor<T>::data() const
151 {
152  return _tensor.data();
153 }
154 
155 template <typename T>
157 {
158  return _tensor.data();
159 }
160 
161 template <typename T>
162 inline const void *SimpleTensorAccessor<T>::operator()(const Coordinates &coord) const
163 {
164  return _tensor(coord);
165 }
166 
167 template <typename T>
169 {
170  return _tensor(coord);
171 }
172 } // namespace test
173 } // namespace arm_compute
174 #endif /* ARM_COMPUTE_TEST_SIMPLE_TENSOR_ACCESSOR_H */
Shape of a tensor.
Definition: TensorShape.h:39
Container for 2D border size.
Definition: Types.h:264
Format format() const override
Image format of the tensor.
size_t size() const override
Total size of the tensor in bytes.
int num_channels() const override
Number of channels of the tensor.
Accessor implementation for SimpleTensor objects.
SimpleTensorAccessor & operator=(const SimpleTensorAccessor &)=delete
Prevent instances of this class from being copied.
const void * data() const
Get the tensor data.
const void * operator()(const Coordinates &coord) const override
Read only access to the specified element.
TensorShape shape() const override
Shape of the tensor.
Copyright (c) 2017-2021 Arm Limited.
Quantization information.
Format
Image colour formats.
Definition: Types.h:54
int num_elements() const override
Number of elements of the tensor.
Coordinates of an item.
Definition: Coordinates.h:37
DataType data_type() const override
Data type of the tensor.
PaddingSize padding() const override
Available padding around the tensor.
size_t element_size() const override
Size of each element in the tensor in bytes.
Simple tensor object that stores elements in a consecutive chunk of memory.
Definition: SimpleTensor.h:58
Common interface to provide information and access to tensor like structures.
Definition: IAccessor.h:37
DataLayout data_layout() const override
Data layout of the tensor.
DataType
Available data types.
Definition: Types.h:77
DataLayout
[DataLayout enum definition]
Definition: Types.h:111
QuantizationInfo quantization_info() const override
Quantization info in case of asymmetric quantized type.
SimpleTensorAccessor(SimpleTensor< T > &tensor)
Create an accessor for the given tensor.