Skip to main content

FiffSparseMatrix

Namespace: FIFFLIB  ·  Library: FIFF Library

#include <fiff/fiff_sparse_matrix.h>

class FIFFLIB::FiffSparseMatrix

Sparse FIFF matrix: CCS or RCS storage with the value / index / pointer triple as written by FiffStream::write_float_sparse_*.

Holds the three arrays the FIFF sparse-matrix tag stores on disk (values, inner indices, outer pointers) and the (nrow, ncol, nnz) shape, so it can be streamed in and out without conversion. Convert to an Eigen::SparseMatrix for arithmetic and back for serialization.

src/examples/ex_fiff_api/main.cpp
SparseMatrix<double> eigen(3, 4);
eigen.insert(0, 1) = 2.0;
eigen.insert(2, 3) = -1.5;
eigen.makeCompressed();
const FiffSparseMatrix fiffSparse = FiffSparseMatrix::fromEigenSparse(eigen); // FIFF storage layout
const SparseMatrix<double> backToEigen = fiffSparse.toEigenSparse();

Public Methods​

FiffSparseMatrix()​

Constructs an empty FiffSparseMatrix.


FiffSparseMatrix(mat, coding)​

Constructs a FiffSparseMatrix wrapping an existing Eigen sparse matrix.

Parameters:

  • mat : Eigen::SparseMatrix< float > && Eigen sparse matrix to wrap (moved in).

  • coding : FIFFLIB::fiff_int_t FIFF storage coding (FIFFTS_MC_RCS or FIFFTS_MC_CCS).


FiffSparseMatrix(mat)​

Default copy constructor.

Parameters:

  • mat : const FiffSparseMatrix & Sparse matrix to copy.

FiffSparseMatrix(mat)​

Default move constructor.

Parameters:

  • mat : FiffSparseMatrix && Sparse matrix to move from; left in a valid but unspecified state.

operator=()​

Default copy-assignment operator.

Returns:


operator=()​

Default move-assignment operator.

Returns:


~FiffSparseMatrix()​

Default destructor.


eigen()​

Mutable access to the underlying Eigen sparse matrix.

Returns:

  • Eigen::SparseMatrix< float > & — Reference to the internal Eigen::SparseMatrix<float>.

eigen()​

Const access to the underlying Eigen sparse matrix.

Returns:

  • const Eigen::SparseMatrix< float > & — Const reference to the internal Eigen::SparseMatrix<float>.

operator const Eigen::SparseMatrix< float > &()​

Implicit conversion to const Eigen::SparseMatrix<float>&.


rows()​

Number of rows.

Returns:

  • int — Row count of the underlying Eigen sparse matrix.

cols()​

Number of columns.

Returns:

  • int — Column count of the underlying Eigen sparse matrix.

nonZeros()​

Number of stored non-zero elements.

Returns:

  • int — Count of explicitly stored entries in the underlying Eigen sparse matrix.

mne_add_upper_triangle_rcs()​

Add the upper triangle to a lower-triangular sparse RCS matrix.

Returns:

  • FiffSparseMatrix::UPtr — A unique pointer to the newly constructed FiffSparseMatrix with both triangles.

pickLowerTriangleRcs()​

Extract only the lower triangle (including diagonal) from a square RCS matrix.

Returns:

  • FiffSparseMatrix::UPtr — A unique pointer to the newly constructed FiffSparseMatrix with lower-triangle elements.

is_empty()​

Check whether this sparse matrix is empty (no non-zero elements).

Returns:

  • bool — true if the matrix has no data.

toEigenSparse()​

Convert to Eigen::SparseMatrix<double> (cast from float).

Returns:

  • Eigen::SparseMatrix< double > — A double-precision copy of the internal sparse matrix.

Static Methods​

fiff_get_matrix_sparse_dims(tag)​

Interpret dimensions and nz from matrix data.

Parameters:

Returns:

  • std::vector< int > — A vector with the matrix dimension info, or empty on error.

fiff_get_float_sparse_matrix(tag)​

Conversion of tag data into the standard sparse representation.

Parameters:

Returns:

  • FiffSparseMatrix::UPtr — A unique pointer to the newly constructed FiffSparseMatrix, or nullptr on error.

create_sparse_rcs(nrow, ncol, nnz, colindex, vals)​

Create a sparse RCS matrix from row-based data.

Parameters:

  • nrow : int Number of rows.

  • ncol : int Number of columns.

  • nnz : *int ** Number of non-zero elements on each row.

  • colindex : *int *** Column indices of non-zero elements on each row.

  • vals : *float *** Values of non-zero elements on each row.

Returns:

  • FiffSparseMatrix::UPtr — A unique pointer to the newly constructed FiffSparseMatrix, or nullptr on error.

fromEigenSparse(mat)​

Create a FiffSparseMatrix from an Eigen::SparseMatrix<double>.

The data is cast to float for internal storage.

Parameters:

  • mat : const Eigen::SparseMatrix< double > & The Eigen sparse matrix to convert.

Returns:


fromEigenSparse(mat)​

Create a FiffSparseMatrix from an Eigen::SparseMatrix<float>.

Parameters:

  • mat : const Eigen::SparseMatrix< float > & The Eigen sparse matrix to wrap.

Returns:


Example​

Used in examples​

ex_fiff_api​

FIFF library: measurement info, channels, digitizer, transforms, projectors, covariance, events,.

src/examples/ex_fiff_api/main.cpp, line 252
eigen.insert(0, 1) = 2.0;
eigen.insert(2, 3) = -1.5;
eigen.makeCompressed();
const FiffSparseMatrix fiffSparse = FiffSparseMatrix::fromEigenSparse(eigen); // FIFF storage layout
const SparseMatrix<double> backToEigen = fiffSparse.toEigenSparse();
ok &= expect(backToEigen.coeff(2, 3) == -1.5 && backToEigen.nonZeros() == 2, "FiffSparseMatrix round-trips an Eigen sparse matrix");

Authors of this file​