Skip to content

Commit

Permalink
Fixed issue with loading all-zero sparse matrices, as the data and ir…
Browse files Browse the repository at this point in the history
… pointers are not stored in the .mat file. (#57)

Co-authored-by: S. Breedveld <[email protected]>
  • Loading branch information
SebastiaanBreedveld and S. Breedveld authored Jul 18, 2024
1 parent dc8a80c commit ac31ea7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions mat73/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,13 @@ def unpack_mat(self, hdf5, depth=0, MATLAB_class=None, force=False):
if 'MATLAB_sparse' in hdf5.attrs:
try:
from scipy.sparse import csc_matrix
data = hdf5['data']
row_ind = hdf5['ir']
if 'data' in hdf5:
data = hdf5['data']
row_ind = hdf5['ir']
else:
data = []
row_ind = []

col_ind = hdf5['jc']
n_rows = hdf5.attrs['MATLAB_sparse']
n_cols = len(col_ind) - 1
Expand Down Expand Up @@ -348,4 +353,4 @@ def savemat(filename, verbose=True):


# file = '../tests/testfile8.mat'
# data = loadmat(file)
# data = loadmat(file)

0 comments on commit ac31ea7

Please sign in to comment.