Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[2.0] make npx.load support empty .npz files #20403

Merged
merged 4 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/c_api/c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,8 @@ 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 || 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) {
Expand Down
5 changes: 5 additions & 0 deletions tests/python/unittest/test_numpy_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,3 +1421,8 @@ 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)

@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'))