27 #ifndef _TOMOGRAPHER_TOOLS_EZMATIO_H
28 #define _TOMOGRAPHER_TOOLS_EZMATIO_H
40 #include <initializer_list>
79 virtual const char * what()
const noexcept {
return p_final.
c_str(); }
91 inline void update_final() {
92 p_final = p_heading + p_message;
105 void setVarName(
std::string varname) { setHeading(heading(varname)); }
116 :
VarError(varname,
"Can't read variable")
152 :
Exception(heading(fname),
"Error opening file" + (errmsg.size() ?
"': "+errmsg :
""))
158 setHeading(heading(fname));
212 p_matfp = Mat_Open(fname.
c_str(), MAT_ACC_RDONLY);
213 if ( p_matfp == NULL ) {
227 p_matfp = other.p_matfp;
228 other.p_matfp = NULL;
233 if ( p_matfp != NULL ) {
275 p_matfp = other.p_matfp;
276 other.p_matfp = NULL;
291 template<typename It, typename ValueType = typename std::iterator_traits<It>::value_type>
295 for (It it = begin; it != end; ++it) {
319 template<
typename VectorType>
324 template<typename T, TOMOGRAPHER_ENABLED_IF_TMPL(std::is_convertible<T,int>::value)>
356 if (wanted[k] >= 0 && this->
operator[](k) != wanted[k]) {
367 DimList& operator<<(const std::vector<int>& moredims) {
368 insert(
end(), moredims.begin(), moredims.end());
377 for (DimList::const_iterator it = dlist.
begin(); it != dlist.
end(); ++it) {
378 if (it != dlist.
begin()) {
415 template<
bool IsRowMajor_ = false>
435 if (linearindex >= 0) {
448 template<
typename VectorIntInitializer>
464 TOMOGRAPHER_ENABLED_IF(IsRowMajor)
467 const int ndims = (int)p_dims.
size();
468 for (
int k = ndims-1; k >= 0; --k) {
469 this->
at(k) = linearindex % p_dims[k];
470 linearindex /= p_dims[k];
480 TOMOGRAPHER_ENABLED_IF(!IsRowMajor)
483 const int ndims = (int)p_dims.
size();
484 for (
int k = 0; k < ndims; ++k) {
485 this->
at(k) = linearindex % p_dims[k];
486 linearindex /= p_dims[k];
496 TOMOGRAPHER_ENABLED_IF(IsRowMajor)
500 for (
int k = 0; k < (int)p_dims.
size(); ++k) {
501 linindex *= p_dims[k];
502 linindex += this->
at(k);
510 TOMOGRAPHER_ENABLED_IF(!IsRowMajor)
514 for (
int k = (
int)p_dims.
size()-1; k >= 0; --k) {
515 linindex *= p_dims[k];
516 linindex += this->
at(k);
557 IndexList& operator<<(const std::vector<int>& moredims) {
558 insert(
end(), moredims.begin(), moredims.end());
566 template<
bool IsRowMajor2 = false>
571 template<
bool IsRowMajor2 = false>
583 template<
bool IsRowMajor>
584 inline std::ostream& operator<<(std::ostream& str, const IndexList<IsRowMajor> & indexlist)
587 for (
std::size_t j = 0; j < indexlist.size(); ++j) {
589 if (j < indexlist.size()) {
595 return str <<
"==" << indexlist.linearIndex() <<
"]";
602 template<
bool IsRowMajor_ = false,
typename IntType_ =
int>
606 static constexpr
bool IsRowMajor = IsRowMajor_;
607 typedef IntType_ IntType;
612 const IntType p_numel;
615 IntType p_linearIndex;
621 p_index(dims.
size(), 0),
626 ss <<
"Invalid dimensions: " << p_dims;
636 inline IntType linearIndex()
const
638 return p_linearIndex;
641 inline IntType numel()
const
647 TOMOGRAPHER_ENABLED_IF(IsRowMajor)
650 for (
int k = p_dims.
size() - 1; k >= 0; --k) {
652 if (p_index[k] < p_dims[k]) {
661 return ++p_linearIndex;
664 TOMOGRAPHER_ENABLED_IF(!IsRowMajor)
667 for (
int k = 0; k < (int)p_dims.
size(); ++k) {
669 if (p_index[k] < p_dims[k]) {
678 return ++p_linearIndex;
681 IntType operator++() {
687 return Tools::is_positive<IntType>(p_linearIndex) && p_linearIndex < p_numel;
693 template<
bool IsRowMajor2 = false,
typename IntType2 =
int>
697 return index.p_index;
699 template<
bool IsRowMajor2 = false,
typename IntType2 =
int>
710 template<
bool IsRowMajor,
typename IntType>
711 inline std::ostream& operator<<(std::ostream& str, const IndexListIterator<IsRowMajor, IntType> & indexlistit)
716 for (
std::size_t j = 0; j < indexlist.size(); ++j) {
718 if (j < indexlist.size()) {
724 return str <<
"==" << indexlistit.linearIndex() <<
"]";
759 template<
typename T,
typename Enabled =
void>
798 namespace tomo_internal {
801 template<
typename T,
typename Enabled =
void>
802 struct has_params_member {
807 struct has_params_member<T, typename T::Params>
818 inline typename VarValueDecoder<T>::RetType value(
const Var& var)
824 template<
typename T, TOMOGRAPHER_ENABLED_IF_TMPL( tomo_
internal::has_params_member<VarValueDecoder<T> >::value )>
825 inline typename VarValueDecoder<T>::RetType value(
const Var& var,
826 const typename VarValueDecoder<T>::Params & params)
855 VarData() : refcount(0), p_matvar(NULL) { }
862 Var(matvar_t * varinfo)
864 if (varinfo == NULL) {
867 p_vardata =
new VarData;
868 p_vardata->refcount++;
869 p_vardata->p_matvar = varinfo;
886 p_vardata =
new VarData;
887 p_vardata->refcount++;
889 p_vardata->p_matvar = Mat_VarRead(matf.
getMatPtr(), varname.
c_str());
891 p_vardata->p_matvar = Mat_VarReadInfo(matf.
getMatPtr(), varname.
c_str());
893 if (p_vardata->p_matvar == NULL) {
898 p_vardata->p_varname = varname;
904 p_vardata = copy.p_vardata;
905 p_vardata->refcount++;
912 p_vardata = other.p_vardata;
913 other.p_vardata = NULL;
917 if (p_vardata != NULL) {
918 p_vardata->refcount--;
919 if (!p_vardata->refcount) {
920 Mat_VarFree(p_vardata->p_matvar);
943 assert(p_vardata != NULL);
944 return p_vardata->p_varname;
953 assert(p_vardata != NULL);
954 return p_vardata->p_matvar->rank;
962 assert(p_vardata != NULL);
963 return DimList(&p_vardata->p_matvar->dims[0],
964 &p_vardata->p_matvar->dims[p_vardata->p_matvar->rank]);
972 assert(p_vardata != NULL);
985 assert(p_vardata != NULL);
986 return p_vardata->p_matvar->isComplex;
994 assert(p_vardata != NULL);
995 return p_vardata->p_matvar->rank == 2 && p_vardata->p_matvar->dims[0] == p_vardata->p_matvar->dims[1];
1005 assert(p_vardata != NULL);
1006 return (p_vardata->p_matvar->data != NULL);
1047 template<
typename T>
1050 return Tomographer::MAT::value<T>(*this);
1062 template<
typename T, TOMOGRAPHER_ENABLED_IF_TMPL( tomo_
internal::has_params_member<VarValueDecoder<T> >::value )>
1065 return Tomographer::MAT::value<T>(*
this, params);
1075 assert(p_vardata != NULL);
1076 return p_vardata->p_matvar;
1085 p_vardata = other.p_vardata;
1086 other.p_vardata = NULL;
1092 p_vardata = copy.p_vardata;
1093 p_vardata->refcount++;
1104 return Var(*
this, varname, load_data);
1111 Mat_Rewind(p_matfp);
1112 matvar_t * p = NULL;
1113 while ( (p = Mat_VarReadNextInfo(p_matfp)) != NULL ) {
1121 template<
typename T,
typename Enabled>
1126 +
typeid(T).name() +
" to decode variable " + var.
varName());
1152 template<>
struct MatType<MAT_T_DOUBLE> {
typedef double Type; };
1154 template<>
struct MatType<MAT_T_SINGLE> {
typedef float Type; };
1156 template<>
struct MatType<MAT_T_INT64> {
typedef int64_t Type; };
1158 template<>
struct MatType<MAT_T_INT32> {
typedef int32_t Type; };
1160 template<>
struct MatType<MAT_T_INT16> {
typedef int16_t Type; };
1162 template<>
struct MatType<MAT_T_INT8> {
typedef int8_t Type; };
1164 template<>
struct MatType<MAT_T_UINT64> {
typedef uint64_t Type; };
1166 template<>
struct MatType<MAT_T_UINT32> {
typedef uint32_t Type; };
1168 template<>
struct MatType<MAT_T_UINT16> {
typedef uint16_t Type; };
1170 template<>
struct MatType<MAT_T_UINT8> {
typedef uint8_t Type; };
1179 #define MAT_SWITCH_REAL_TYPE(typ, ...) \
1180 do { switch (typ) { \
1181 case MAT_T_DOUBLE: { typedef typename MatType<MAT_T_DOUBLE>::Type Type; { __VA_ARGS__; } break; } \
1182 case MAT_T_SINGLE: { typedef typename MatType<MAT_T_SINGLE>::Type Type; { __VA_ARGS__; } break; } \
1183 case MAT_T_INT64: { typedef typename MatType<MAT_T_INT64>::Type Type; { __VA_ARGS__; } break; } \
1184 case MAT_T_INT32: { typedef typename MatType<MAT_T_INT32>::Type Type; { __VA_ARGS__; } break; } \
1185 case MAT_T_INT16: { typedef typename MatType<MAT_T_INT16>::Type Type; { __VA_ARGS__; } break; } \
1186 case MAT_T_INT8: { typedef typename MatType<MAT_T_INT8>::Type Type; { __VA_ARGS__; } break; } \
1187 case MAT_T_UINT64: { typedef typename MatType<MAT_T_UINT64>::Type Type; { __VA_ARGS__; } break; } \
1188 case MAT_T_UINT32: { typedef typename MatType<MAT_T_UINT32>::Type Type; { __VA_ARGS__; } break; } \
1189 case MAT_T_UINT16: { typedef typename MatType<MAT_T_UINT16>::Type Type; { __VA_ARGS__; } break; } \
1190 case MAT_T_UINT8: { typedef typename MatType<MAT_T_UINT8>::Type Type; { __VA_ARGS__; } break; } \
1192 throw VarMatTypeError( streamstr("Uknown/unsupported encoded type from matio: " \
1203 #define MAT_SWITCH_COMPLEX_TYPE(typ, ...) \
1204 do { switch (typ) { \
1205 case MAT_T_DOUBLE: { typedef std::complex<typename MatType<MAT_T_DOUBLE>::Type> Type; { __VA_ARGS__; } break; } \
1206 case MAT_T_SINGLE: { typedef std::complex<typename MatType<MAT_T_SINGLE>::Type> Type; { __VA_ARGS__; } break; } \
1208 throw VarMatTypeError( streamstr("Uknown/unsupported encoded type from matio: " \
1221 #define MAT_SWITCH_TYPE(matvar_ptr, ...) \
1223 if (!(matvar_ptr)->isComplex) { \
1224 switch ((matvar_ptr)->data_type) { \
1225 case MAT_T_DOUBLE: { typedef typename MatType<MAT_T_DOUBLE>::Type Type; { __VA_ARGS__; } break; } \
1226 case MAT_T_SINGLE: { typedef typename MatType<MAT_T_SINGLE>::Type Type; { __VA_ARGS__; } break; } \
1227 case MAT_T_INT64: { typedef typename MatType<MAT_T_INT64>::Type Type; { __VA_ARGS__; } break; } \
1228 case MAT_T_INT32: { typedef typename MatType<MAT_T_INT32>::Type Type; { __VA_ARGS__; } break; } \
1229 case MAT_T_INT16: { typedef typename MatType<MAT_T_INT16>::Type Type; { __VA_ARGS__; } break; } \
1230 case MAT_T_INT8: { typedef typename MatType<MAT_T_INT8>::Type Type; { __VA_ARGS__; } break; } \
1231 case MAT_T_UINT64: { typedef typename MatType<MAT_T_UINT64>::Type Type; { __VA_ARGS__; } break; } \
1232 case MAT_T_UINT32: { typedef typename MatType<MAT_T_UINT32>::Type Type; { __VA_ARGS__; } break; } \
1233 case MAT_T_UINT16: { typedef typename MatType<MAT_T_UINT16>::Type Type; { __VA_ARGS__; } break; } \
1234 case MAT_T_UINT8: { typedef typename MatType<MAT_T_UINT8>::Type Type; { __VA_ARGS__; } break; } \
1236 throw VarMatTypeError( streamstr("Uknown/unsupported encoded type from matio: " \
1237 << (matvar_ptr)->data_type) ); \
1240 switch ((matvar_ptr)->data_type) { \
1241 case MAT_T_DOUBLE: { typedef std::complex<typename MatType<MAT_T_DOUBLE>::Type> Type; { __VA_ARGS__; } break; } \
1242 case MAT_T_SINGLE: { typedef std::complex<typename MatType<MAT_T_SINGLE>::Type> Type; { __VA_ARGS__; } break; } \
1244 throw VarMatTypeError( streamstr("Uknown/unsupported encoded type from matio: " \
1245 << (matvar_ptr)->data_type) ); \
1260 template<
typename T>
1262 typename
std::enable_if<(std::numeric_limits<T>::is_specialized ||
1263 Tools::is_complex<T>::value)>::type
1272 streamstr(
"Can't store complex matrix in type " <<
typeid(T).name()));
1274 if (var.
numel() != 1) {
1276 streamstr(
"Expected scalar but got matrix"));
1285 return get_value<Type>(matvar_ptr, var.
varName());
1292 template<
typename MATType,
1295 static inline RetType get_value(
const matvar_t * matvar_ptr,
const std::string & )
1297 return (RetType) ((
const MATType *) matvar_ptr->data)[0];
1300 template<
typename MATType,
1303 static inline RetType get_value(
const matvar_t * matvar_ptr,
const std::string & )
1305 return RetType( ((
const MATType *) matvar_ptr->data)[0],
1309 template<
typename MATType,
1312 static inline RetType get_value(
const matvar_t * ,
const std::string & varname)
1314 throw VarTypeError(varname,
"Expected real scalar, got complex type");
1317 template<
typename MATType,
1320 static inline RetType get_value(
const matvar_t * matvar_ptr,
const std::string & )
1322 typedef typename Tools::complex_real_scalar<MATType>::type MATRealType;
1323 const mat_complex_split_t * cdata = (mat_complex_split_t*) matvar_ptr->data;
1325 return RetType( ((
const MATRealType *) cdata->Re)[0],
1326 ((
const MATRealType *) cdata->Im)[0] );
1336 namespace tomo_internal {
1339 template<
typename OutType,
typename MatInnerT>
1340 class VarMatDataAccessor
1344 typedef typename Tools::complex_real_scalar<MatInnerT>::type MatRealInnerT;
1346 const MatInnerT * p_r_ptr;
1347 const MatRealInnerT * p_cre_ptr;
1348 const MatRealInnerT * p_cim_ptr;
1351 VarMatDataAccessor(
const Var & var)
1355 assert(matvar_ptr->data != NULL);
1356 if (!matvar_ptr->isComplex) {
1358 p_r_ptr = (
const MatInnerT*) matvar_ptr->data;
1362 const mat_complex_split_t * cdata = (mat_complex_split_t*) matvar_ptr->data;
1364 p_cre_ptr = (
const MatRealInnerT*) cdata->Re;
1365 p_cim_ptr = (
const MatRealInnerT*) cdata->Im;
1366 assert(p_cre_ptr != NULL);
1367 assert(p_cim_ptr != NULL);
1371 virtual ~VarMatDataAccessor() { }
1373 template<
typename IndexListType,
1374 typename OutType__ = OutType,
typename MatInnerT__ = MatInnerT,
1375 TOMOGRAPHER_ENABLED_IF_TMPL(!Tools::is_complex<OutType__>::value &&
1376 !Tools::is_complex<MatInnerT__>::value)>
1377 inline OutType value(IndexListType&& index)
const
1379 assert(p_r_ptr != NULL);
1382 std::size_t lin = linear_index(std::forward<IndexListType>(index));
1383 return p_r_ptr[lin];
1386 template<
typename IndexListType,
1387 typename OutType__ = OutType,
typename MatInnerT__ = MatInnerT,
1388 TOMOGRAPHER_ENABLED_IF_TMPL(!Tools::is_complex<OutType__>::value &&
1389 Tools::is_complex<MatInnerT__>::value)>
1390 inline OutType value(IndexListType&& )
const
1392 throw VarTypeError(p_var.
varName(),
"Expected real type, got complex");
1395 template<
typename IndexListType,
1396 typename OutType__ = OutType,
typename MatInnerT__ = MatInnerT,
1397 TOMOGRAPHER_ENABLED_IF_TMPL(Tools::is_complex<OutType__>::value &&
1398 !Tools::is_complex<MatInnerT__>::value)>
1399 inline OutType value(IndexListType&& index)
const
1401 assert(p_r_ptr != NULL);
1404 std::size_t lin = linear_index(std::forward<IndexListType>(index));
1405 return OutType( p_r_ptr[lin] , 0 );
1408 template<
typename IndexListType,
1409 typename OutType__ = OutType,
typename MatInnerT__ = MatInnerT,
1410 TOMOGRAPHER_ENABLED_IF_TMPL(Tools::is_complex<OutType__>::value &&
1411 Tools::is_complex<MatInnerT__>::value)>
1412 inline OutType value(IndexListType&& index)
const
1414 assert(p_cre_ptr != NULL);
1415 assert(p_cim_ptr != NULL);
1418 std::size_t lin = linear_index(std::forward<IndexListType>(index));
1419 return OutType(p_cre_ptr[lin], p_cim_ptr[lin]);
1423 template<
typename IndexListType>
1424 std::size_t linear_index(IndexListType && index)
const
1426 IndexList<false> ind_cmaj{
1431 return ind_cmaj.linearIndex();
1527 template<
typename DimListType>
1528 VarShape(
bool is_complex_, DimListType&& dims_,
bool is_square_)
1529 : is_complex(is_complex_), dims(
std::forward<DimListType>(dims_)), is_square(is_square_)
1531 _check_consistency();
1540 : is_complex(var.isComplex()), dims(var.dims()), is_square(var.isSquareMatrix())
1546 void _check_consistency()
1549 assert(dims.
size() == 0 || (dims.
size() == 2 && (dims[0] == -1 || dims[1] == -1 || dims[0] == dims[1])));
1576 err.setVarName(var.
varName());
1588 }
else if (varshape.
dims.
size() == 2) {
1593 }
else if (varshape.
dims.
size() > 0) {
1594 str << varshape.
dims.
size() <<
"-D array";
1596 str <<
" with first two dimensions square";
1603 str <<
" of shape " << varshape.
dims;
1614 (is_square && (mvardims.
size() != 2 || mvardims[0] != mvardims[1])) ||
1619 errstr <<
"Expected "
1645 template<
typename T_,
bool IsRowMajor_ = false>
1648 static constexpr
bool IsRowMajor = IsRowMajor_;
1652 template<
typename T,
bool IsRowMajor>
1661 std::string(
"can't store complex matrix in type ")
1662 +
typeid(T).name());
1673 tomo_internal::VarMatDataAccessor<T, Type> acc(var);
1677 val[il.linearIndex()] = acc.value(il);
1698 namespace tomo_internal {
1703 assert(vdims.
size() >= 1);
1705 if (vdims.
size() == 1) {
1706 vdimsreshaped = vdims;
1708 }
else if (vdims.
size() == 2) {
1709 vdimsreshaped = vdims;
1710 }
else if (vdims.
size() > 2) {
1713 assert(vdimsreshaped[0] != -1 && vdimsreshaped[1] != -1);
1714 return vdimsreshaped;
1717 template<
typename MatrixType,
typename MatType,
1720 void init_eigen_matrix(MatrixType & matrix,
const DimList & vdims,
1723 typedef typename MatrixType::Scalar Scalar;
1728 const matvar_t * matvar_ptr = var.getMatvarPtr();
1730 const mat_complex_split_t * cdata = (mat_complex_split_t*) matvar_ptr->data;
1732 DimList vdimsreshaped = dims_stackedcols(vdims);
1736 (
const MatRealType *) cdata->Re + data_offset, vdimsreshaped[0], vdimsreshaped[1]
1737 ).template cast<std::complex<RealScalar> >()
1740 (
const MatRealType *) cdata->Im + data_offset, vdimsreshaped[0], vdimsreshaped[1]
1741 ).template cast<std::complex<RealScalar> >()
1745 template<
typename MatrixType,
typename MatRealType,
1748 void init_eigen_matrix(MatrixType & ,
const DimList & ,
1751 throw VarTypeError(var.varName(),
"Expected real type, but got complex.");
1754 template<
typename MatrixType,
typename MatRealType,
1756 void init_eigen_matrix(MatrixType & matrix,
const DimList & vdims,
1759 typedef typename MatrixType::Scalar Scalar;
1761 const matvar_t * matvar_ptr = var.getMatvarPtr();
1763 DimList vdimsreshaped = dims_stackedcols(vdims);
1767 (
const MatRealType *) matvar_ptr->data + data_offset, vdimsreshaped[0], vdimsreshaped[1]
1769 ).
template cast<Scalar>();
1784 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
1820 matdims << (Rows!=Eigen::Dynamic ? Rows : -1)
1821 << (Cols!=Eigen::Dynamic ? Cols : -1);
1825 matdims[0] != -1 && matdims[0] == matdims[1]);
1828 if (vdims.
size() > 2) {
1834 err.setVarName(var.
varName());
1844 if (vdims.
size() < 2) {
1848 if (vdims.
size() > 2 &&
1851 "When collapsing several dimensions into Eigen columns, you must use "
1852 "column-major ordering (sorry).");
1855 const int cols = vdims[vdims.
size()-1];
1859 MatrixType matrix(rows, cols);
1863 tomo_internal::init_eigen_matrix<MatrixType, Type>(
1886 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols,
typename Alloc>
1897 matdims << (Rows!=Eigen::Dynamic ? Rows : -1)
1898 << (Cols!=Eigen::Dynamic ? Cols : -1)
1906 if (vdims.
size() < 1) {
1909 if (vdims.
size() == 1) {
1911 }
else if (vdims.
size() == 2) {
1922 err.setVarName(var.
varName());
1932 assert(vardims.size() >= 1);
1936 if (vardims.size() == 1) {
1937 innerdims << vardims[0] << 1;
1938 }
else if (vardims.size() == 2) {
1939 innerdims = vardims;
1942 innerdims << vardims[0] << vardims[1];
1943 outerdim =
get_numel(vardims.data()+2, vardims.data()+vardims.size());
1946 RetType value(outerdim);
1955 for (j = 0; j < outerdim; ++j) {
1956 tomo_internal::init_eigen_matrix<MatrixType,Type>(
Utilities for formatting strings.
static void checkShape(const Var &var)
Check that the type and shape of the var are compatible with T.
Utility to iterate over a multidim array by increasing linear index.
File(File &&other)
Move constructor.
bool hasData() const
Whether data for this Var object has been loaded.
bool isComplex() const
Whether this variable is complex or real.
Base namespace for the Tomographer project.
IndexList(const std::vector< int > &dims=std::vector< int >(), int linearindex=-1)
Constructor with linear index.
Var var(const std::string varname, bool load_data=true)
Find a variable by name.
Invalid index or index list provided to a routine.
Unknown type of a variable present in the data file.
void checkShape(const Var &var)
Shorthand for checkShape(const VarShape& other) for a shape given by a variable.
Error while reading a variable from the MATLAB data file.
int ndims() const
Number of dimensions of this object.
static constexpr bool IsRowMajor
Is this class calculating and expecting row-major (true) or column-major (false) format.
A MATLAB file open for reading data.
Var & operator=(Var &&other)
Move assignment operator as this object implements C++11 move semantics.
File(const std::string fname)
Open a data file for reading.
bool matchesWanted(const DimList &wanted) const
Test whether our dimensions match the given required list of dimensions.
A list of indices with an API for linear or subindices access.
Base Exception class for errors within our MAT routines.
void setLinearIndex(int linearindex)
Set the linear index.
IndexList & operator<<(int ind)
Append index to list.
const std::string & varName() const
The variable name.
IndexList(const std::vector< int > &dims, VectorIntInitializer &&index)
Constructor with multidimensional index specification.
std::vector< Var > getVarInfoList()
Get a list of all variables in this data file.
Map matio's constants to C/C++ types.
Error while opening a MATLAB file.
int push_back(int...args)
static Var takeOver(matvar_t *varinfo)
Take in charge the given C matvar_t pointer.
Var(Var &&other)
Var implements C++11 move semantics.
void checkShape(const VarShape &shape)
Verify that our requirements match the given other shape.
const bool is_complex
Whether the variable is or should be complex.
A MATLAB variable in the MAT file.
std::vector< int > VectorType
Base vector type (superclass)
bool isSquareMatrix() const
Whether this is a square matrix.
VarValueDecoder< T >::RetType value() const
Read this variable data as native C++ object.
int numel() const
The total number of elements in this array or tensor.
Ask for this type in Var::value() to get an std::vector of the data.
int ndims() const
Get the number of dimensions in this array.
DimList dims() const
Specific dimensions of this numeric array or tensor.
std::ostream & operator<<(std::ostream &out, const DimList &dlist)
C++ output stream operators for a DimList.
#define MAT_SWITCH_TYPE(matvar_ptr,...)
Useful hack to get C++ type from dynamical MAT type ID.
An array of ints which specifies a list of dimensions.
T RetType
Type returned by decodeValue()
Var & operator=(const Var ©)
Var objects are copyable. Beware though that the data is shared.
VarShape(bool is_complex_, DimListType &&dims_, bool is_square_)
Construct a VarShape object from given characteristics.
File & operator=(File &&other)
Move assignment operator.
VarShape(const Var &var)
Construct a VarShape object reflecting the actual shape of a variable in the data file...
Specializable template which takes care of decoding values.
const std::vector< int > & index() const
Return a reference to *this.
Type mismatch (wrong type requested) in a variable read from the MATLAB data file.
Exception relating to a MATLAB variable in the data file.
Describe shape of variable and whether it is complex.
mat_t * getMatPtr()
Direct access to the underlying C pointer used for the MatIO library.
int numel() const
Get the total number of elements in an array of these dimensions.
const unsigned int RowMajorBit
int linearIndex() const
Linear index corresponding to the stored multidimensional indices.
const std::vector< int > & dims() const
Get the underlying dimensions given to the constructor.
#define streamstr(tokens)
Utility macro to format stream tokens to a std::string.
Var(File &matf, const std::string &varname, bool load_data=true)
Read variable from MATLAB data file.
Var(const Var ©)
Var objects are copyable. Beware though that the data is shared.
ValueType get_numel(It begin, It end)
Calculate the product of all dimensions.
const DimList dims
The dimensions of the variable, or requested dimensions.
static RetType decodeValue(const Var &var)
Decode the variable var into the C++ type T.
Basic utilities for dealing with Eigen matrices and other types.
const bool is_square
Whether the variable's two first dimensions are (or should be) the same.
VarValueDecoder< T >::RetType value(const typename VarValueDecoder< T >::Params ¶ms)
Read this variable data as native C++ object.
const matvar_t * getMatvarPtr() const
Access the underlying C pointer to the MatIO structure. Use with care.