v2.0.0
Loading...
Searching...
No Matches
fiff_sparse_matrix.h
Go to the documentation of this file.
1//=============================================================================================================
23
24#ifndef FIFFSPARSEMATRIX_H
25#define FIFFSPARSEMATRIX_H
26
27//=============================================================================================================
28// INCLUDES
29//=============================================================================================================
30
31#include "fiff_global.h"
32#include "fiff_types.h"
33#include "fiff_tag.h"
34
35//=============================================================================================================
36// EIGEN INCLUDES
37//=============================================================================================================
38
39#include <Eigen/Core>
40#include <Eigen/SparseCore>
41
42//=============================================================================================================
43// STL INCLUDES
44//=============================================================================================================
45
46#include <memory>
47
48//=============================================================================================================
49// QT INCLUDES
50//=============================================================================================================
51
52#include <QSharedPointer>
53#include <QDebug>
54
55//=============================================================================================================
56// DEFINE NAMESPACE FIFFLIB
57//=============================================================================================================
58
59namespace FIFFLIB
60{
61
62//=============================================================================================================
74{
75public:
76 using SPtr = QSharedPointer<FiffSparseMatrix>;
77 using ConstSPtr = QSharedPointer<const FiffSparseMatrix>;
78 using UPtr = std::unique_ptr<FiffSparseMatrix>;
79 using ConstUPtr = std::unique_ptr<const FiffSparseMatrix>;
80
81 //=========================================================================================================
86
87 //=========================================================================================================
94 explicit FiffSparseMatrix(Eigen::SparseMatrix<float>&& mat,
96
97 //=========================================================================================================
103 FiffSparseMatrix(const FiffSparseMatrix& mat) = default;
104
105 //=========================================================================================================
112
113 //=========================================================================================================
120
121 //=========================================================================================================
128
129 //=========================================================================================================
133 ~FiffSparseMatrix() = default;
134
135 //============================= Eigen access =============================
136
141 inline Eigen::SparseMatrix<float>& eigen()
142 {
143 return m_eigen;
144 }
145
150 inline const Eigen::SparseMatrix<float>& eigen() const
151 {
152 return m_eigen;
153 }
154
158 inline operator const Eigen::SparseMatrix<float>&() const
159 {
160 return m_eigen;
161 }
162
167 inline int rows() const
168 {
169 return static_cast<int>(m_eigen.rows());
170 }
171
176 inline int cols() const
177 {
178 return static_cast<int>(m_eigen.cols());
179 }
180
185 inline int nonZeros() const
186 {
187 return static_cast<int>(m_eigen.nonZeros());
188 }
189
190 //============================= fiff_sparse.c =============================
191
199 static std::vector<int> fiff_get_matrix_sparse_dims(const FIFFLIB::FiffTag::UPtr& tag);
200
208 static FiffSparseMatrix::UPtr fiff_get_float_sparse_matrix(const FIFFLIB::FiffTag::UPtr& tag);
209
210 //============================= mne_sparse_matop.c =============================
211
223 static FiffSparseMatrix::UPtr create_sparse_rcs(int nrow,
224 int ncol,
225 int* nnz,
226 int** colindex,
227 float** vals);
228
234 FiffSparseMatrix::UPtr mne_add_upper_triangle_rcs();
235
241 FiffSparseMatrix::UPtr pickLowerTriangleRcs() const;
242
248 inline bool is_empty() const;
249
255 inline Eigen::SparseMatrix<double> toEigenSparse() const;
256
265 static FiffSparseMatrix fromEigenSparse(const Eigen::SparseMatrix<double>& mat);
266
274 static FiffSparseMatrix fromEigenSparse(const Eigen::SparseMatrix<float>& mat);
275
276public:
278
279private:
280 Eigen::SparseMatrix<float> m_eigen;
281};
282
283//=============================================================================================================
284// INLINE DEFINITIONS
285//=============================================================================================================
286
287inline bool FiffSparseMatrix::is_empty() const
288{
289 return m_eigen.nonZeros() <= 0;
290}
291
292inline Eigen::SparseMatrix<double> FiffSparseMatrix::toEigenSparse() const
293{
294 return m_eigen.cast<double>();
295}
296
297} // NAMESPACE FIFFLIB
298
299#endif // FIFFSPARSEMATRIX_H
FIFF tag: the 16-byte tag header (kind, type, size, next) plus its decoded payload.
#define FIFFTS_MC_RCS
Definition fiff_file.h:263
Export/import macros and build-info accessors for the FIFFLIB shared library.
#define FIFFSHARED_EXPORT
Definition fiff_global.h:44
Primitive scalar typedefs and forward-compatible aliases backing the FIFF type system.
FIFF file I/O, in-memory data structures and high-level readers/writers.
qint32 fiff_int_t
Definition fiff_types.h:86
Sparse FIFF matrix: CCS or RCS storage with the value / index / pointer triple as written by FiffStre...
Eigen::SparseMatrix< float > & eigen()
FiffSparseMatrix & operator=(const FiffSparseMatrix &)=default
FiffSparseMatrix(const FiffSparseMatrix &mat)=default
FiffSparseMatrix(FiffSparseMatrix &&mat)=default
QSharedPointer< FiffSparseMatrix > SPtr
const Eigen::SparseMatrix< float > & eigen() const
QSharedPointer< const FiffSparseMatrix > ConstSPtr
Eigen::SparseMatrix< double > toEigenSparse() const
FiffSparseMatrix & operator=(FiffSparseMatrix &&)=default
std::unique_ptr< const FiffSparseMatrix > ConstUPtr
std::unique_ptr< FiffSparseMatrix > UPtr
std::unique_ptr< FiffTag > UPtr
Definition fiff_tag.h:165