v2.0.0
Loading...
Searching...
No Matches
fiff_named_matrix.h
Go to the documentation of this file.
1//=============================================================================================================
26
27#ifndef FIFF_NAMED_MATRIX_H
28#define FIFF_NAMED_MATRIX_H
29
30//=============================================================================================================
31// INCLUDES
32//=============================================================================================================
33
34#include "fiff_global.h"
35#include "fiff_constants.h"
36#include "fiff_types.h"
37
38//=============================================================================================================
39// EIGEN INCLUDES
40//=============================================================================================================
41
42#include <Eigen/Core>
43
44//=============================================================================================================
45// QT INCLUDES
46//=============================================================================================================
47
48#include <QStringList>
49#include <QSharedData>
50#include <QSharedDataPointer>
51#include <QSharedPointer>
52#include <memory>
53
54//=============================================================================================================
55// DEFINE NAMESPACE FIFFLIB
56//=============================================================================================================
57
58namespace FIFFLIB
59{
60
61//=============================================================================================================
72class FIFFSHARED_EXPORT FiffNamedMatrix : public QSharedData
73{
74public:
75 using SPtr = QSharedPointer<FiffNamedMatrix>;
76 using ConstSPtr = QSharedPointer<const FiffNamedMatrix>;
77 using UPtr = std::unique_ptr<FiffNamedMatrix>;
78 using ConstUPtr = std::unique_ptr<const FiffNamedMatrix>;
79 using SDPtr = QSharedDataPointer<FiffNamedMatrix>;
80
81 //=========================================================================================================
86
87 //=========================================================================================================
97 explicit FiffNamedMatrix(fiff_int_t p_nrow,
98 fiff_int_t p_ncol,
99 const QStringList& p_row_names,
100 const QStringList& p_col_names,
101 const Eigen::MatrixXd& p_data);
102
103 //=========================================================================================================
109 FiffNamedMatrix(const FiffNamedMatrix& p_FiffNamedMatrix);
110
111 //=========================================================================================================
115 ~FiffNamedMatrix() = default;
116
117 //=========================================================================================================
121 void clear();
122
123 //=========================================================================================================
129 inline bool isEmpty() const;
130
131 //ToDo return the transposed matrix instead of applying it to its members
132 //=========================================================================================================
137
138// //=========================================================================================================
139// /**
140// * Assignment Operator
141// *
142// * @return rhs named matrix which hould be assigned.
143// */
144// inline FiffNamedMatrix& operator=(const FiffNamedMatrix& rhs);
145
146 //=========================================================================================================
155 friend std::ostream& operator<<(std::ostream& out, const FIFFLIB::FiffNamedMatrix &p_FiffNamedMatrix);
156
164 friend bool operator==(const FiffNamedMatrix &a, const FiffNamedMatrix &b);
165
166public:
167 fiff_int_t nrow;
168 fiff_int_t ncol;
169 QStringList row_names;
170 QStringList col_names;
171 Eigen::MatrixXd data;
172
173};
174
175//=============================================================================================================
176// INLINE DEFINITIONS
177//=============================================================================================================
178
179//inline FiffNamedMatrix& FiffNamedMatrix::operator=(const FiffNamedMatrix& rhs)
180//{
181// // Check for self-assignment!
182// if (this == &rhs)
183// return *this;
184// //Else
185// nrow = rhs.nrow;
186// ncol = rhs.ncol;
187// row_names = rhs.row_names;
188// col_names = rhs.col_names;
189// data = rhs.data;
190
191// return *this;
192//}
193
194inline bool FiffNamedMatrix::isEmpty() const
195{
196 return !(this->data.size() > 0);
197}
198
199//=============================================================================================================
200
201inline std::ostream& operator<<(std::ostream& out, const FIFFLIB::FiffNamedMatrix &p_FiffNamedMatrix)
202{
203 bool t_bIsShort = true;
204 out << "#### Fiff Named Matrix ####\n";
205 out << "\tnrow: " << p_FiffNamedMatrix.nrow << std::endl;
206 out << "\tncol: " << p_FiffNamedMatrix.ncol << std::endl;
207
208 Eigen::MatrixXd data;
209
210 out << "\trow_names " << p_FiffNamedMatrix.row_names.size() << ":\n\t";
211 if(t_bIsShort)
212 {
213 qint32 nchan = p_FiffNamedMatrix.row_names.size() > 6 ? 6 : p_FiffNamedMatrix.row_names.size();
214 for(qint32 i = 0; i < nchan/2; ++i)
215 out << p_FiffNamedMatrix.row_names[i].toUtf8().constData() << " ";
216 out << "... ";
217 for(qint32 i = p_FiffNamedMatrix.row_names.size() - nchan/2; i < p_FiffNamedMatrix.row_names.size(); ++i)
218 out << p_FiffNamedMatrix.row_names[i].toUtf8().constData() << " ";
219 out << std::endl;
220 }
221
222 out << "\tcol_names " << p_FiffNamedMatrix.col_names.size() << ":\n\t";
223 if(t_bIsShort)
224 {
225 qint32 nchan = p_FiffNamedMatrix.col_names.size() > 6 ? 6 : p_FiffNamedMatrix.col_names.size();
226 for(qint32 i = 0; i < nchan/2; ++i)
227 out << p_FiffNamedMatrix.col_names[i].toUtf8().constData() << " ";
228 out << "... ";
229 for(qint32 i = p_FiffNamedMatrix.col_names.size() - nchan/2; i < p_FiffNamedMatrix.col_names.size(); ++i)
230 out << p_FiffNamedMatrix.col_names[i].toUtf8().constData() << " ";
231 out << std::endl;
232 }
233
234 out << "\tdata " << p_FiffNamedMatrix.data.rows() << " x " << p_FiffNamedMatrix.data.cols() << ":\n\t";
235 if(t_bIsShort)
236 {
237 qint32 nrows = p_FiffNamedMatrix.data.rows() > 6 ? 6 : p_FiffNamedMatrix.data.rows();
238 qint32 ncols = p_FiffNamedMatrix.data.cols() > 6 ? 6 : p_FiffNamedMatrix.data.cols();
239 if(nrows == 1)
240 {
241 for(qint32 i = 0; i < nrows; ++i)
242 {
243 for(qint32 j = 0; j < ncols/2; ++j)
244 out << p_FiffNamedMatrix.data(i,j) << " ";
245 out << "... ";
246 for(qint32 j = p_FiffNamedMatrix.data.cols() - ncols/2; j < p_FiffNamedMatrix.data.cols(); ++j)
247 out << p_FiffNamedMatrix.data(i,j) << " ";
248 out << "\n\t";
249 }
250 }
251 else
252 {
253 for(qint32 i = 0; i < nrows/2; ++i)
254 {
255 for(qint32 j = 0; j < ncols/2; ++j)
256 out << p_FiffNamedMatrix.data(i,j) << " ";
257 out << "... ";
258 for(qint32 j = p_FiffNamedMatrix.data.cols() - ncols/2; j < p_FiffNamedMatrix.data.cols(); ++j)
259 out << p_FiffNamedMatrix.data(i,j) << " ";
260 out << "\n\t";
261 }
262 out << "...\n\t";
263 for(qint32 i = p_FiffNamedMatrix.data.rows()-nrows/2; i < p_FiffNamedMatrix.data.rows(); ++i)
264 {
265 for(qint32 j = 0; j < ncols/2; ++j)
266 out << p_FiffNamedMatrix.data(i,j) << " ";
267 out << "... ";
268 for(qint32 j = p_FiffNamedMatrix.data.cols() - ncols/2; j < p_FiffNamedMatrix.data.cols(); ++j)
269 out << p_FiffNamedMatrix.data(i,j) << " ";
270 out << "\n\t";
271 }
272 }
273 out << "\n";
274 }
275
276 return out;
277}
278
279//=============================================================================================================
280
281inline bool operator== (const FiffNamedMatrix &a, const FiffNamedMatrix &b)
282{
283 return (a.nrow == b.nrow &&
284 a.ncol == b.ncol &&
285 a.row_names == b.row_names &&
286 a.col_names == b.col_names &&
287 a.data.isApprox(b.data, 0.0001));
288}
289} // NAMESPACE
290
291#endif // FIFF_NAMED_MATRIX_H
bool operator==(const BIDSPath &a, const BIDSPath &b)
Symbolic FIFF tag, block, value, unit and channel-type constants shared across FIFFLIB.
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.
std::ostream & operator<<(std::ostream &out, const FIFFLIB::FiffCov &p_FiffCov)
Definition fiff_cov.h:268
bool operator==(const FiffChInfo &a, const FiffChInfo &b)
FIFF named matrix: dense / sparse Eigen matrix plus row-name and column-name string lists.
std::unique_ptr< FiffNamedMatrix > UPtr
std::unique_ptr< const FiffNamedMatrix > ConstUPtr
FiffNamedMatrix(fiff_int_t p_nrow, fiff_int_t p_ncol, const QStringList &p_row_names, const QStringList &p_col_names, const Eigen::MatrixXd &p_data)
friend std::ostream & operator<<(std::ostream &out, const FIFFLIB::FiffNamedMatrix &p_FiffNamedMatrix)
QSharedPointer< FiffNamedMatrix > SPtr
QSharedDataPointer< FiffNamedMatrix > SDPtr
QSharedPointer< const FiffNamedMatrix > ConstSPtr