xtensor/0001-Fix-xnpy-save-padding-computation.patch

111 lines
5.5 KiB
Diff
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>NUMPYF{'descr': '|b1', 'fortran_order': False, 'shape': (3, 3, 3), }
+<2B>NUMPYv{'descr': '|b1', 'fortran_order': False, 'shape': (3, 3, 3), }

\ No newline at end of file
diff --git a/test/files/xnpy_files/bool_fortran.npy b/test/files/xnpy_files/bool_fortran.npy
index 5068b33..a6766f6 100644
--- a/test/files/xnpy_files/bool_fortran.npy
+++ b/test/files/xnpy_files/bool_fortran.npy
@@ -1,2 +1,2 @@
-<2D>NUMPYF{'descr': '|b1', 'fortran_order': True, 'shape': (3, 3, 3), }
+<2B>NUMPYv{'descr': '|b1', 'fortran_order': True, 'shape': (3, 3, 3), }

\ No newline at end of file
diff --git a/test/files/xnpy_files/double.npy b/test/files/xnpy_files/double.npy
index e5ef170..b4eb19a 100644
--- a/test/files/xnpy_files/double.npy
+++ b/test/files/xnpy_files/double.npy
@@ -1,3 +1,3 @@
-<2D>NUMPYF{'descr': '<f8', 'fortran_order': False, 'shape': (3, 3, 3), }
+<2B>NUMPYv{'descr': '<f8', 'fortran_order': False, 'shape': (3, 3, 3), }
<20>{<7B><>><07>?<3F>Q<EFBFBD><51>(m<>?0E<30>
<20>Q<EFBFBD>?<3F>~<7E><1C>4<EFBFBD>?yе^<5E><>?<3F>3<EFBFBD>=\<5C><>?}E<><45><EFBFBD>?~&<26>o<EFBFBD>p<EFBFBD>?<3F>Av<41><76>|<7C>?b<><62>&<26><><EFBFBD>?<3F><>x=<3D><>?<3F><><EFBFBD><EFBFBD><EFBFBD>o<EFBFBD>?<3F>'<27>CS<>?<3F><><EFBFBD><EFBFBD><EFBFBD>,<2C>?<00>Z<00><><EFBFBD>?<00><><EFBFBD><EFBFBD><12>?<3F><><EFBFBD><EFBFBD>m.<2E>?@ 3\<15><>?<3F>zx}<7D><><EFBFBD>?E<><45>|<7C><>?<3F><>$Y<19>?<3F><>r<Ք<>?<3F><><EFBFBD>G<EFBFBD>e<EFBFBD>?<04>e<EFBFBD><65>o<EFBFBD>?<3F>M9Jv<4A>?vy<76>2<><32>?<3F>Hc|<03>?
\ No newline at end of file
diff --git a/test/files/xnpy_files/double_fortran.npy b/test/files/xnpy_files/double_fortran.npy
index c6a0bb7..0d395e9 100644
--- a/test/files/xnpy_files/double_fortran.npy
+++ b/test/files/xnpy_files/double_fortran.npy
@@ -1,3 +1,3 @@
-<2D>NUMPYF{'descr': '<f8', 'fortran_order': True, 'shape': (3, 3, 3), }
+<2B>NUMPYv{'descr': '<f8', 'fortran_order': True, 'shape': (3, 3, 3), }
<20>{<7B><>><07>?b<><62>&<26><><EFBFBD>?<3F>zx}<7D><><EFBFBD>?<3F>~<7E><1C>4<EFBFBD>?<3F>'<27>CS<>?<3F><>r<Ք<>?}E<><45><EFBFBD>?<00><><EFBFBD><EFBFBD><12>?<3F>M9Jv<4A>?<3F>Q<EFBFBD><51>(m<>?<3F><>x=<3D><>?E<><45>|<7C><>?yе^<5E><>?<3F><><EFBFBD><EFBFBD><EFBFBD>,<2C>?<3F><><EFBFBD>G<EFBFBD>e<EFBFBD>?~&<26>o<EFBFBD>p<EFBFBD>?<3F><><EFBFBD><EFBFBD>m.<2E>?vy<76>2<><32>?0E<30>
<20>Q<EFBFBD>?<3F><><EFBFBD><EFBFBD><EFBFBD>o<EFBFBD>?<3F><>$Y<19>?<3F>3<EFBFBD>=\<5C><>?<00>Z<00><><EFBFBD>?<04>e<EFBFBD><65>o<EFBFBD>?<3F>Av<41><76>|<7C>?@ 3\<15><>?<3F>Hc|<03>?
\ No newline at end of file
diff --git a/test/files/xnpy_files/unsignedlong.npy b/test/files/xnpy_files/unsignedlong.npy
index f463685..4c6863f 100644
--- a/test/files/xnpy_files/unsignedlong.npy
+++ b/test/files/xnpy_files/unsignedlong.npy
@@ -1,2 +1,2 @@
-<2D>NUMPYF{'descr': '<u8', 'fortran_order': False, 'shape': (5,), }
+<2B>NUMPYv{'descr': '<u8', 'fortran_order': False, 'shape': (5,), }
<00><>
\ No newline at end of file
diff --git a/test/files/xnpy_files/unsignedlong_fortran.npy b/test/files/xnpy_files/unsignedlong_fortran.npy
index f463685..4c6863f 100644
--- a/test/files/xnpy_files/unsignedlong_fortran.npy
+++ b/test/files/xnpy_files/unsignedlong_fortran.npy
@@ -1,2 +1,2 @@
-<2D>NUMPYF{'descr': '<u8', 'fortran_order': False, 'shape': (5,), }
+<2B>NUMPYv{'descr': '<u8', 'fortran_order': False, 'shape': (5,), }
<00><>
\ No newline at end of file
--
1.8.3.1