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;
189 const T *
data()
const;
218 template <
typename U>
222 Buffer _buffer{
nullptr };
226 int _num_channels{ 0 };
231 template <
typename T1,
typename T2>
238 for(
size_t n = 0;
n < size_t(st.num_elements());
n++)
240 st.
data()[
n] =
static_cast<T1
>(tensor.
data()[
n]);
245 template <typename T1, typename T2, typename std::enable_if<std::is_same<T1, T2>::value,
int>
::type = 0>
252 memcpy((
void *)st.data(), (
const void *)tensor.
data(), size_t(st.num_elements() *
sizeof(T1)));
256 template < typename T1, typename T2, typename std::enable_if < (std::is_same<T1, half>::value || std::is_same<T2, half>::value),
int >::
type = 0 >
263 for(
size_t n = 0;
n < size_t(st.num_elements());
n++)
265 st.
data()[
n] = half_float::detail::half_cast<T1, T2>(tensor.
data()[
n]);
270 template <
typename T>
275 _quantization_info(),
278 _num_channels = num_channels();
279 _buffer = std::make_unique<T[]>(num_elements() * _num_channels);
282 template <
typename T>
286 _data_type(data_type),
287 _num_channels(num_channels),
288 _quantization_info(quantization_info),
289 _data_layout(data_layout)
291 _buffer = std::make_unique<T[]>(this->_shape.total_size() * _num_channels);
294 template <
typename T>
297 _shape(tensor.
shape()),
298 _format(tensor.format()),
300 _num_channels(tensor.num_channels()),
301 _quantization_info(tensor.quantization_info()),
304 _buffer = std::make_unique<T[]>(tensor.
num_elements() * _num_channels);
305 std::copy_n(tensor.
data(), this->_shape.total_size() * _num_channels, _buffer.get());
308 template <
typename T>
316 template <
typename T>
322 template <
typename T>
328 template <
typename T>
334 template <
typename T>
340 template <
typename T>
343 return _quantization_info;
346 template <
typename T>
349 _quantization_info =
qinfo;
353 template <
typename T>
356 const size_t size =
std::accumulate(_shape.cbegin(), _shape.cend(), 1, std::multiplies<size_t>());
357 return size * element_size();
360 template <
typename T>
366 template <
typename T>
372 template <
typename T>
385 template <
typename T>
400 case Format::YUYV422:
401 case Format::UYVY422:
407 case Format::RGBA8888:
410 return _num_channels;
421 template <
typename T>
424 return _shape.total_size();
427 template <
typename T>
433 template <
typename T>
436 return _buffer.get();
439 template <
typename T>
442 return _buffer.get();
445 template <
typename T>
448 return _buffer.get() +
coord2index(_shape, coord) * _num_channels;
451 template <
typename T>
454 return _buffer.get() +
coord2index(_shape, coord) * _num_channels;
457 template <
typename U>
463 swap(tensor1._shape, tensor2._shape);
464 swap(tensor1._format, tensor2._format);
465 swap(tensor1._data_type, tensor2._data_type);
466 swap(tensor1._num_channels, tensor2._num_channels);
467 swap(tensor1._quantization_info, tensor2._quantization_info);
468 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.
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-2023 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.
const QuantizationInfo qinfo
int num_elements() const override
Number of elements of the tensor.
CLTensor * tensor
Pointer to the auxiliary 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.