Compute Library
 23.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>
156 inline void *SimpleTensorAccessor<T>::data()
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 */
arm_compute::QuantizationInfo
Quantization information.
Definition: QuantizationInfo.h:68
arm_compute::DataLayout
DataLayout
[DataLayout enum definition]
Definition: CoreTypes.h:109
arm_compute::BorderSize
Container for 2D border size.
Definition: Types.h:242
arm_compute::TensorShape
Shape of a tensor.
Definition: TensorShape.h:39
SimpleTensor.h
arm_compute::test::SimpleTensorAccessor::shape
TensorShape shape() const override
Shape of the tensor.
Definition: SimpleTensorAccessor.h:90
arm_compute::test::SimpleTensorAccessor::operator=
SimpleTensorAccessor & operator=(const SimpleTensorAccessor &)=delete
Prevent instances of this class from being copied.
IAccessor.h
arm_compute::test::SimpleTensorAccessor::data_layout
DataLayout data_layout() const override
Data layout of the tensor.
Definition: SimpleTensorAccessor.h:114
arm_compute::test::SimpleTensorAccessor::data_type
DataType data_type() const override
Data type of the tensor.
Definition: SimpleTensorAccessor.h:120
arm_compute::test::SimpleTensorAccessor::num_elements
int num_elements() const override
Number of elements of the tensor.
Definition: SimpleTensorAccessor.h:132
arm_compute::Coordinates
Coordinates of an item.
Definition: Coordinates.h:37
arm_compute::test::SimpleTensorAccessor::SimpleTensorAccessor
SimpleTensorAccessor(SimpleTensor< T > &tensor)
Create an accessor for the given tensor.
Definition: SimpleTensorAccessor.h:84
tensor
CLTensor * tensor
Pointer to the auxiliary tensor.
Definition: ClWorkloadRuntime.cpp:66
arm_compute::test::SimpleTensorAccessor::format
Format format() const override
Image format of the tensor.
Definition: SimpleTensorAccessor.h:108
arm_compute::Format
Format
Image colour formats.
Definition: CoreTypes.h:57
arm_compute::test::SimpleTensorAccessor::quantization_info
QuantizationInfo quantization_info() const override
Quantization info in case of asymmetric quantized type.
Definition: SimpleTensorAccessor.h:144
arm_compute::test::SimpleTensorAccessor::operator()
const void * operator()(const Coordinates &coord) const override
Read only access to the specified element.
Definition: SimpleTensorAccessor.h:162
arm_compute::test::SimpleTensor
Simple tensor object that stores elements in a consecutive chunk of memory.
Definition: SimpleTensor.h:58
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
arm_compute::test::SimpleTensorAccessor::element_size
size_t element_size() const override
Size of each element in the tensor in bytes.
Definition: SimpleTensorAccessor.h:96
arm_compute::test::SimpleTensorAccessor::size
size_t size() const override
Total size of the tensor in bytes.
Definition: SimpleTensorAccessor.h:102
arm_compute::test::SimpleTensorAccessor::num_channels
int num_channels() const override
Number of channels of the tensor.
Definition: SimpleTensorAccessor.h:126
arm_compute::test::IAccessor
Common interface to provide information and access to tensor like structures.
Definition: IAccessor.h:38
arm_compute::test::SimpleTensorAccessor
Accessor implementation for SimpleTensor objects.
Definition: SimpleTensorAccessor.h:36
arm_compute::DataType
DataType
Available data types.
Definition: CoreTypes.h:82
arm_compute::test::SimpleTensorAccessor::data
const void * data() const
Get the tensor data.
Definition: SimpleTensorAccessor.h:150
arm_compute::test::SimpleTensorAccessor::padding
PaddingSize padding() const override
Available padding around the tensor.
Definition: SimpleTensorAccessor.h:138