From f5ac9299cbf9b7fb57343ef9108b498f2782a885 Mon Sep 17 00:00:00 2001 From: barry-jin Date: Tue, 29 Jun 2021 19:49:51 -0700 Subject: [PATCH 1/4] npx.load empty npz file --- src/c_api/c_api.cc | 2 +- tests/python/unittest/test_numpy_ndarray.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/c_api/c_api.cc b/src/c_api/c_api.cc index e35f0f4a351a..d3a1eec7fc01 100644 --- a/src/c_api/c_api.cc +++ b/src/c_api/c_api.cc @@ -1974,7 +1974,7 @@ int MXNDArrayLoad(const char* fname, << "Failed to read 32 bits from file."; } - if (magic == 0x04034b50 || magic == 0x504b0304) { // zip file format; assumed to be npz + if (magic == 0x04034b50 || magic == 0x504b0304 || magic == 0x06054b50) { // zip file format; assumed to be npz auto[data, names] = npz::load_arrays(fname); ret->ret_handles.resize(data.size()); for (size_t i = 0; i < data.size(); ++i) { diff --git a/tests/python/unittest/test_numpy_ndarray.py b/tests/python/unittest/test_numpy_ndarray.py index 9f2c67b7db29..b87db24ec6ca 100644 --- a/tests/python/unittest/test_numpy_ndarray.py +++ b/tests/python/unittest/test_numpy_ndarray.py @@ -1421,3 +1421,7 @@ def test_mixed_array_types_share_memory(): mx_pinned_array = mx_array.as_in_ctx(mx.cpu_pinned(0)) assert not _np.may_share_memory(np_array, mx_pinned_array) assert not _np.shares_memory(np_array, mx_pinned_array) + +def test_save_load_empty(tmp_path): + mx.npx.savez(str(tmp_path / 'params.npz')) + mx.npx.load(str(tmp_path / 'params.npz')) From eef254e0e23add81ee199b43fbf240fc71d645db Mon Sep 17 00:00:00 2001 From: barry-jin Date: Tue, 29 Jun 2021 20:05:10 -0700 Subject: [PATCH 2/4] fix --- src/c_api/c_api.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/c_api/c_api.cc b/src/c_api/c_api.cc index d3a1eec7fc01..e5283340076a 100644 --- a/src/c_api/c_api.cc +++ b/src/c_api/c_api.cc @@ -1974,7 +1974,8 @@ int MXNDArrayLoad(const char* fname, << "Failed to read 32 bits from file."; } - if (magic == 0x04034b50 || magic == 0x504b0304 || magic == 0x06054b50) { // zip file format; assumed to be npz + if (magic == 0x04034b50 || magic == 0x504b0304 || magic == 0x06054b50) { + // zip file format; assumed to be npz auto[data, names] = npz::load_arrays(fname); ret->ret_handles.resize(data.size()); for (size_t i = 0; i < data.size(); ++i) { From bbf93178abd1edc25aa281c98651c68cc7c18d09 Mon Sep 17 00:00:00 2001 From: barry-jin Date: Tue, 29 Jun 2021 22:23:01 -0700 Subject: [PATCH 3/4] set use_np --- tests/python/unittest/test_numpy_ndarray.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/python/unittest/test_numpy_ndarray.py b/tests/python/unittest/test_numpy_ndarray.py index b87db24ec6ca..c6221c5c9eae 100644 --- a/tests/python/unittest/test_numpy_ndarray.py +++ b/tests/python/unittest/test_numpy_ndarray.py @@ -1422,6 +1422,7 @@ def test_mixed_array_types_share_memory(): assert not _np.may_share_memory(np_array, mx_pinned_array) assert not _np.shares_memory(np_array, mx_pinned_array) +@use_np def test_save_load_empty(tmp_path): mx.npx.savez(str(tmp_path / 'params.npz')) mx.npx.load(str(tmp_path / 'params.npz')) From e9b08c4d8f3dcdad0db42000f95148108de4ebbf Mon Sep 17 00:00:00 2001 From: barry-jin Date: Wed, 30 Jun 2021 09:35:44 -0700 Subject: [PATCH 4/4] BIG_ENDIAN --- src/c_api/c_api.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/c_api/c_api.cc b/src/c_api/c_api.cc index e5283340076a..eac1944016df 100644 --- a/src/c_api/c_api.cc +++ b/src/c_api/c_api.cc @@ -1974,8 +1974,8 @@ int MXNDArrayLoad(const char* fname, << "Failed to read 32 bits from file."; } - if (magic == 0x04034b50 || magic == 0x504b0304 || magic == 0x06054b50) { - // zip file format; assumed to be npz + if (magic == 0x04034b50 || magic == 0x504b0304 || + magic == 0x06054b50 || magic == 0x504b0506) { // zip file format; assumed to be npz auto[data, names] = npz::load_arrays(fname); ret->ret_handles.resize(data.size()); for (size_t i = 0; i < data.size(); ++i) {