Compute Library
 21.08
NumPyAccessor Class Referencefinal

NumPy accessor class. More...

#include <GraphUtils.h>

Collaboration diagram for NumPyAccessor:
[legend]

Public Member Functions

 NumPyAccessor (std::string npy_path, TensorShape shape, DataType data_type, DataLayout data_layout=DataLayout::NCHW, std::ostream &output_stream=std::cout)
 Constructor. More...
 
 NumPyAccessor (NumPyAccessor &&)=default
 Allow instances of this class to be move constructed. More...
 
 NumPyAccessor (const NumPyAccessor &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NumPyAccessoroperator= (const NumPyAccessor &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
bool access_tensor (ITensor &tensor) override
 Interface to be implemented to access a given tensor. More...
 
- Public Member Functions inherited from ITensorAccessor
virtual ~ITensorAccessor ()=default
 Default virtual destructor. More...
 

Detailed Description

NumPy accessor class.

Definition at line 146 of file GraphUtils.h.

Constructor & Destructor Documentation

◆ NumPyAccessor() [1/3]

NumPyAccessor ( std::string  npy_path,
TensorShape  shape,
DataType  data_type,
DataLayout  data_layout = DataLayout::NCHW,
std::ostream &  output_stream = std::cout 
)

Constructor.

Parameters
[in]npy_pathPath to npy file.
[in]shapeShape of the numpy tensor data.
[in]data_typeDataType of the numpy tensor data.
[in]data_layout(Optional) DataLayout of the numpy tensor data.
[out]output_stream(Optional) Output stream

Definition at line 180 of file GraphUtils.cpp.

References NumPyBinLoader::access_tensor(), TensorAllocator::allocate(), Tensor::allocator(), ITensor::info(), arm_compute::test::validation::info, TensorAllocator::init(), TensorInfo::set_data_layout(), ITensorInfo::tensor_shape(), and TensorShape::total_size().

181  : _npy_tensor(), _filename(std::move(npy_path)), _output_stream(output_stream)
182 {
183  NumPyBinLoader loader(_filename, data_layout);
184 
185  TensorInfo info(shape, 1, data_type);
186  info.set_data_layout(data_layout);
187 
188  _npy_tensor.allocator()->init(info);
189  _npy_tensor.allocator()->allocate();
190 
191  loader.access_tensor(_npy_tensor);
192 }
void init(const TensorAllocator &allocator, const Coordinates &coords, TensorInfo &sub_info)
Shares the same backing memory with another tensor allocator, while the tensor info might be differen...
const DataLayout data_layout
Definition: Im2Col.cpp:151
TensorAllocator * allocator()
Return a pointer to the tensor&#39;s allocator.
Definition: Tensor.cpp:48
const DataType data_type
Definition: Im2Col.cpp:150
Numpy Binary loader class.
Definition: GraphUtils.h:431
void allocate() override
Allocate size specified by TensorInfo of CPU memory.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)

◆ NumPyAccessor() [2/3]

NumPyAccessor ( NumPyAccessor &&  )
default

Allow instances of this class to be move constructed.

◆ NumPyAccessor() [3/3]

NumPyAccessor ( const NumPyAccessor )
delete

Prevent instances of this class from being copied (As this class contains pointers)

Member Function Documentation

◆ access_tensor()

bool access_tensor ( ITensor tensor)
overridevirtual

Interface to be implemented to access a given tensor.

Parameters
[in]tensorTensor to be accessed
Returns
True if access is successful else false

Implements ITensorAccessor.

Definition at line 206 of file GraphUtils.cpp.

References PrintAccessor::access_tensor(), ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ITensorInfo::data_type(), ITensorInfo::dimension(), arm_compute::F32, ITensor::info(), Tensor::info(), ITensor::print(), PrintAccessor::PrintAccessor(), and arm_compute::QASYMM8.

207 {
209  ARM_COMPUTE_ERROR_ON(_npy_tensor.info()->dimension(0) != tensor.info()->dimension(0));
210 
211  switch(tensor.info()->data_type())
212  {
213  case DataType::QASYMM8:
214  access_numpy_tensor<qasymm8_t>(tensor, 0);
215  break;
216  case DataType::F32:
217  access_numpy_tensor<float>(tensor, 0.0001f);
218  break;
219  default:
220  ARM_COMPUTE_ERROR("NOT SUPPORTED!");
221  }
222 
223  return false;
224 }
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
ITensorInfo * info() const override
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Definition: Tensor.cpp:33
quantized, asymmetric fixed-point 8-bit number unsigned
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:786

◆ operator=()

NumPyAccessor& operator= ( const NumPyAccessor )
delete

Prevent instances of this class from being copied (As this class contains pointers)


The documentation for this class was generated from the following files: