blob: 606a94f100aac45415b76db89dffa1e886603636 [file] [log] [blame]
Georgios Pinitasdef2a852019-02-21 14:47:56 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019 Arm Limited.
Georgios Pinitasdef2a852019-02-21 14:47:56 +00003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_TEST_SIMPLE_TENSOR_ACCESSOR_H
25#define ARM_COMPUTE_TEST_SIMPLE_TENSOR_ACCESSOR_H
Georgios Pinitasdef2a852019-02-21 14:47:56 +000026
27#include "SimpleTensor.h"
28#include "tests/IAccessor.h"
29
30namespace arm_compute
31{
32namespace test
33{
34/** Accessor implementation for @ref SimpleTensor objects. */
35template <typename T>
36class SimpleTensorAccessor : public IAccessor
37{
38public:
39 /** Create an accessor for the given @p tensor.
40 *
41 * @param[in, out] tensor To be accessed tensor.
42 */
43 SimpleTensorAccessor(SimpleTensor<T> &tensor);
44
45 /** Prevent instances of this class from being copy constructed */
46 SimpleTensorAccessor(const SimpleTensorAccessor &) = delete;
47 /** Prevent instances of this class from being copied */
48 SimpleTensorAccessor &operator=(const SimpleTensorAccessor &) = delete;
49 /** Allow instances of this class to be move constructed */
50 SimpleTensorAccessor(SimpleTensorAccessor &&) = default;
51 /** Allow instances of this class to be moved */
52 SimpleTensorAccessor &operator=(SimpleTensorAccessor &&) = default;
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
79private:
80 SimpleTensor<T> &_tensor;
81};
82
83template <typename T>
84inline SimpleTensorAccessor<T>::SimpleTensorAccessor(SimpleTensor<T> &tensor)
85 : _tensor{ tensor }
86{
87}
88
89template <typename T>
90inline TensorShape SimpleTensorAccessor<T>::shape() const
91{
92 return _tensor.shape();
93}
94
95template <typename T>
96inline size_t SimpleTensorAccessor<T>::element_size() const
97{
98 return _tensor.element_size();
99}
100
101template <typename T>
102inline size_t SimpleTensorAccessor<T>::size() const
103{
104 return _tensor.num_elements() * _tensor.element_size();
105}
106
107template <typename T>
108inline Format SimpleTensorAccessor<T>::format() const
109{
110 return _tensor.format();
111}
112
113template <typename T>
114inline DataLayout SimpleTensorAccessor<T>::data_layout() const
115{
116 return _tensor.data_layout();
117}
118
119template <typename T>
120inline DataType SimpleTensorAccessor<T>::data_type() const
121{
122 return _tensor.data_type();
123}
124
125template <typename T>
126inline int SimpleTensorAccessor<T>::num_channels() const
127{
128 return _tensor.num_channels();
129}
130
131template <typename T>
132inline int SimpleTensorAccessor<T>::num_elements() const
133{
134 return _tensor.num_elements();
135}
136
137template <typename T>
138inline PaddingSize SimpleTensorAccessor<T>::padding() const
139{
140 return _tensor.padding();
141}
142
143template <typename T>
144inline QuantizationInfo SimpleTensorAccessor<T>::quantization_info() const
145{
146 return _tensor.quantization_info();
147}
148
149template <typename T>
150inline const void *SimpleTensorAccessor<T>::data() const
151{
152 return _tensor.data();
153}
154
155template <typename T>
156inline void *SimpleTensorAccessor<T>::data()
157{
158 return _tensor.data();
159}
160
161template <typename T>
162inline const void *SimpleTensorAccessor<T>::operator()(const Coordinates &coord) const
163{
164 return _tensor(coord);
165}
166
167template <typename T>
168inline void *SimpleTensorAccessor<T>::operator()(const Coordinates &coord)
169{
170 return _tensor(coord);
171}
172} // namespace test
173} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000174#endif /* ARM_COMPUTE_TEST_SIMPLE_TENSOR_ACCESSOR_H */