27 #ifndef _TOMOGRAPHER_TOOLS_EZMATIO_H 28 #define _TOMOGRAPHER_TOOLS_EZMATIO_H 40 #include <initializer_list> 78 virtual const char * what()
const noexcept {
return p_final.
c_str(); }
90 inline void update_final() {
91 p_final = p_heading + p_message;
104 void setVarName(
std::string varname) { setHeading(heading(varname)); }
115 :
VarError(varname,
"Can't read variable")
151 :
Exception(heading(fname),
"Error opening file" + (errmsg.size() ?
"': "+errmsg :
""))
157 setHeading(heading(fname));
201 p_matfp = Mat_Open(fname.
c_str(), MAT_ACC_RDONLY);
202 if ( p_matfp == NULL ) {
216 p_matfp = other.p_matfp;
217 other.p_matfp = NULL;
222 if ( p_matfp != NULL ) {
264 p_matfp = other.p_matfp;
265 other.p_matfp = NULL;
280 template<typename It, typename ValueType = typename std::iterator_traits<It>::value_type>
284 for (It it = begin; it != end; ++it) {
315 template<
typename VectorType>
317 :
std::vector<int>(
std::forward<VectorType>(dims))
357 inline int ndims()
const {
return (
int)size(); }
364 if (size() != wanted.
size()) {
368 if (wanted[k] >= 0 && this->
operator[](k) != wanted[k]) {
389 DimList& operator<<(const std::vector<int>& moredims) {
390 insert(end(), moredims.begin(), moredims.end());
399 for (DimList::const_iterator it = dlist.
begin(); it != dlist.
end(); ++it) {
400 if (it != dlist.
begin()) {
437 template<
bool IsRowMajor_ = false>
442 static constexpr
bool IsRowMajor = IsRowMajor_;
452 :
std::vector<int>(dims.size()), p_dims(dims)
454 if (
getNumEl(dims.begin(), dims.end()) <= 0) {
457 if (linearindex >= 0) {
458 setLinearIndex(linearindex);
470 template<
typename VectorIntInitializer>
472 :
std::vector<int>(
std::forward<VectorIntInitializer>(index)), p_dims(dims)
486 TOMOGRAPHER_ENABLED_IF(IsRowMajor)
487 void setLinearIndex(
int linearindex)
489 const int ndims = (int)p_dims.size();
490 for (
int k = ndims-1; k >= 0; --k) {
491 this->at(k) = linearindex % p_dims[k];
492 linearindex /= p_dims[k];
502 TOMOGRAPHER_ENABLED_IF(!IsRowMajor)
503 void setLinearIndex(
int linearindex)
505 const int ndims = (int)p_dims.size();
506 for (
int k = 0; k < ndims; ++k) {
507 this->at(k) = linearindex % p_dims[k];
508 linearindex /= p_dims[k];
518 TOMOGRAPHER_ENABLED_IF(IsRowMajor)
519 int linearIndex()
const 522 for (
int k = 0; k < (int)p_dims.size(); ++k) {
523 linindex *= p_dims[k];
524 linindex += this->at(k);
532 TOMOGRAPHER_ENABLED_IF(!IsRowMajor)
533 int linearIndex()
const 536 for (
int k = (
int)p_dims.size()-1; k >= 0; --k) {
537 linindex *= p_dims[k];
538 linindex += this->at(k);
579 IndexList& operator<<(const std::vector<int>& moredims) {
580 insert(end(), moredims.begin(), moredims.end());
588 template<
bool IsRowMajor2 = false>
593 template<
bool IsRowMajor2 = false>
605 template<
bool IsRowMajor>
606 inline std::ostream& operator<<(std::ostream& str, const IndexList<IsRowMajor> & indexlist)
609 for (
std::size_t j = 0; j < indexlist.size(); ++j) {
611 if (j < indexlist.size()) {
617 return str <<
"==" << indexlist.linearIndex() <<
"]";
624 template<
bool IsRowMajor_ = false,
typename IntType_ =
int>
628 static constexpr
bool IsRowMajor = IsRowMajor_;
629 typedef IntType_ IntType;
634 const IntType p_numel;
637 IntType p_linearIndex;
643 p_index(dims.
size(), 0),
648 ss <<
"Invalid dimensions: " << p_dims;
658 inline IntType linearIndex()
const 660 return p_linearIndex;
663 inline IntType numel()
const 669 TOMOGRAPHER_ENABLED_IF(IsRowMajor)
672 for (
int k = p_dims.
size() - 1; k >= 0; --k) {
674 if (p_index[k] < p_dims[k]) {
683 return ++p_linearIndex;
686 TOMOGRAPHER_ENABLED_IF(!IsRowMajor)
689 for (
int k = 0; k < (int)p_dims.
size(); ++k) {
691 if (p_index[k] < p_dims[k]) {
700 return ++p_linearIndex;
703 IntType operator++() {
709 return Tools::isPositive<IntType>(p_linearIndex) && p_linearIndex < p_numel;
715 template<
bool IsRowMajor2 = false,
typename IntType2 =
int>
719 return index.p_index;
721 template<
bool IsRowMajor2 = false,
typename IntType2 =
int>
732 template<
bool IsRowMajor,
typename IntType>
733 inline std::ostream& operator<<(std::ostream& str, const IndexListIterator<IsRowMajor, IntType> & indexlistit)
738 for (
std::size_t j = 0; j < indexlist.size(); ++j) {
740 if (j < indexlist.size()) {
746 return str <<
"==" << indexlistit.linearIndex() <<
"]";
790 template<
typename T,
typename Enabled =
void>
825 static inline RetType decodeValue(
const Var & var);
829 namespace tomo_internal {
832 template<
typename T,
typename Enabled =
void>
833 struct has_params_member {
838 struct has_params_member<T, typename T::Params>
868 template<
typename T, TOMOGRAPHER_ENABLED_IF_TMPL( tomo_
internal::has_params_member<VarValueDecoder<T> >::value )>
898 VarData() : refcount(0), p_matvar(NULL) { }
905 Var(matvar_t * varinfo)
907 if (varinfo == NULL) {
910 p_vardata =
new VarData;
911 p_vardata->refcount++;
912 p_vardata->p_matvar = varinfo;
929 p_vardata =
new VarData;
930 p_vardata->refcount++;
932 p_vardata->p_matvar = Mat_VarRead(matf.
getMatPtr(), varname.
c_str());
934 p_vardata->p_matvar = Mat_VarReadInfo(matf.
getMatPtr(), varname.
c_str());
936 if (p_vardata->p_matvar == NULL) {
941 p_vardata->p_varname = varname;
947 p_vardata = copy.p_vardata;
948 p_vardata->refcount++;
955 p_vardata = other.p_vardata;
956 other.p_vardata = NULL;
960 if (p_vardata != NULL) {
961 p_vardata->refcount--;
962 if (!p_vardata->refcount) {
963 Mat_VarFree(p_vardata->p_matvar);
986 tomographer_assert(p_vardata != NULL);
987 return p_vardata->p_varname;
996 tomographer_assert(p_vardata != NULL);
997 return p_vardata->p_matvar->rank;
1005 tomographer_assert(p_vardata != NULL);
1006 return DimList(&p_vardata->p_matvar->dims[0],
1007 &p_vardata->p_matvar->dims[p_vardata->p_matvar->rank]);
1015 tomographer_assert(p_vardata != NULL);
1016 return dims().numel();
1028 tomographer_assert(p_vardata != NULL);
1029 return p_vardata->p_matvar->isComplex;
1037 tomographer_assert(p_vardata != NULL);
1038 return p_vardata->p_matvar->rank == 2 && p_vardata->p_matvar->dims[0] == p_vardata->p_matvar->dims[1];
1048 tomographer_assert(p_vardata != NULL);
1049 return (p_vardata->p_matvar->data != NULL);
1091 template<
typename T>
1094 return Tomographer::MAT::value<T>(*this);
1106 template<
typename T, TOMOGRAPHER_ENABLED_IF_TMPL( tomo_
internal::has_params_member<VarValueDecoder<T> >::value )>
1109 return Tomographer::MAT::value<T>(*
this, params);
1119 tomographer_assert(p_vardata != NULL);
1120 return p_vardata->p_matvar;
1129 p_vardata = other.p_vardata;
1130 other.p_vardata = NULL;
1136 p_vardata = copy.p_vardata;
1137 p_vardata->refcount++;
1148 return Var(*
this, varname, load_data);
1155 Mat_Rewind(p_matfp);
1156 matvar_t * p = NULL;
1157 while ( (p = Mat_VarReadNextInfo(p_matfp)) != NULL ) {
1165 template<
typename T,
typename Enabled>
1170 +
typeid(T).name() +
" to decode variable " + var.
varName());
1196 template<>
struct MatType<MAT_T_DOUBLE> {
typedef double Type; };
1198 template<>
struct MatType<MAT_T_SINGLE> {
typedef float Type; };
1200 template<>
struct MatType<MAT_T_INT64> {
typedef int64_t Type; };
1202 template<>
struct MatType<MAT_T_INT32> {
typedef int32_t Type; };
1204 template<>
struct MatType<MAT_T_INT16> {
typedef int16_t Type; };
1206 template<>
struct MatType<MAT_T_INT8> {
typedef int8_t Type; };
1208 template<>
struct MatType<MAT_T_UINT64> {
typedef uint64_t Type; };
1210 template<>
struct MatType<MAT_T_UINT32> {
typedef uint32_t Type; };
1212 template<>
struct MatType<MAT_T_UINT16> {
typedef uint16_t Type; };
1214 template<>
struct MatType<MAT_T_UINT8> {
typedef uint8_t Type; };
1223 #define MAT_SWITCH_REAL_TYPE(typ, ...) \ 1224 do { switch (typ) { \ 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: " \ 1247 #define MAT_SWITCH_COMPLEX_TYPE(typ, ...) \ 1248 do { switch (typ) { \ 1249 case MAT_T_DOUBLE: { typedef std::complex<typename MatType<MAT_T_DOUBLE>::Type> Type; { __VA_ARGS__; } break; } \ 1250 case MAT_T_SINGLE: { typedef std::complex<typename MatType<MAT_T_SINGLE>::Type> Type; { __VA_ARGS__; } break; } \ 1252 throw VarMatTypeError( streamstr("Uknown/unsupported encoded type from matio: " \ 1265 #define MAT_SWITCH_TYPE(matvar_ptr, ...) \ 1267 if (!(matvar_ptr)->isComplex) { \ 1268 switch ((matvar_ptr)->data_type) { \ 1269 case MAT_T_DOUBLE: { typedef typename MatType<MAT_T_DOUBLE>::Type Type; { __VA_ARGS__; } break; } \ 1270 case MAT_T_SINGLE: { typedef typename MatType<MAT_T_SINGLE>::Type Type; { __VA_ARGS__; } break; } \ 1271 case MAT_T_INT64: { typedef typename MatType<MAT_T_INT64>::Type Type; { __VA_ARGS__; } break; } \ 1272 case MAT_T_INT32: { typedef typename MatType<MAT_T_INT32>::Type Type; { __VA_ARGS__; } break; } \ 1273 case MAT_T_INT16: { typedef typename MatType<MAT_T_INT16>::Type Type; { __VA_ARGS__; } break; } \ 1274 case MAT_T_INT8: { typedef typename MatType<MAT_T_INT8>::Type Type; { __VA_ARGS__; } break; } \ 1275 case MAT_T_UINT64: { typedef typename MatType<MAT_T_UINT64>::Type Type; { __VA_ARGS__; } break; } \ 1276 case MAT_T_UINT32: { typedef typename MatType<MAT_T_UINT32>::Type Type; { __VA_ARGS__; } break; } \ 1277 case MAT_T_UINT16: { typedef typename MatType<MAT_T_UINT16>::Type Type; { __VA_ARGS__; } break; } \ 1278 case MAT_T_UINT8: { typedef typename MatType<MAT_T_UINT8>::Type Type; { __VA_ARGS__; } break; } \ 1280 throw VarMatTypeError( streamstr("Uknown/unsupported encoded type from matio: " \ 1281 << (matvar_ptr)->data_type) ); \ 1284 switch ((matvar_ptr)->data_type) { \ 1285 case MAT_T_DOUBLE: { typedef std::complex<typename MatType<MAT_T_DOUBLE>::Type> Type; { __VA_ARGS__; } break; } \ 1286 case MAT_T_SINGLE: { typedef std::complex<typename MatType<MAT_T_SINGLE>::Type> Type; { __VA_ARGS__; } break; } \ 1288 throw VarMatTypeError( streamstr("Uknown/unsupported encoded type from matio: " \ 1289 << (matvar_ptr)->data_type) ); \ 1306 template<
typename T>
1308 #ifdef TOMOGRAPHER_PARSED_BY_DOXYGEN
1311 typename
std::enable_if<(std::numeric_limits<T>::is_specialized ||
1312 Tools::isComplex<T>::value)>::type
1324 streamstr(
"Can't store complex matrix in type " <<
typeid(T).name()));
1326 if (var.
numel() != 1) {
1328 streamstr(
"Expected scalar but got matrix"));
1338 return get_value<Type>(matvar_ptr, var.
varName());
1341 tomographer_assert(
false);
1345 template<
typename MATType,
1348 static inline RetType get_value(
const matvar_t * matvar_ptr,
const std::string & )
1350 return (RetType) ((
const MATType *) matvar_ptr->data)[0];
1353 template<
typename MATType,
1356 static inline RetType get_value(
const matvar_t * matvar_ptr,
const std::string & )
1358 return RetType( ((
const MATType *) matvar_ptr->data)[0],
1362 template<
typename MATType,
1365 static inline RetType get_value(
const matvar_t * ,
const std::string & varname)
1367 throw VarTypeError(varname,
"Expected real scalar, got complex type");
1370 template<
typename MATType,
1373 static inline RetType get_value(
const matvar_t * matvar_ptr,
const std::string & )
1375 typedef typename Tools::ComplexRealScalar<MATType>::type MATRealType;
1376 const mat_complex_split_t * cdata = (mat_complex_split_t*) matvar_ptr->data;
1378 return RetType( ((
const MATRealType *) cdata->Re)[0],
1379 ((
const MATRealType *) cdata->Im)[0] );
1389 namespace tomo_internal {
1392 template<
typename OutType,
typename MatInnerT>
1393 class VarMatDataAccessor
1397 typedef typename Tools::ComplexRealScalar<MatInnerT>::type MatRealInnerT;
1399 const MatInnerT * p_r_ptr;
1400 const MatRealInnerT * p_cre_ptr;
1401 const MatRealInnerT * p_cim_ptr;
1404 VarMatDataAccessor(
const Var & var)
1408 tomographer_assert(matvar_ptr->data != NULL);
1409 if (!matvar_ptr->isComplex) {
1411 p_r_ptr = (
const MatInnerT*) matvar_ptr->data;
1415 const mat_complex_split_t * cdata = (mat_complex_split_t*) matvar_ptr->data;
1417 p_cre_ptr = (
const MatRealInnerT*) cdata->Re;
1418 p_cim_ptr = (
const MatRealInnerT*) cdata->Im;
1419 tomographer_assert(p_cre_ptr != NULL);
1420 tomographer_assert(p_cim_ptr != NULL);
1424 virtual ~VarMatDataAccessor() { }
1426 template<
typename IndexListType,
1427 typename OutType__ = OutType,
typename MatInnerT__ = MatInnerT,
1430 inline OutType
value(IndexListType&& index)
const 1432 tomographer_assert(p_r_ptr != NULL);
1435 std::size_t lin = linear_index(std::forward<IndexListType>(index));
1436 return p_r_ptr[lin];
1439 template<
typename IndexListType,
1440 typename OutType__ = OutType,
typename MatInnerT__ = MatInnerT,
1443 inline OutType
value(IndexListType&& )
const 1448 template<
typename IndexListType,
1449 typename OutType__ = OutType,
typename MatInnerT__ = MatInnerT,
1452 inline OutType
value(IndexListType&& index)
const 1454 tomographer_assert(p_r_ptr != NULL);
1457 std::size_t lin = linear_index(std::forward<IndexListType>(index));
1458 return OutType( p_r_ptr[lin] , 0 );
1461 template<
typename IndexListType,
1462 typename OutType__ = OutType,
typename MatInnerT__ = MatInnerT,
1465 inline OutType
value(IndexListType&& index)
const 1467 tomographer_assert(p_cre_ptr != NULL);
1468 tomographer_assert(p_cim_ptr != NULL);
1471 std::size_t lin = linear_index(std::forward<IndexListType>(index));
1472 return OutType(p_cre_ptr[lin], p_cim_ptr[lin]);
1476 template<
typename IndexListType>
1477 std::size_t linear_index(IndexListType && index)
const 1484 return ind_cmaj.linearIndex();
1580 template<
typename DimListType>
1581 VarShape(
bool is_complex_, DimListType&& dims_,
bool is_square_)
1582 : is_complex(is_complex_), dims(
std::forward<DimListType>(dims_)), is_square(is_square_)
1584 _check_consistency();
1593 : is_complex(var.isComplex()), dims(var.dims()), is_square(var.isSquareMatrix())
1599 void _check_consistency()
1602 tomographer_assert(dims.
size() == 0 || (dims.
size() == 2 && (dims[0] == -1 || dims[1] == -1 || dims[0] == dims[1])));
1615 inline void checkShape(
const VarShape & shape);
1629 err.setVarName(var.
varName());
1641 }
else if (varshape.
dims.
size() == 2) {
1646 }
else if (varshape.
dims.
size() > 0) {
1647 str << varshape.
dims.
size() <<
"-D array";
1649 str <<
" with first two dimensions square";
1656 str <<
" of shape " << varshape.
dims;
1666 (mvardims.
size() != dims.size() && dims.size() > 0) ||
1667 (is_square && (mvardims.
size() != 2 || mvardims[0] != mvardims[1])) ||
1672 errstr <<
"Expected " 1698 template<
typename T_,
bool IsRowMajor_ = false>
1701 static constexpr
bool IsRowMajor = IsRowMajor_;
1705 template<
typename T,
bool IsRowMajor>
1710 static inline void checkShape(
const Var & var)
1714 std::string(
"can't store complex matrix in type ")
1715 +
typeid(T).name());
1726 tomo_internal::VarMatDataAccessor<T, Type> acc(var);
1730 val[il.linearIndex()] = acc.value(il);
1736 tomographer_assert(
false);
1751 namespace tomo_internal {
1756 tomographer_assert(vdims.
size() >= 1);
1758 if (vdims.
size() == 1) {
1759 vdimsreshaped = vdims;
1761 }
else if (vdims.
size() == 2) {
1762 vdimsreshaped = vdims;
1763 }
else if (vdims.
size() > 2) {
1766 tomographer_assert(vdimsreshaped[0] != -1 && vdimsreshaped[1] != -1);
1767 return vdimsreshaped;
1770 template<
typename MatrixType,
typename MatType,
1773 void init_eigen_matrix(MatrixType & matrix,
const DimList & vdims,
1776 typedef typename MatrixType::Scalar Scalar;
1783 const mat_complex_split_t * cdata = (mat_complex_split_t*) matvar_ptr->data;
1785 DimList vdimsreshaped = dims_stackedcols(vdims);
1789 (
const MatRealType *) cdata->Re + data_offset, vdimsreshaped[0], vdimsreshaped[1]
1790 ).template cast<std::complex<RealScalar> >()
1793 (
const MatRealType *) cdata->Im + data_offset, vdimsreshaped[0], vdimsreshaped[1]
1794 ).template cast<std::complex<RealScalar> >()
1798 template<
typename MatrixType,
typename MatRealType,
1801 void init_eigen_matrix(MatrixType & ,
const DimList & ,
1807 template<
typename MatrixType,
typename MatRealType,
1809 void init_eigen_matrix(MatrixType & matrix,
const DimList & vdims,
1812 typedef typename MatrixType::Scalar Scalar;
1816 DimList vdimsreshaped = dims_stackedcols(vdims);
1820 (
const MatRealType *) matvar_ptr->data + data_offset, vdimsreshaped[0], vdimsreshaped[1]
1822 ).
template cast<Scalar>();
1837 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
1870 static inline void checkShape(
const Var & var)
1873 matdims << (Rows!=Eigen::Dynamic ? Rows : -1)
1874 << (Cols!=Eigen::Dynamic ? Cols : -1);
1878 matdims[0] != -1 && matdims[0] == matdims[1]);
1881 if (vdims.
size() > 2) {
1887 err.setVarName(var.
varName());
1892 static inline RetType decodeValue(
const Var & var)
1897 if (vdims.size() < 2) {
1901 if (vdims.size() > 2 &&
1904 "When collapsing several dimensions into Eigen columns, you must use " 1905 "column-major ordering (sorry).");
1908 const int cols = vdims[vdims.size()-1];
1910 const int rows =
getNumEl(vdims.data(), vdims.data()+vdims.size()-1);
1912 MatrixType matrix(rows, cols);
1916 tomo_internal::init_eigen_matrix<MatrixType, Type>(
1939 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols,
typename Alloc>
1947 static inline void checkShape(
const Var & var)
1950 matdims << (Rows!=Eigen::Dynamic ? Rows : -1)
1951 << (Cols!=Eigen::Dynamic ? Cols : -1)
1959 if (vdims.
size() < 1) {
1962 if (vdims.
size() == 1) {
1964 }
else if (vdims.
size() == 2) {
1975 err.setVarName(var.
varName());
1981 static inline RetType decodeValue(
const Var & var)
1985 tomographer_assert(vardims.size() >= 1);
1989 if (vardims.size() == 1) {
1990 innerdims << vardims[0] << 1;
1991 }
else if (vardims.size() == 2) {
1992 innerdims = vardims;
1995 innerdims << vardims[0] << vardims[1];
1996 outerdim =
getNumEl(vardims.data()+2, vardims.data()+vardims.size());
1999 RetType
value(outerdim);
2008 for (j = 0; j < outerdim; ++j) {
2009 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.
static void checkShape(const Var &var)
See VarValueDecoder::checkShape()
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.
DimList()
Initializes an empty dimension list.
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.
DimList(VectorType &&dims)
Initialize a dimension list with another list of dimensions.
A MATLAB file open for reading data.
static RetType decodeValue(const Var &var)
See VarValueDecoder::decodeValue()
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.
#define streamstr(tokens)
Utility macro to format stream tokens to a std::string.
A list of indices with an API for linear or subindices access.
Base Exception class for errors within our MAT routines.
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.
static Var takeOver(matvar_t *varinfo)
Take in charge the given C matvar_t pointer.
Var(Var &&other)
Var implements C++11 move semantics.
Basic utilities for dealing with Eigen matrices and other types.
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 Var &var, const typename VarValueDecoder< T >::Params ¶ms)
Access the value of the given variable, as a C++ type.
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<typename T>() to get an std::vector of the data.
Some C++ utilities, with a tad of C++11 tricks.
int ndims() const
Get the number of dimensions in this array.
T RetType
See VarValueDecoder::RetType.
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.
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.
#define MAT_SWITCH_TYPE(matvar_ptr,...)
Useful hack to get C++ type from dynamical MAT type ID.
VarShape(const Var &var)
Construct a VarShape object reflecting the actual shape of a variable in the data file...
::value DimList(std::initializer_list< T > init)
Initialize the dimension list with an explicit initializer.
VarValueDecoder< T >::RetType value(const Var &var)
Access the value of the given variable, as a C++ type.
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.
DimList & operator<<(int dim)
Add (append) a dimension to the dimension list.
int numel() const
Get the total number of elements in an array of these dimensions.
const unsigned int RowMajorBit
const std::vector< int > & dims() const
Get the underlying dimensions given to the constructor.
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.
DimList(It b, It e)
Initialize the dimension list with an iterator range.
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.
ValueType getNumEl(It begin, It end)
Calculate the product of all dimensions.
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.