Skip to content

Commit

Permalink
FIX: Try explicit copy
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Mar 2, 2024
1 parent 2316a94 commit 4d33968
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mne/_fiff/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ def _read_matrix(fid, tag, shape, rlims):
if matrix_coding == "sparse CCS":
tmp_indices = fid.read(4 * nnz)
indices = np.frombuffer(tmp_indices, dtype=">i4")
indices = np.array(indices, int)
tmp_ptr = fid.read(4 * (ncol + 1))
indptr = np.frombuffer(tmp_ptr, dtype=">i4")
indptr = np.array(np.frombuffer(tmp_ptr, dtype=">i4"))
if indptr[-1] > len(indices) or np.any(indptr < 0):
# There was a bug in MNE-C that caused some data to be
# stored without byte swapping
Expand All @@ -214,11 +215,12 @@ def _read_matrix(fid, tag, shape, rlims):
)
)
indptr = np.frombuffer(tmp_ptr, dtype="<i4")
indptr = np.array(indptr, int)
data = csc_matrix((data, indices, indptr), shape=shape)
else:
assert matrix_coding == "sparse RCS", matrix_coding
tmp_indices = fid.read(4 * nnz)
indices = np.frombuffer(tmp_indices, dtype=">i4")
indices = np.array(np.frombuffer(tmp_indices, dtype=">i4"), int)
tmp_ptr = fid.read(4 * (nrow + 1))
indptr = np.frombuffer(tmp_ptr, dtype=">i4")
if indptr[-1] > len(indices) or np.any(indptr < 0):
Expand All @@ -231,6 +233,7 @@ def _read_matrix(fid, tag, shape, rlims):
)
)
indptr = np.frombuffer(tmp_ptr, dtype="<i4")
indptr = np.array(indptr, int)
data = csr_matrix((data, indices, indptr), shape=shape)
return data

Expand Down

0 comments on commit 4d33968

Please sign in to comment.