111 lines
5.5 KiB
Diff
111 lines
5.5 KiB
Diff
From 20c18a47e05feb2fee27a24aaa914a86a48e11c8 Mon Sep 17 00:00:00 2001
|
||
From: serge-sans-paille <serge.guelton@telecom-bretagne.eu>
|
||
Date: Wed, 7 Oct 2020 07:03:11 +0200
|
||
Subject: [PATCH] Fix xnpy save padding computation
|
||
MIME-Version: 1.0
|
||
Content-Type: text/plain; charset=UTF-8
|
||
Content-Transfer-Encoding: 8bit
|
||
|
||
According to the documentation [0],
|
||
|
||
> It is terminated by a newline (\n) and padded with spaces (\x20) to make the
|
||
> total of len(magic string) + 2 + len(length) + HEADER_LEN be evenly
|
||
> divisible by 64 for alignment purposes.
|
||
|
||
In former version, the aligment was 16 [1]
|
||
|
||
> the total length of the magic string + 4 + HEADER_LEN be evenly divisible by
|
||
> 16 for alignment purposes.
|
||
|
||
The official documentation also states
|
||
|
||
> The .npy format, including motivation for creating it and a comparison of
|
||
> alternatives, is described in the “npy-format” NEP, however details have
|
||
> evolved with time and this document is more current.
|
||
|
||
This patches fixes xnpy implementation and reference tests to match the documentation.
|
||
|
||
[0] https://numpy.org/doc/stable/reference/generated/numpy.lib.format.html
|
||
[1] https://docs.scipy.org/doc/numpy-1.14.2/neps/npy-format.html
|
||
---
|
||
include/xtensor/xnpy.hpp | 2 +-
|
||
test/files/xnpy_files/bool.npy | Bin 107 -> 155 bytes
|
||
test/files/xnpy_files/bool_fortran.npy | Bin 107 -> 155 bytes
|
||
test/files/xnpy_files/double.npy | Bin 296 -> 344 bytes
|
||
test/files/xnpy_files/double_fortran.npy | Bin 296 -> 344 bytes
|
||
test/files/xnpy_files/unsignedlong.npy | Bin 120 -> 168 bytes
|
||
test/files/xnpy_files/unsignedlong_fortran.npy | Bin 120 -> 168 bytes
|
||
7 files changed, 1 insertion(+), 1 deletion(-)
|
||
|
||
diff --git a/include/xtensor/xnpy.hpp b/include/xtensor/xnpy.hpp
|
||
index 9f86c03..12deca9 100644
|
||
--- a/include/xtensor/xnpy.hpp
|
||
+++ b/include/xtensor/xnpy.hpp
|
||
@@ -393,7 +393,7 @@ namespace xt
|
||
version[0] = 2;
|
||
version[1] = 0;
|
||
}
|
||
- std::size_t padding_len = 16 - metadata_len % 16;
|
||
+ std::size_t padding_len = 64 - (metadata_len % 64);
|
||
std::string padding(padding_len, ' ');
|
||
ss_header << padding;
|
||
ss_header << std::endl;
|
||
diff --git a/test/files/xnpy_files/bool.npy b/test/files/xnpy_files/bool.npy
|
||
index 3e4cd6e..528c0ee 100644
|
||
--- a/test/files/xnpy_files/bool.npy
|
||
+++ b/test/files/xnpy_files/bool.npy
|
||
@@ -1,2 +1,2 @@
|
||
-<2D>NUMPY |