28 #ifndef _TOMOGRAPHER_TOOLS_EZMATIO_H 29 #define _TOMOGRAPHER_TOOLS_EZMATIO_H 41 #include <initializer_list> 80 virtual const char * what()
const noexcept {
return p_final.
c_str(); }
92 inline void update_final() {
93 p_final = p_heading + p_message;
106 void setVarName(
std::string varname) { setHeading(heading(varname)); }
117 :
VarError(varname,
"Can't read variable")
153 :
Exception(heading(fname),
"Error opening file" + (errmsg.size() ?
": "+errmsg :
""))
159 setHeading(heading(fname));
203 p_matfp = Mat_Open(fname.
c_str(), MAT_ACC_RDONLY);
204 if ( p_matfp == NULL ) {
218 p_matfp = other.p_matfp;
219 other.p_matfp = NULL;
224 if ( p_matfp != NULL ) {
266 p_matfp = other.p_matfp;
267 other.p_matfp = NULL;
270 File& operator=(
const File& other) =
delete;
282 template<typename It, typename ValueType = typename std::iterator_traits<It>::value_type>
286 for (It it = begin; it != end; ++it) {
317 template<
typename VectorType>
319 :
std::vector<int>(
std::forward<VectorType>(dims))
359 inline int ndims()
const {
return (
int)size(); }
366 if (size() != wanted.
size()) {
370 if (wanted[k] >= 0 && this->
operator[](k) != wanted[k]) {
391 DimList& operator<<(const std::vector<int>& moredims) {
392 insert(end(), moredims.begin(), moredims.end());
401 for (DimList::const_iterator it = dlist.
begin(); it != dlist.
end(); ++it) {
402 if (it != dlist.
begin()) {
439 template<
bool IsRowMajor_ = false>
444 static constexpr
bool IsRowMajor = IsRowMajor_;
454 :
std::vector<int>(dims.size()), p_dims(dims)
456 if (
getNumEl(dims.begin(), dims.end()) <= 0) {
459 if (linearindex >= 0) {
460 setLinearIndex(linearindex);
472 template<
typename VectorIntInitializer>
474 :
std::vector<int>(
std::forward<VectorIntInitializer>(index)), p_dims(dims)
488 TOMOGRAPHER_ENABLED_IF(IsRowMajor)
489 void setLinearIndex(
int linearindex)
491 const int ndims = (int)p_dims.size();
492 for (
int k = ndims-1; k >= 0; --k) {
504 TOMOGRAPHER_ENABLED_IF(!IsRowMajor)
505 void setLinearIndex(
int linearindex)
507 const int ndims = (int)p_dims.size();
508 for (
int k = 0; k < ndims; ++k) {
520 TOMOGRAPHER_ENABLED_IF(IsRowMajor)
521 int linearIndex()
const 524 for (
int k = 0; k < (int)p_dims.size(); ++k) {
534 TOMOGRAPHER_ENABLED_IF(!IsRowMajor)
535 int linearIndex()
const 538 for (
int k = (
int)p_dims.size()-1; k >= 0; --k) {
581 IndexList& operator<<(const std::vector<int>& moredims) {
582 insert(end(), moredims.begin(), moredims.end());
590 template<
bool IsRowMajor2 = false>
595 template<
bool IsRowMajor2 = false>
607 template<
bool IsRowMajor>
608 inline std::ostream& operator<<(std::ostream& str, const IndexList<IsRowMajor> & indexlist)
611 for (
std::size_t j = 0; j < indexlist.size(); ++j) {
613 if (j < indexlist.size()) {
619 return str <<
"==" << indexlist.linearIndex() <<
"]";
626 template<
bool IsRowMajor_ = false,
typename IntType_ =
int>
630 static constexpr
bool IsRowMajor = IsRowMajor_;
631 typedef IntType_ IntType;
636 const IntType p_numel;
639 IntType p_linearIndex;
645 p_index(dims.
size(), 0),
650 ss <<
"Invalid dimensions: " << p_dims;
660 inline IntType linearIndex()
const 662 return p_linearIndex;
665 inline IntType numel()
const 671 TOMOGRAPHER_ENABLED_IF(IsRowMajor)
674 for (
int k = (
int)p_dims.
size() - 1; k >= 0; --k) {
685 return ++p_linearIndex;
688 TOMOGRAPHER_ENABLED_IF(!IsRowMajor)
693 if (p_index[k] < p_dims[k]) {
702 return ++p_linearIndex;
705 IntType operator++() {
711 return Tools::isPositive<IntType>(p_linearIndex) && p_linearIndex < p_numel;
717 template<
bool IsRowMajor2 = false,
typename IntType2 =
int>
721 return index.p_index;
723 template<
bool IsRowMajor2 = false,
typename IntType2 =
int>
734 template<
bool IsRowMajor,
typename IntType>
735 inline std::ostream& operator<<(std::ostream& str, const IndexListIterator<IsRowMajor, IntType> & indexlistit)
740 for (
std::size_t j = 0; j < indexlist.size(); ++j) {
742 if (j < indexlist.size()) {
748 return str <<
"==" << indexlistit.linearIndex() <<
"]";
801 template<
typename T,
typename Enabled =
void>
837 static inline RetType decodeValue(
const Var & var);
841 namespace tomo_internal {
843 template<
typename T,
typename Res =
void>
844 struct enable_if_is_type {
typedef T check_type;
typedef Res type; };
848 template<
typename T,
typename Enabled =
void>
849 struct has_params_member {
855 struct has_params_member<T, typename enable_if_is_type<typename T::Params>::type >
860 template<
typename Scalar>
892 template<
typename T, TOMOGRAPHER_ENABLED_IF_TMPL( tomo_
internal::has_params_member<VarValueDecoder<T> >::value )>
918 class TOMOGRAPHER_EXPORT
Var 922 VarData() : refcount(0), p_matvar(NULL) { }
929 Var(matvar_t * varinfo)
931 if (varinfo == NULL) {
934 p_vardata =
new VarData;
935 p_vardata->refcount++;
936 p_vardata->p_matvar = varinfo;
953 p_vardata =
new VarData;
954 p_vardata->refcount++;
956 p_vardata->p_matvar = Mat_VarRead(matf.
getMatPtr(), varname.
c_str());
958 p_vardata->p_matvar = Mat_VarReadInfo(matf.
getMatPtr(), varname.
c_str());
960 if (p_vardata->p_matvar == NULL) {
965 p_vardata->p_varname = varname;
971 p_vardata = copy.p_vardata;
972 p_vardata->refcount++;
979 p_vardata = other.p_vardata;
980 other.p_vardata = NULL;
984 if (p_vardata != NULL) {
985 p_vardata->refcount--;
986 if (!p_vardata->refcount) {
987 Mat_VarFree(p_vardata->p_matvar);
1001 return Var(varinfo);
1011 return p_vardata->p_varname;
1021 return p_vardata->p_matvar->rank;
1030 return DimList(&p_vardata->p_matvar->dims[0],
1031 &p_vardata->p_matvar->dims[p_vardata->p_matvar->rank]);
1040 return dims().numel();
1053 return p_vardata->p_matvar->isComplex;
1062 return p_vardata->p_matvar->rank == 2 && p_vardata->p_matvar->dims[0] == p_vardata->p_matvar->dims[1];
1073 return (p_vardata->p_matvar->data != NULL);
1115 template<
typename T>
1118 return Tomographer::MAT::value<T>(*this);
1130 template<
typename T, TOMOGRAPHER_ENABLED_IF_TMPL( tomo_
internal::has_params_member<VarValueDecoder<T> >::value )>
1133 return Tomographer::MAT::value<T>(*
this, params);
1144 return p_vardata->p_matvar;
1153 p_vardata = other.p_vardata;
1154 other.p_vardata = NULL;
1160 p_vardata = copy.p_vardata;
1161 p_vardata->refcount++;
1172 return Var(*
this, varname, load_data);
1179 Mat_Rewind(p_matfp);
1180 matvar_t * p = NULL;
1181 while ( (p = Mat_VarReadNextInfo(p_matfp)) != NULL ) {
1189 template<
typename T,
typename Enabled>
1194 +
typeid(T).name() +
" to decode variable " + var.
varName());
1220 template<>
struct MatType<MAT_T_DOUBLE> {
typedef double Type; };
1222 template<>
struct MatType<MAT_T_SINGLE> {
typedef float Type; };
1224 template<>
struct MatType<MAT_T_INT64> {
typedef int64_t Type; };
1226 template<>
struct MatType<MAT_T_INT32> {
typedef int32_t Type; };
1228 template<>
struct MatType<MAT_T_INT16> {
typedef int16_t Type; };
1230 template<>
struct MatType<MAT_T_INT8> {
typedef int8_t Type; };
1232 template<>
struct MatType<MAT_T_UINT64> {
typedef uint64_t Type; };
1234 template<>
struct MatType<MAT_T_UINT32> {
typedef uint32_t Type; };
1236 template<>
struct MatType<MAT_T_UINT16> {
typedef uint16_t Type; };
1238 template<>
struct MatType<MAT_T_UINT8> {
typedef uint8_t Type; };
1247 #define MAT_SWITCH_REAL_TYPE(typ, ...) \ 1248 do { switch (typ) { \ 1249 case MAT_T_DOUBLE: { typedef typename MatType<MAT_T_DOUBLE>::Type Type; { __VA_ARGS__; } break; } \ 1250 case MAT_T_SINGLE: { typedef typename MatType<MAT_T_SINGLE>::Type Type; { __VA_ARGS__; } break; } \ 1251 case MAT_T_INT64: { typedef typename MatType<MAT_T_INT64>::Type Type; { __VA_ARGS__; } break; } \ 1252 case MAT_T_INT32: { typedef typename MatType<MAT_T_INT32>::Type Type; { __VA_ARGS__; } break; } \ 1253 case MAT_T_INT16: { typedef typename MatType<MAT_T_INT16>::Type Type; { __VA_ARGS__; } break; } \ 1254 case MAT_T_INT8: { typedef typename MatType<MAT_T_INT8>::Type Type; { __VA_ARGS__; } break; } \ 1255 case MAT_T_UINT64: { typedef typename MatType<MAT_T_UINT64>::Type Type; { __VA_ARGS__; } break; } \ 1256 case MAT_T_UINT32: { typedef typename MatType<MAT_T_UINT32>::Type Type; { __VA_ARGS__; } break; } \ 1257 case MAT_T_UINT16: { typedef typename MatType<MAT_T_UINT16>::Type Type; { __VA_ARGS__; } break; } \ 1258 case MAT_T_UINT8: { typedef typename MatType<MAT_T_UINT8>::Type Type; { __VA_ARGS__; } break; } \ 1260 throw VarMatTypeError( streamstr("Uknown/unsupported encoded type from matio: " \ 1271 #define MAT_SWITCH_COMPLEX_TYPE(typ, ...) \ 1272 do { switch (typ) { \ 1273 case MAT_T_DOUBLE: { typedef std::complex<typename MatType<MAT_T_DOUBLE>::Type> Type; { __VA_ARGS__; } break; } \ 1274 case MAT_T_SINGLE: { typedef std::complex<typename MatType<MAT_T_SINGLE>::Type> Type; { __VA_ARGS__; } break; } \ 1276 throw VarMatTypeError( streamstr("Uknown/unsupported encoded type from matio: " \ 1289 #define MAT_SWITCH_TYPE(matvar_ptr, ...) \ 1291 if (!(matvar_ptr)->isComplex) { \ 1292 switch ((matvar_ptr)->data_type) { \ 1293 case MAT_T_DOUBLE: { typedef typename MatType<MAT_T_DOUBLE>::Type Type; { __VA_ARGS__; } break; } \ 1294 case MAT_T_SINGLE: { typedef typename MatType<MAT_T_SINGLE>::Type Type; { __VA_ARGS__; } break; } \ 1295 case MAT_T_INT64: { typedef typename MatType<MAT_T_INT64>::Type Type; { __VA_ARGS__; } break; } \ 1296 case MAT_T_INT32: { typedef typename MatType<MAT_T_INT32>::Type Type; { __VA_ARGS__; } break; } \ 1297 case MAT_T_INT16: { typedef typename MatType<MAT_T_INT16>::Type Type; { __VA_ARGS__; } break; } \ 1298 case MAT_T_INT8: { typedef typename MatType<MAT_T_INT8>::Type Type; { __VA_ARGS__; } break; } \ 1299 case MAT_T_UINT64: { typedef typename MatType<MAT_T_UINT64>::Type Type; { __VA_ARGS__; } break; } \ 1300 case MAT_T_UINT32: { typedef typename MatType<MAT_T_UINT32>::Type Type; { __VA_ARGS__; } break; } \ 1301 case MAT_T_UINT16: { typedef typename MatType<MAT_T_UINT16>::Type Type; { __VA_ARGS__; } break; } \ 1302 case MAT_T_UINT8: { typedef typename MatType<MAT_T_UINT8>::Type Type; { __VA_ARGS__; } break; } \ 1304 throw VarMatTypeError( streamstr("Uknown/unsupported encoded type from matio: " \ 1305 << (matvar_ptr)->data_type) ); \ 1308 switch ((matvar_ptr)->data_type) { \ 1309 case MAT_T_DOUBLE: { typedef std::complex<typename MatType<MAT_T_DOUBLE>::Type> Type; { __VA_ARGS__; } break; } \ 1310 case MAT_T_SINGLE: { typedef std::complex<typename MatType<MAT_T_SINGLE>::Type> Type; { __VA_ARGS__; } break; } \ 1312 throw VarMatTypeError( streamstr("Uknown/unsupported encoded type from matio: " \ 1313 << (matvar_ptr)->data_type) ); \ 1330 template<
typename T>
1332 #ifdef TOMOGRAPHER_PARSED_BY_DOXYGEN
1335 typename
std::enable_if<(std::numeric_limits<T>::is_specialized ||
1336 tomo_internal::isComplex<T>::value)>::type
1349 streamstr(
"Can't store complex matrix in type " <<
typeid(T).name()));
1351 if (var.
numel() != 1) {
1353 streamstr(
"Expected scalar but got matrix"));
1363 return get_value<Type>(matvar_ptr, var.
varName());
1370 template<
typename MATType,
1373 static inline RetType get_value(
const matvar_t * matvar_ptr,
const std::string & )
1375 return RetType( ((
const MATType *) matvar_ptr->data)[0] );
1378 template<
typename MATType,
1381 static inline RetType get_value(
const matvar_t * matvar_ptr,
const std::string & )
1383 return RetType(
typename Tools::ComplexRealScalar<RetType>::type(((
const MATType *) matvar_ptr->data)[0]),
1387 template<
typename MATType,
1390 static inline RetType get_value(
const matvar_t * ,
const std::string & varname)
1392 throw VarTypeError(varname,
"Expected real scalar, got complex type");
1395 template<
typename MATType,
1398 static inline RetType get_value(
const matvar_t * matvar_ptr,
const std::string & )
1400 typedef typename Tools::ComplexRealScalar<MATType>::type MATRealType;
1401 const mat_complex_split_t * cdata = (mat_complex_split_t*) matvar_ptr->data;
1403 return RetType(
typename Tools::ComplexRealScalar<RetType>::type( ((
const MATRealType *) cdata->Re)[0] ),
1404 typename Tools::ComplexRealScalar<RetType>::type( ((
const MATRealType *) cdata->Im)[0] ) );
1414 namespace tomo_internal {
1417 template<
typename OutType,
typename MatInnerT>
1418 class VarMatDataAccessor
1422 typedef typename Tools::ComplexRealScalar<MatInnerT>::type MatRealInnerT;
1424 const MatInnerT * p_r_ptr;
1425 const MatRealInnerT * p_cre_ptr;
1426 const MatRealInnerT * p_cim_ptr;
1429 VarMatDataAccessor(
const Var & var)
1434 if (!matvar_ptr->isComplex) {
1436 p_r_ptr = (
const MatInnerT*) matvar_ptr->data;
1440 const mat_complex_split_t * cdata = (mat_complex_split_t*) matvar_ptr->data;
1442 p_cre_ptr = (
const MatRealInnerT*) cdata->Re;
1443 p_cim_ptr = (
const MatRealInnerT*) cdata->Im;
1449 virtual ~VarMatDataAccessor() { }
1451 template<
typename IndexListType,
1452 typename OutType__ = OutType,
typename MatInnerT__ = MatInnerT,
1455 inline OutType
value(IndexListType&& index)
const 1460 std::size_t lin = linear_index(std::forward<IndexListType>(index));
1461 return (OutType)p_r_ptr[lin];
1464 template<
typename IndexListType,
1465 typename OutType__ = OutType,
typename MatInnerT__ = MatInnerT,
1468 inline OutType
value(IndexListType&& )
const 1473 template<
typename IndexListType,
1474 typename OutType__ = OutType,
typename MatInnerT__ = MatInnerT,
1477 inline OutType
value(IndexListType&& index)
const 1482 std::size_t lin = linear_index(std::forward<IndexListType>(index));
1486 template<
typename IndexListType,
1487 typename OutType__ = OutType,
typename MatInnerT__ = MatInnerT,
1490 inline OutType
value(IndexListType&& index)
const 1496 std::size_t lin = linear_index(std::forward<IndexListType>(index));
1502 template<
typename IndexListType>
1503 std::size_t linear_index(IndexListType && index)
const 1606 template<
typename DimListType>
1607 VarShape(
bool is_complex_, DimListType&& dims_,
bool is_square_)
1608 : is_complex(is_complex_), dims(
std::forward<DimListType>(dims_)), is_square(is_square_)
1610 _check_consistency();
1619 : is_complex(var.isComplex()), dims(var.dims()), is_square(var.isSquareMatrix())
1625 void _check_consistency()
1641 inline void checkShape(
const VarShape & shape);
1655 err.setVarName(var.
varName());
1667 }
else if (varshape.
dims.
size() == 2) {
1672 }
else if (varshape.
dims.
size() > 0) {
1673 str << varshape.
dims.
size() <<
"-D array";
1675 str <<
" with first two dimensions square";
1682 str <<
" of shape " << varshape.
dims;
1692 (mvardims.
size() != dims.size() && dims.size() > 0) ||
1693 (is_square && (mvardims.
size() != 2 || mvardims[0] != mvardims[1])) ||
1698 errstr <<
"Expected " 1724 template<
typename T_,
bool IsRowMajor_ = false>
1727 static constexpr
bool IsRowMajor = IsRowMajor_;
1731 template<
typename T,
bool IsRowMajor>
1737 static inline void checkShape(
const Var & var)
1741 std::string(
"can't store complex matrix in type ")
1742 +
typeid(T).name());
1753 tomo_internal::VarMatDataAccessor<T, Type> acc(var);
1757 val[(
std::size_t)il.linearIndex()] = acc.value(il);
1778 namespace tomo_internal {
1785 if (vdims.
size() == 1) {
1786 vdimsreshaped = vdims;
1788 }
else if (vdims.
size() == 2) {
1789 vdimsreshaped = vdims;
1790 }
else if (vdims.
size() > 2) {
1794 return vdimsreshaped;
1797 template<
typename MatrixType,
typename MatType,
1800 inline void init_eigen_matrix(MatrixType & matrix,
const DimList & vdims,
1803 typedef typename MatrixType::Scalar Scalar;
1810 const mat_complex_split_t * cdata = (mat_complex_split_t*) matvar_ptr->data;
1812 DimList vdimsreshaped = dims_stackedcols(vdims);
1816 (
const MatRealType *) cdata->Re + data_offset, vdimsreshaped[0], vdimsreshaped[1]
1817 ).template cast<std::complex<RealScalar> >()
1820 (
const MatRealType *) cdata->Im + data_offset, vdimsreshaped[0], vdimsreshaped[1]
1821 ).template cast<std::complex<RealScalar> >()
1825 template<
typename MatrixType,
typename MatRealType,
1828 inline void init_eigen_matrix(MatrixType & ,
const DimList & ,
1834 template<
typename MatrixType,
typename MatRealType,
1836 inline void init_eigen_matrix(MatrixType & matrix,
const DimList & vdims,
1839 typedef typename MatrixType::Scalar Scalar;
1843 DimList vdimsreshaped = dims_stackedcols(vdims);
1847 (
const MatRealType *) matvar_ptr->data + data_offset, vdimsreshaped[0], vdimsreshaped[1]
1849 ).
template cast<Scalar>();
1864 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
1899 static inline void checkShape(
const Var & var)
1902 matdims << (Rows!=Eigen::Dynamic ? Rows : -1)
1903 << (Cols!=Eigen::Dynamic ? Cols : -1);
1907 matdims[0] != -1 && matdims[0] == matdims[1]);
1910 if (vdims.
size() > 2) {
1916 err.setVarName(var.
varName());
1921 static inline RetType decodeValue(
const Var & var)
1926 if (vdims.size() < 2) {
1930 if (vdims.size() > 2 &&
1933 "When collapsing several dimensions into Eigen columns, you must use " 1934 "column-major ordering (sorry).");
1937 const int cols = vdims[vdims.size()-1];
1939 const int rows =
getNumEl(vdims.data(), vdims.data()+vdims.size()-1);
1941 MatrixType matrix(rows, cols);
1945 tomo_internal::init_eigen_matrix<MatrixType, Type>(
1968 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols,
typename Alloc>
1969 class TOMOGRAPHER_EXPORT
VarValueDecoder<
std::vector<Eigen::Matrix<Scalar,Rows,Cols,Options,MaxRows,MaxCols>, Alloc> >
1978 static inline void checkShape(
const Var & var)
1981 matdims << (Rows!=Eigen::Dynamic ? Rows : -1)
1982 << (Cols!=Eigen::Dynamic ? Cols : -1)
1990 if (vdims.
size() < 1) {
1993 if (vdims.
size() == 1) {
1995 }
else if (vdims.
size() == 2) {
2006 err.setVarName(var.
varName());
2012 static inline RetType decodeValue(
const Var & var)
2020 if (vardims.size() == 1) {
2021 innerdims << vardims[0] << 1;
2022 }
else if (vardims.size() == 2) {
2023 innerdims = vardims;
2026 innerdims << vardims[0] << vardims[1];
2030 RetType
value(outerdim);
2039 for (j = 0; j < outerdim; ++j) {
2040 tomo_internal::init_eigen_matrix<MatrixType,Type>(
2077 template<
typename EigenType_>
2081 typedef EigenType_ EigenType;
2099 : tolerance(tolerance_) { }
2123 Tomographer::MathTools::forcePosVecKeepSum<RealVectorType>(d, p.
tolerance);
2125 mat = U * d.asDiagonal() * U.adjoint();
2126 sqrt = U * d.cwiseSqrt().asDiagonal() * U.adjoint();
2130 template<
typename EigenType_>
2134 typedef EigenType_ EigenType;
2141 static inline void checkShape(
const Var & var,
const Params & = Params())
2144 EigenVarDecoder::checkShape(var);
2147 if (d.
size() != 2 || d[0] != d[1]) {
2152 static inline RetType decodeValue(
const Var & var,
const Params & p = Params())
Utilities for formatting strings.
Utility to iterate over a multidim array by increasing linear index.
File(File &&other)
Move constructor.
DimList()
Initializes an empty dimension list.
DimList dims() const
Specific dimensions of this numeric array or tensor.
const std::string & varName() const
The variable name.
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.
const RealVectorType & eigenvalues() const
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.
const std::vector< int > & index() const
Return a reference to *this.
DimList(VectorType &&dims)
Initialize a dimension list with another list of dimensions.
int numel() const
Get the total number of elements in an array of these dimensions.
A MATLAB file open for reading data.
EigenType mat
The matrix itself.
int ndims() const
Get the number of dimensions in this array.
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.
VarValueDecoder< T >::RetType value() const
Read this variable data as native C++ object.
A list of indices with an API for linear or subindices access.
Base Exception class for errors within our MAT routines.
Specializable template which takes care of decoding values.
IndexList & operator<<(int ind)
Append index to list.
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.
Tools for dealing with positive semidefinite matrices.
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)
EigenType sqrt
The matrix square root of the read matrix.
Params(RealScalarType tolerance_=Eigen::NumTraits< RealScalarType >::dummy_precision())
Constructor, specify the tolerance.
const RealScalarType tolerance
The tolerance.
VarValueDecoder< T >::RetType value(const Var &var, const typename VarValueDecoder< T >::Params ¶ms)
Access the value of the given variable, as a C++ type.
Ask for this type in Var::value<typename T>() to get an std::vector of the data.
Parameters to read the positive semidefinite matrix.
int ndims() const
Number of dimensions of this object.
Some C++ utilities, with a tad of C++11 tricks.
T RetType
See VarValueDecoder::RetType.
Read a positive semidefinite matrix along with its matrix square root.
internal::plain_col_type< MatrixType, RealScalar >::type RealVectorType
static RetType decodeValue(const Var &var)
Decode the variable var into the C++ type T.
static void checkShape(const Var &var)
Check that the type and shape of the var are compatible with T.
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.
Var & operator=(const Var ©)
Var objects are copyable. Beware though that the data is shared.
const std::vector< int > & dims() const
Get the underlying dimensions given to the constructor.
VarShape(bool is_complex_, DimListType &&dims_, bool is_square_)
Construct a VarShape object from given characteristics.
bool isComplex() const
Whether this variable is complex or real.
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...
bool isSquareMatrix() const
Whether this is a square matrix.
const MatrixType & eigenvectors() const
::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.
const matvar_t * getMatvarPtr() const
Access the underlying C pointer to the MatIO structure. Use with care.
static void checkShape(const Var &var)
See VarValueDecoder::checkShape()
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.
static RetType decodeValue(const Var &var)
See VarValueDecoder::decodeValue()
const unsigned int RowMajorBit
T RetType
Type returned by decodeValue()
#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.
bool matchesWanted(const DimList &wanted) const
Test whether our dimensions match the given required list of dimensions.
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.
#define tomographer_assert(...)
Assertion test macro.
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.
Eigen::SelfAdjointEigenSolver< EigenType > eig
The readily-initialized eigenvalue decomposition of the matrix read from the MAT file.
bool hasData() const
Whether data for this Var object has been loaded.
int numel() const
The total number of elements in this array or tensor.