MCPcopy Create free account
hub / github.com/mne-tools/mne-python / write_float_sparse

Function write_float_sparse

mne/_fiff/write.py:423–446  ·  view source on GitHub ↗

Write a single-precision floating-point sparse matrix tag.

(fid, kind, mat, fmt="auto")

Source from the content-addressed store, hash-verified

421
422
423def write_float_sparse(fid, kind, mat, fmt="auto"):
424 """Write a single-precision floating-point sparse matrix tag."""
425 if fmt == "auto":
426 fmt = "csr" if isinstance(mat, csr_array) else "csc"
427 need = csr_array if fmt == "csr" else csc_array
428 matrix_type = getattr(FIFF, f"FIFFT_SPARSE_{fmt[-1].upper()}CS_MATRIX")
429 _validate_type(mat, need, "sparse")
430 matrix_type = matrix_type | FIFF.FIFFT_MATRIX | FIFF.FIFFT_FLOAT
431 nnzm = mat.nnz
432 nrow = mat.shape[0]
433 data_size = 4 * nnzm + 4 * nnzm + 4 * (nrow + 1) + 4 * 4
434
435 fid.write(np.array(kind, dtype=">i4").tobytes())
436 fid.write(np.array(matrix_type, dtype=">i4").tobytes())
437 fid.write(np.array(data_size, dtype=">i4").tobytes())
438 fid.write(np.array(FIFF.FIFFV_NEXT_SEQ, dtype=">i4").tobytes())
439
440 fid.write(np.array(mat.data, dtype=">f4").tobytes())
441 fid.write(np.array(mat.indices, dtype=">i4").tobytes())
442 fid.write(np.array(mat.indptr, dtype=">i4").tobytes())
443
444 dims = [nnzm, mat.shape[0], mat.shape[1], 2]
445 fid.write(np.array(dims, dtype=">i4").tobytes())
446 check_fiff_length(fid)
447
448
449def _generate_meas_id():

Callers 1

write_float_sparse_rcsFunction · 0.85

Calls 3

_validate_typeFunction · 0.85
check_fiff_lengthFunction · 0.85
writeMethod · 0.80

Tested by

no test coverage detected