Fill a tensor with the content of the currently open NPY file.
598 const size_t current_position = _fs.tellg();
599 _fs.seekg(0, std::ios_base::end);
600 const size_t end_position = _fs.tellg();
601 _fs.seekg(current_position, std::ios_base::beg);
603 ARM_COMPUTE_ERROR_ON_MSG((end_position - current_position) < tensor.info()->tensor_shape().total_size() * tensor.info()->element_size(),
604 "Not enough data in file");
608 std::string expect_typestr =
get_typestring(tensor.info()->data_type());
615 for(
size_t i = 0; i < _shape.size(); ++i)
622 for(
size_t i = 0; i < _shape.size(); ++i)
624 ARM_COMPUTE_ERROR_ON_MSG(tensor.info()->tensor_shape()[i] != _shape[_shape.size() - i - 1],
"Tensor dimensions mismatch");
628 switch(tensor.info()->data_type())
633 if(tensor.info()->padding().empty())
636 _fs.read(reinterpret_cast<char *>(tensor.buffer()), tensor.info()->total_size());
642 window.use_tensor_dimensions(tensor.info()->tensor_shape());
646 _fs.read(reinterpret_cast<char *>(tensor.ptr_to_element(
id)), tensor.info()->element_size());
659 catch(
const std::ifstream::failure &e)
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
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.
void unmap(T &tensor)
Unmaps a tensor if needed.
std::string get_typestring(DataType data_type)
Obtain numpy type string from DataType.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
void execute_window_loop(const Window &w, L &&lambda_function, Ts &&...iterators)
Iterate through the passed window, automatically adjusting the iterators and calling the lambda_funct...
bool is_open()
Return true if a NPY file is currently open.
void map(T &tensor, bool blocking)
Maps a tensor if needed.
#define ARM_COMPUTE_ERROR_ON_MSG(cond,...)
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_NOT_IN(t,...)