From 87f21cd39639118293b51fa776d30aa7722917bd Mon Sep 17 00:00:00 2001 From: Anthony Barbier Date: Fri, 10 Nov 2017 16:27:32 +0000 Subject: COMPMID-556 Updated libnpy.hpp Change-Id: I380a11f41ca2158de1dd0a6339ed9c884feb8f69 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/95385 Tested-by: Kaizen Reviewed-by: Michalis Spyrou --- utils/GraphUtils.cpp | 24 +++--------------------- utils/Utils.cpp | 21 ++------------------- utils/Utils.h | 8 ++++---- 3 files changed, 9 insertions(+), 44 deletions(-) (limited to 'utils') diff --git a/utils/GraphUtils.cpp b/utils/GraphUtils.cpp index 9a1ed3d7d9..b9be9d4085 100644 --- a/utils/GraphUtils.cpp +++ b/utils/GraphUtils.cpp @@ -301,30 +301,12 @@ bool NumPyBinLoader::access_tensor(ITensor &tensor) // Open file std::ifstream stream(_filename, std::ios::in | std::ios::binary); ARM_COMPUTE_ERROR_ON_MSG(!stream.good(), "Failed to load binary data"); - // Check magic bytes and version number - unsigned char v_major = 0; - unsigned char v_minor = 0; - npy::read_magic(stream, &v_major, &v_minor); - - // Read header - std::string header; - if(v_major == 1 && v_minor == 0) - { - header = npy::read_header_1_0(stream); - } - else if(v_major == 2 && v_minor == 0) - { - header = npy::read_header_2_0(stream); - } - else - { - ARM_COMPUTE_ERROR("Unsupported file format version"); - } + std::string header = npy::read_header(stream); // Parse header bool fortran_order = false; std::string typestr; - npy::ParseHeader(header, typestr, &fortran_order, shape); + npy::parse_header(header, typestr, fortran_order, shape); // Check if the typestring matches the given one std::string expect_typestr = arm_compute::utils::get_typestring(tensor.info()->data_type()); @@ -365,4 +347,4 @@ bool NumPyBinLoader::access_tensor(ITensor &tensor) }); } return true; -} \ No newline at end of file +} diff --git a/utils/Utils.cpp b/utils/Utils.cpp index b99afb441c..f6aff6f92d 100644 --- a/utils/Utils.cpp +++ b/utils/Utils.cpp @@ -172,30 +172,13 @@ std::tuple, bool, std::string> parse_npy_header(std:: { std::vector shape; // NOLINT - // Check magic bytes and version number - unsigned char v_major = 0; - unsigned char v_minor = 0; - npy::read_magic(fs, &v_major, &v_minor); - // Read header - std::string header; - if(v_major == 1 && v_minor == 0) - { - header = npy::read_header_1_0(fs); - } - else if(v_major == 2 && v_minor == 0) - { - header = npy::read_header_2_0(fs); - } - else - { - ARM_COMPUTE_ERROR("Unsupported file format version"); - } + std::string header = npy::read_header(fs); // Parse header bool fortran_order = false; std::string typestr; - npy::ParseHeader(header, typestr, &fortran_order, shape); + npy::parse_header(header, typestr, fortran_order, shape); if(!fortran_order) { diff --git a/utils/Utils.h b/utils/Utils.h index 76329671af..4e5bc815ab 100644 --- a/utils/Utils.h +++ b/utils/Utils.h @@ -709,9 +709,9 @@ void save_to_npy(T &tensor, const std::string &npy_filename, bool fortran_order) fs.exceptions(std::ofstream::failbit | std::ofstream::badbit | std::ofstream::eofbit); fs.open(npy_filename, std::ios::out | std::ios::binary); - const unsigned int width = tensor.info()->tensor_shape()[0]; - const unsigned int height = tensor.info()->tensor_shape()[1]; - unsigned long shape[2]; + const unsigned int width = tensor.info()->tensor_shape()[0]; + const unsigned int height = tensor.info()->tensor_shape()[1]; + std::vector shape(2); if(!fortran_order) { @@ -734,7 +734,7 @@ void save_to_npy(T &tensor, const std::string &npy_filename, bool fortran_order) std::string typestring = typestring_o.str(); std::ofstream stream(npy_filename, std::ofstream::binary); - npy::WriteHeader(stream, typestring, fortran_order, 2, shape); + npy::write_header(stream, typestring, fortran_order, shape); arm_compute::Window window; window.set(arm_compute::Window::DimX, arm_compute::Window::Dimension(0, width, 1)); -- cgit v1.2.1