24.02.1
|
Go to the documentation of this file.
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 };
227 QuantizationInfo _quantization_info{};
231 template <
typename T1,
typename T2>
236 tensor.quantization_info(),
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>
250 tensor.quantization_info(),
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 >
261 tensor.quantization_info(),
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>
287 _num_channels(num_channels),
288 _quantization_info(quantization_info),
291 _buffer = std::make_unique<T[]>(this->_shape.total_size() * _num_channels);
294 template <
typename T>
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>
402 case Format::YUYV422:
403 case Format::UYVY422:
409 case Format::RGBA8888:
412 return _num_channels;
423 template <
typename T>
426 return _shape.total_size();
429 template <
typename T>
435 template <
typename T>
438 return _buffer.get();
441 template <
typename T>
444 return _buffer.get();
447 template <
typename T>
450 return _buffer.get() +
coord2index(_shape, coord) * _num_channels;
453 template <
typename T>
456 return _buffer.get() +
coord2index(_shape, coord) * _num_channels;
459 template <
typename U>
465 swap(tensor1._shape, tensor2._shape);
466 swap(tensor1._format, tensor2._format);
467 swap(tensor1._data_type, tensor2._data_type);
468 swap(tensor1._num_channels, tensor2._num_channels);
469 swap(tensor1._quantization_info, tensor2._quantization_info);
470 swap(tensor1._buffer, tensor2._buffer);
@ NCHW
Num samples, channels, height, width.
DataLayout data_layout() const override
Data layout of the tensor.
size_t size() const override
Total size of the tensor in bytes.
friend void swap(SimpleTensor< U > &tensor1, SimpleTensor< U > &tensor2)
Swaps the content of the provided tensors.
@ UNKNOWN
Unknown image format.
decltype(strategy::transforms) typedef type
Quantization information.
DataLayout
[DataLayout enum definition]
PaddingSize padding() const override
Available padding around the tensor.
Container for 2D border size.
int coord2index(const TensorShape &shape, const Coordinates &coord)
Linearise the given coordinate.
T & operator[](size_t offset)
Return value at offset in the buffer.
TensorShape shape() const override
Shape of the tensor.
int num_channels() const override
Number of channels of the tensor.
size_t element_size_from_data_type(DataType dt)
The size in bytes of the data type.
DataType data_type() const override
Data type of the tensor.
constexpr auto data_layout
~SimpleTensor()=default
Default destructor.
uint8_t value_type
Tensor value type.
DataType data_type_from_format(Format format)
Return the data type used by a given single-planar pixel format.
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
SimpleTensor< T2 > accumulate(const SimpleTensor< T1 > &src, DataType output_data_type)
const void * operator()(const Coordinates &coord) const override
Read only access to the specified element.
CLTensor * tensor
Pointer to the auxiliary tensor.
int num_elements() const override
Number of elements of the tensor.
Format
Image colour formats.
SimpleTensor()=default
Create an uninitialised tensor.
Simple tensor object that stores elements in a consecutive chunk of memory.
std::unique_ptr< value_type[]> Buffer
Tensor buffer pointer type.
BorderSize PaddingSize
Container for 2D padding size.
Copyright (c) 2017-2024 Arm Limited.
const T * data() const
Constant pointer to the underlying buffer.
@ UNKNOWN
Unknown CL kernel type.
Format format() const override
Image format of the tensor.
QuantizationInfo quantization_info() const override
Quantization info in case of asymmetric quantized type.
Subclass of SimpleTensor using uint8_t as value type.
@ UNKNOWN
Unknown data layout.
Common interface to provide information and access to tensor like structures.
void swap(SimpleTensor< U > &tensor1, SimpleTensor< U > &tensor2)
@ UNKNOWN
Unknown data type.
SimpleTensor & operator=(SimpleTensor tensor)
Create a deep copy of the given tensor.
DataType
Available data types.
SimpleTensor< T1 > copy_tensor(const SimpleTensor< T2 > &tensor)
const QuantizationInfo qinfo
size_t element_size() const override
Size of each element in the tensor in bytes.