Write a single-precision floating-point sparse matrix tag.
(fid, kind, mat, fmt="auto")
| 421 | |
| 422 | |
| 423 | def 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 | |
| 449 | def _generate_meas_id(): |
no test coverage detected