24 #ifndef ARM_COMPUTE_TEST_SIMPLE_TENSOR_H 25 #define ARM_COMPUTE_TEST_SIMPLE_TENSOR_H 105 using Buffer = std::unique_ptr<value_type[]>;
139 size_t size()
const override;
180 const T *
data()
const;
209 template <
typename U>
213 Buffer _buffer{
nullptr };
217 int _num_channels{ 0 };
218 QuantizationInfo _quantization_info{};
222 template <
typename T1,
typename T2>
229 for(
size_t n = 0; n < size_t(st.num_elements()); n++)
231 st.
data()[n] = static_cast<T1>(tensor.
data()[n]);
236 template <typename T1, typename T2, typename std::enable_if<std::is_same<T1, T2>::value,
int>
::type = 0>
243 memcpy((
void *)st.data(), (
const void *)tensor.
data(), size_t(st.num_elements() *
sizeof(T1)));
247 template <
typename T1,
typename T2,
typename std::enable_if < (std::is_same<T1, half>::value || std::is_same<T2, half>::value),
int >::type = 0 >
248 SimpleTensor<T1>
copy_tensor(
const SimpleTensor<half> &tensor)
250 SimpleTensor<T1> st(tensor.shape(), tensor.data_type(),
251 tensor.num_channels(),
252 tensor.quantization_info(),
253 tensor.data_layout());
254 for(
size_t n = 0; n < size_t(st.num_elements()); n++)
256 st.data()[n] = half_float::detail::half_cast<T1, T2>(tensor.data()[n]);
261 template <
typename T>
266 _quantization_info(),
269 _num_channels = num_channels();
270 _buffer = std::make_unique<T[]>(num_elements() * _num_channels);
273 template <
typename T>
278 _num_channels(num_channels),
279 _quantization_info(quantization_info),
282 _buffer = std::make_unique<T[]>(this->_shape.total_size() * _num_channels);
285 template <
typename T>
288 _shape(tensor.
shape()),
289 _format(tensor.format()),
291 _num_channels(tensor.num_channels()),
292 _quantization_info(tensor.quantization_info()),
295 _buffer = std::make_unique<T[]>(tensor.
num_elements() * _num_channels);
296 std::copy_n(tensor.
data(), this->_shape.total_size() * _num_channels, _buffer.get());
299 template <
typename T>
307 template <
typename T>
313 template <
typename T>
319 template <
typename T>
325 template <
typename T>
331 template <
typename T>
334 return _quantization_info;
337 template <
typename T>
340 const size_t size =
std::accumulate(_shape.cbegin(), _shape.cend(), 1, std::multiplies<size_t>());
341 return size * element_size();
344 template <
typename T>
350 template <
typename T>
356 template <
typename T>
359 if(_format != Format::UNKNOWN)
369 template <
typename T>
384 case Format::YUYV422:
385 case Format::UYVY422:
391 case Format::RGBA8888:
393 case Format::UNKNOWN:
394 return _num_channels;
405 template <
typename T>
408 return _shape.total_size();
411 template <
typename T>
417 template <
typename T>
420 return _buffer.get();
423 template <
typename T>
426 return _buffer.get();
429 template <
typename T>
432 return _buffer.get() +
coord2index(_shape, coord) * _num_channels;
435 template <
typename T>
438 return _buffer.get() +
coord2index(_shape, coord) * _num_channels;
441 template <
typename U>
447 swap(tensor1._shape, tensor2._shape);
448 swap(tensor1._format, tensor2._format);
449 swap(tensor1._data_type, tensor2._data_type);
450 swap(tensor1._num_channels, tensor2._num_channels);
451 swap(tensor1._quantization_info, tensor2._quantization_info);
452 swap(tensor1._buffer, tensor2._buffer);
friend void swap(SimpleTensor< U > &tensor1, SimpleTensor< U > &tensor2)
Swaps the content of the provided tensors.
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
size_t element_size() const override
Size of each element in the tensor in bytes.
Subclass of SimpleTensor using uint8_t as value type.
size_t size() const override
Total size of the tensor in bytes.
T & operator[](size_t offset)
Return value at offset in the buffer.
Container for 2D border size.
size_t element_size_from_data_type(DataType dt)
The size in bytes of the data type.
Format format() const override
Image format of the tensor.
DataType data_type() const override
Data type of the tensor.
const DataLayout data_layout
void swap(SimpleTensor< U > &tensor1, SimpleTensor< U > &tensor2)
TensorShape shape() const override
Shape of the tensor.
decltype(strategy::transforms) typedef type
SimpleTensor< T2 > accumulate(const SimpleTensor< T1 > &src, DataType output_data_type)
SimpleTensor< T1 > copy_tensor(const SimpleTensor< T2 > &tensor)
Copyright (c) 2017-2021 Arm Limited.
int coord2index(const TensorShape &shape, const Coordinates &coord)
Linearise the given coordinate.
Quantization information.
Format
Image colour formats.
~SimpleTensor()=default
Default destructor.
uint8_t value_type
Tensor value type.
PaddingSize padding() const override
Available padding around the tensor.
DataLayout data_layout() const override
Data layout of the tensor.
BorderSize PaddingSize
Container for 2D padding size.
Num samples, channels, height, width.
SimpleTensor()=default
Create an uninitialised tensor.
const void * operator()(const Coordinates &coord) const override
Read only access to the specified element.
DataType data_type_from_format(Format format)
Return the data type used by a given single-planar pixel format.
std::unique_ptr< value_type[]> Buffer
Tensor buffer pointer type.
Simple tensor object that stores elements in a consecutive chunk of memory.
int num_channels() const override
Number of channels of the tensor.
SimpleTensor & operator=(SimpleTensor tensor)
Create a deep copy of the given tensor.
Common interface to provide information and access to tensor like structures.
int num_elements() const override
Number of elements of the tensor.
QuantizationInfo quantization_info() const override
Quantization info in case of asymmetric quantized type.
DataType
Available data types.
DataLayout
[DataLayout enum definition]
const T * data() const
Constant pointer to the underlying buffer.