2 * Copyright (c) 2017-2018 ARM Limited.
4 * SPDX-License-Identifier: MIT
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:
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
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
24 #ifndef __ARM_COMPUTE_TEST_RAW_TENSOR_H__
25 #define __ARM_COMPUTE_TEST_RAW_TENSOR_H__
27 #include "tests/SimpleTensor.h"
33 /** Subclass of SimpleTensor using uint8_t as value type.
35 * Access operations (except for operator[]) will be based on the data type to
36 * copy the right number of elements.
38 class RawTensor : public SimpleTensor<uint8_t>
41 /** Create an uninitialised tensor of the given @p shape and @p format.
43 * @param[in] shape Shape of the new raw tensor.
44 * @param[in] format Format of the new raw tensor.
45 * @param[in] fixed_point_position (Optional) Number of bits for the fractional part of the fixed point numbers
47 RawTensor(TensorShape shape, Format format, int fixed_point_position = 0);
49 /** Create an uninitialised tensor of the given @p shape and @p data type.
51 * @param[in] shape Shape of the new raw tensor.
52 * @param[in] data_type Data type of the new raw tensor.
53 * @param[in] num_channels (Optional) Number of channels (default = 1).
54 * @param[in] fixed_point_position (Optional) Number of bits for the fractional part of the fixed point numbers (default = 0).
56 RawTensor(TensorShape shape, DataType data_type, int num_channels = 1, int fixed_point_position = 0);
58 /** Conversion constructor from SimpleTensor.
60 * The passed SimpleTensor will be destroyed after it has been converted to
63 * @param[in,out] tensor SimpleTensor to be converted to a RawTensor.
66 RawTensor(SimpleTensor<T> &&tensor)
68 _buffer = std::unique_ptr<uint8_t[]>(reinterpret_cast<uint8_t *>(tensor._buffer.release()));
69 _shape = std::move(tensor._shape);
70 _format = tensor._format;
71 _data_type = tensor._data_type;
72 _num_channels = tensor._num_channels;
73 _fixed_point_position = tensor._fixed_point_position;
74 _data_layout = tensor._data_layout;
77 /** Conversion operator to SimpleTensor.
79 * The current RawTensor must not be used after the conversion.
81 * @return SimpleTensor of the given type.
84 operator SimpleTensor<T>()
87 cast._buffer = std::unique_ptr<T[]>(reinterpret_cast<T *>(_buffer.release()));
88 cast._shape = std::move(_shape);
89 cast._format = _format;
90 cast._data_type = _data_type;
91 cast._num_channels = _num_channels;
92 cast._fixed_point_position = _fixed_point_position;
93 cast._data_layout = _data_layout;
98 /** Create a deep copy of the given @p tensor.
100 * @param[in] tensor To be copied tensor.
102 RawTensor(const RawTensor &tensor);
104 /** Copy the given @p tensor.
106 * @param[in] tensor To be copied tensor.
108 * @return a copy of the given tensor.
110 RawTensor &operator=(RawTensor tensor);
111 /** Allow instances of this class to be move constructed */
112 RawTensor(RawTensor &&) = default;
113 /** Default destructor. */
114 ~RawTensor() = default;
116 /** Read only access to the specified element.
118 * @param[in] coord Coordinates of the desired element.
120 * @return A pointer to the desired element.
122 const void *operator()(const Coordinates &coord) const override;
124 /** Access to the specified element.
126 * @param[in] coord Coordinates of the desired element.
128 * @return A pointer to the desired element.
130 void *operator()(const Coordinates &coord) override;
133 } // namespace arm_compute
134 #endif /* __ARM_COMPUTE_TEST_RAW_TENSOR_H__ */