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;
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) {
493 this->at(k) = linearindex % p_dims[k];
494 linearindex /= p_dims[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) {
509 this->at(k) = linearindex % p_dims[k];
510 linearindex /= p_dims[k];
520 TOMOGRAPHER_ENABLED_IF(IsRowMajor)
521 int linearIndex()
const 524 for (
int k = 0; k < (int)p_dims.size(); ++k) {
525 linindex *= p_dims[k];
526 linindex += this->at(k);
534 TOMOGRAPHER_ENABLED_IF(!IsRowMajor)
535 int linearIndex()
const 538 for (
int k = (
int)p_dims.size()-1; k >= 0; --k) {
539 linindex *= p_dims[k];
540 linindex += this->at(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 = p_dims.
size() - 1; k >= 0; --k) {
676 if (p_index[k] < p_dims[k]) {
685 return ++p_linearIndex;
688 TOMOGRAPHER_ENABLED_IF(!IsRowMajor)
691 for (
int k = 0; k < (int)p_dims.
size(); ++k) {
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 >
885 template<
typename T, TOMOGRAPHER_ENABLED_IF_TMPL( tomo_
internal::has_params_member<VarValueDecoder<T> >::value )>
915 VarData() : refcount(0), p_matvar(NULL) { }
922 Var(matvar_t * varinfo)
924 if (varinfo == NULL) {
927 p_vardata =
new VarData;
928 p_vardata->refcount++;
929 p_vardata->p_matvar = varinfo;
946 p_vardata =
new VarData;
947 p_vardata->refcount++;
949 p_vardata->p_matvar = Mat_VarRead(matf.
getMatPtr(), varname.
c_str());
951 p_vardata->p_matvar = Mat_VarReadInfo(matf.
getMatPtr(), varname.
c_str());
953 if (p_vardata->p_matvar == NULL) {
958 p_vardata->p_varname = varname;
964 p_vardata = copy.p_vardata;
965 p_vardata->refcount++;
972 p_vardata = other.p_vardata;
973 other.p_vardata = NULL;
977 if (p_vardata != NULL) {
978 p_vardata->refcount--;
979 if (!p_vardata->refcount) {
980 Mat_VarFree(p_vardata->p_matvar);
1003 tomographer_assert(p_vardata != NULL);
1004 return p_vardata->p_varname;
1013 tomographer_assert(p_vardata != NULL);
1014 return p_vardata->p_matvar->rank;
1022 tomographer_assert(p_vardata != NULL);
1023 return DimList(&p_vardata->p_matvar->dims[0],
1024 &p_vardata->p_matvar->dims[p_vardata->p_matvar->rank]);
1032 tomographer_assert(p_vardata != NULL);
1033 return dims().numel();
1045 tomographer_assert(p_vardata != NULL);
1046 return p_vardata->p_matvar->isComplex;
1054 tomographer_assert(p_vardata != NULL);
1055 return p_vardata->p_matvar->rank == 2 && p_vardata->p_matvar->dims[0] == p_vardata->p_matvar->dims[1];
1065 tomographer_assert(p_vardata != NULL);
1066 return (p_vardata->p_matvar->data != NULL);
1108 template<
typename T>
1111 return Tomographer::MAT::value<T>(*this);
1123 template<
typename T, TOMOGRAPHER_ENABLED_IF_TMPL( tomo_
internal::has_params_member<VarValueDecoder<T> >::value )>
1126 return Tomographer::MAT::value<T>(*
this, params);
1136 tomographer_assert(p_vardata != NULL);
1137 return p_vardata->p_matvar;
1146 p_vardata = other.p_vardata;
1147 other.p_vardata = NULL;
1153 p_vardata = copy.p_vardata;
1154 p_vardata->refcount++;
1165 return Var(*
this, varname, load_data);
1172 Mat_Rewind(p_matfp);
1173 matvar_t * p = NULL;
1174 while ( (p = Mat_VarReadNextInfo(p_matfp)) != NULL ) {
1182 template<
typename T,
typename Enabled>
1187 +
typeid(T).name() +
" to decode variable " + var.
varName());
1213 template<>
struct MatType<MAT_T_DOUBLE> {
typedef double Type; };
1215 template<>
struct MatType<MAT_T_SINGLE> {
typedef float Type; };
1217 template<>
struct MatType<MAT_T_INT64> {
typedef int64_t Type; };
1219 template<>
struct MatType<MAT_T_INT32> {
typedef int32_t Type; };
1221 template<>
struct MatType<MAT_T_INT16> {
typedef int16_t Type; };
1223 template<>
struct MatType<MAT_T_INT8> {
typedef int8_t Type; };
1225 template<>
struct MatType<MAT_T_UINT64> {
typedef uint64_t Type; };
1227 template<>
struct MatType<MAT_T_UINT32> {
typedef uint32_t Type; };
1229 template<>
struct MatType<MAT_T_UINT16> {
typedef uint16_t Type; };
1231 template<>
struct MatType<MAT_T_UINT8> {
typedef uint8_t Type; };
1240 #define MAT_SWITCH_REAL_TYPE(typ, ...) \ 1241 do { switch (typ) { \ 1242 case MAT_T_DOUBLE: { typedef typename MatType<MAT_T_DOUBLE>::Type Type; { __VA_ARGS__; } break; } \ 1243 case MAT_T_SINGLE: { typedef typename MatType<MAT_T_SINGLE>::Type Type; { __VA_ARGS__; } break; } \ 1244 case MAT_T_INT64: { typedef typename MatType<MAT_T_INT64>::Type Type; { __VA_ARGS__; } break; } \ 1245 case MAT_T_INT32: { typedef typename MatType<MAT_T_INT32>::Type Type; { __VA_ARGS__; } break; } \ 1246 case MAT_T_INT16: { typedef typename MatType<MAT_T_INT16>::Type Type; { __VA_ARGS__; } break; } \ 1247 case MAT_T_INT8: { typedef typename MatType<MAT_T_INT8>::Type Type; { __VA_ARGS__; } break; } \ 1248 case MAT_T_UINT64: { typedef typename MatType<MAT_T_UINT64>::Type Type; { __VA_ARGS__; } break; } \ 1249 case MAT_T_UINT32: { typedef typename MatType<MAT_T_UINT32>::Type Type; { __VA_ARGS__; } break; } \ 1250 case MAT_T_UINT16: { typedef typename MatType<MAT_T_UINT16>::Type Type; { __VA_ARGS__; } break; } \ 1251 case MAT_T_UINT8: { typedef typename MatType<MAT_T_UINT8>::Type Type; { __VA_ARGS__; } break; } \ 1253 throw VarMatTypeError( streamstr("Uknown/unsupported encoded type from matio: " \ 1264 #define MAT_SWITCH_COMPLEX_TYPE(typ, ...) \ 1265 do { switch (typ) { \ 1266 case MAT_T_DOUBLE: { typedef std::complex<typename MatType<MAT_T_DOUBLE>::Type> Type; { __VA_ARGS__; } break; } \ 1267 case MAT_T_SINGLE: { typedef std::complex<typename MatType<MAT_T_SINGLE>::Type> Type; { __VA_ARGS__; } break; } \ 1269 throw VarMatTypeError( streamstr("Uknown/unsupported encoded type from matio: " \ 1282 #define MAT_SWITCH_TYPE(matvar_ptr, ...) \ 1284 if (!(matvar_ptr)->isComplex) { \ 1285 switch ((matvar_ptr)->data_type) { \ 1286 case MAT_T_DOUBLE: { typedef typename MatType<MAT_T_DOUBLE>::Type Type; { __VA_ARGS__; } break; } \ 1287 case MAT_T_SINGLE: { typedef typename MatType<MAT_T_SINGLE>::Type Type; { __VA_ARGS__; } break; } \ 1288 case MAT_T_INT64: { typedef typename MatType<MAT_T_INT64>::Type Type; { __VA_ARGS__; } break; } \ 1289 case MAT_T_INT32: { typedef typename MatType<MAT_T_INT32>::Type Type; { __VA_ARGS__; } break; } \ 1290 case MAT_T_INT16: { typedef typename MatType<MAT_T_INT16>::Type Type; { __VA_ARGS__; } break; } \ 1291 case MAT_T_INT8: { typedef typename MatType<MAT_T_INT8>::Type Type; { __VA_ARGS__; } break; } \ 1292 case MAT_T_UINT64: { typedef typename MatType<MAT_T_UINT64>::Type Type; { __VA_ARGS__; } break; } \ 1293 case MAT_T_UINT32: { typedef typename MatType<MAT_T_UINT32>::Type Type; { __VA_ARGS__; } break; } \ 1294 case MAT_T_UINT16: { typedef typename MatType<MAT_T_UINT16>::Type Type; { __VA_ARGS__; } break; } \ 1295 case MAT_T_UINT8: { typedef typename MatType<MAT_T_UINT8>::Type Type; { __VA_ARGS__; } break; } \ 1297 throw VarMatTypeError( streamstr("Uknown/unsupported encoded type from matio: " \ 1298 << (matvar_ptr)->data_type) ); \ 1301 switch ((matvar_ptr)->data_type) { \ 1302 case MAT_T_DOUBLE: { typedef std::complex<typename MatType<MAT_T_DOUBLE>::Type> Type; { __VA_ARGS__; } break; } \ 1303 case MAT_T_SINGLE: { typedef std::complex<typename MatType<MAT_T_SINGLE>::Type> Type; { __VA_ARGS__; } break; } \ 1305 throw VarMatTypeError( streamstr("Uknown/unsupported encoded type from matio: " \ 1306 << (matvar_ptr)->data_type) ); \ 1323 template<
typename T>
1325 #ifdef TOMOGRAPHER_PARSED_BY_DOXYGEN
1328 typename
std::enable_if<(std::numeric_limits<T>::is_specialized ||
1329 Tools::isComplex<T>::value)>::type
1342 streamstr(
"Can't store complex matrix in type " <<
typeid(T).name()));
1344 if (var.
numel() != 1) {
1346 streamstr(
"Expected scalar but got matrix"));
1356 return get_value<Type>(matvar_ptr, var.
varName());
1359 tomographer_assert(
false);
1363 template<
typename MATType,
1366 static inline RetType get_value(
const matvar_t * matvar_ptr,
const std::string & )
1368 return RetType( ((
const MATType *) matvar_ptr->data)[0] );
1371 template<
typename MATType,
1374 static inline RetType get_value(
const matvar_t * matvar_ptr,
const std::string & )
1376 return RetType(
typename Tools::ComplexRealScalar<RetType>::type(((
const MATType *) matvar_ptr->data)[0]),
1380 template<
typename MATType,
1383 static inline RetType get_value(
const matvar_t * ,
const std::string & varname)
1385 throw VarTypeError(varname,
"Expected real scalar, got complex type");
1388 template<
typename MATType,
1391 static inline RetType get_value(
const matvar_t * matvar_ptr,
const std::string & )
1393 typedef typename Tools::ComplexRealScalar<MATType>::type MATRealType;
1394 const mat_complex_split_t * cdata = (mat_complex_split_t*) matvar_ptr->data;
1396 return RetType(
typename Tools::ComplexRealScalar<RetType>::type( ((
const MATRealType *) cdata->Re)[0] ),
1397 typename Tools::ComplexRealScalar<RetType>::type( ((
const MATRealType *) cdata->Im)[0] ) );
1407 namespace tomo_internal {
1410 template<
typename OutType,
typename MatInnerT>
1411 class VarMatDataAccessor
1415 typedef typename Tools::ComplexRealScalar<MatInnerT>::type MatRealInnerT;
1417 const MatInnerT * p_r_ptr;
1418 const MatRealInnerT * p_cre_ptr;
1419 const MatRealInnerT * p_cim_ptr;
1422 VarMatDataAccessor(
const Var & var)
1426 tomographer_assert(matvar_ptr->data != NULL);
1427 if (!matvar_ptr->isComplex) {
1429 p_r_ptr = (
const MatInnerT*) matvar_ptr->data;
1433 const mat_complex_split_t * cdata = (mat_complex_split_t*) matvar_ptr->data;
1435 p_cre_ptr = (
const MatRealInnerT*) cdata->Re;
1436 p_cim_ptr = (
const MatRealInnerT*) cdata->Im;
1437 tomographer_assert(p_cre_ptr != NULL);
1438 tomographer_assert(p_cim_ptr != NULL);
1442 virtual ~VarMatDataAccessor() { }
1444 template<
typename IndexListType,
1445 typename OutType__ = OutType,
typename MatInnerT__ = MatInnerT,
1448 inline OutType
value(IndexListType&& index)
const 1450 tomographer_assert(p_r_ptr != NULL);
1453 std::size_t lin = linear_index(std::forward<IndexListType>(index));
1454 return (OutType)p_r_ptr[lin];
1457 template<
typename IndexListType,
1458 typename OutType__ = OutType,
typename MatInnerT__ = MatInnerT,
1461 inline OutType
value(IndexListType&& )
const 1466 template<
typename IndexListType,
1467 typename OutType__ = OutType,
typename MatInnerT__ = MatInnerT,
1470 inline OutType
value(IndexListType&& index)
const 1472 tomographer_assert(p_r_ptr != NULL);
1475 std::size_t lin = linear_index(std::forward<IndexListType>(index));
1479 template<
typename IndexListType,
1480 typename OutType__ = OutType,
typename MatInnerT__ = MatInnerT,
1483 inline OutType
value(IndexListType&& index)
const 1485 tomographer_assert(p_cre_ptr != NULL);
1486 tomographer_assert(p_cim_ptr != NULL);
1489 std::size_t lin = linear_index(std::forward<IndexListType>(index));
1495 template<
typename IndexListType>
1496 std::size_t linear_index(IndexListType && index)
const 1503 return ind_cmaj.linearIndex();
1599 template<
typename DimListType>
1600 VarShape(
bool is_complex_, DimListType&& dims_,
bool is_square_)
1601 : is_complex(is_complex_), dims(
std::forward<DimListType>(dims_)), is_square(is_square_)
1603 _check_consistency();
1612 : is_complex(var.isComplex()), dims(var.dims()), is_square(var.isSquareMatrix())
1618 void _check_consistency()
1621 tomographer_assert(dims.
size() == 0 || (dims.
size() == 2 && (dims[0] == -1 || dims[1] == -1 || dims[0] == dims[1])));
1634 inline void checkShape(
const VarShape & shape);
1648 err.setVarName(var.
varName());
1660 }
else if (varshape.
dims.
size() == 2) {
1665 }
else if (varshape.
dims.
size() > 0) {
1666 str << varshape.
dims.
size() <<
"-D array";
1668 str <<
" with first two dimensions square";
1675 str <<
" of shape " << varshape.
dims;
1685 (mvardims.
size() != dims.size() && dims.size() > 0) ||
1686 (is_square && (mvardims.
size() != 2 || mvardims[0] != mvardims[1])) ||
1691 errstr <<
"Expected " 1717 template<
typename T_,
bool IsRowMajor_ = false>
1720 static constexpr
bool IsRowMajor = IsRowMajor_;
1724 template<
typename T,
bool IsRowMajor>
1730 static inline void checkShape(
const Var & var)
1734 std::string(
"can't store complex matrix in type ")
1735 +
typeid(T).name());
1746 tomo_internal::VarMatDataAccessor<T, Type> acc(var);
1750 val[il.linearIndex()] = acc.value(il);
1756 tomographer_assert(
false);
1771 namespace tomo_internal {
1776 tomographer_assert(vdims.
size() >= 1);
1778 if (vdims.
size() == 1) {
1779 vdimsreshaped = vdims;
1781 }
else if (vdims.
size() == 2) {
1782 vdimsreshaped = vdims;
1783 }
else if (vdims.
size() > 2) {
1786 tomographer_assert(vdimsreshaped[0] != -1 && vdimsreshaped[1] != -1);
1787 return vdimsreshaped;
1790 template<
typename MatrixType,
typename MatType,
1793 void init_eigen_matrix(MatrixType & matrix,
const DimList & vdims,
1796 typedef typename MatrixType::Scalar Scalar;
1803 const mat_complex_split_t * cdata = (mat_complex_split_t*) matvar_ptr->data;
1805 DimList vdimsreshaped = dims_stackedcols(vdims);
1809 (
const MatRealType *) cdata->Re + data_offset, vdimsreshaped[0], vdimsreshaped[1]
1810 ).template cast<std::complex<RealScalar> >()
1813 (
const MatRealType *) cdata->Im + data_offset, vdimsreshaped[0], vdimsreshaped[1]
1814 ).template cast<std::complex<RealScalar> >()
1818 template<
typename MatrixType,
typename MatRealType,
1821 void init_eigen_matrix(MatrixType & ,
const DimList & ,
1827 template<
typename MatrixType,
typename MatRealType,
1829 void init_eigen_matrix(MatrixType & matrix,
const DimList & vdims,
1832 typedef typename MatrixType::Scalar Scalar;
1836 DimList vdimsreshaped = dims_stackedcols(vdims);
1840 (
const MatRealType *) matvar_ptr->data + data_offset, vdimsreshaped[0], vdimsreshaped[1]
1842 ).
template cast<Scalar>();
1857 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
1892 static inline void checkShape(
const Var & var)
1895 matdims << (Rows!=Eigen::Dynamic ? Rows : -1)
1896 << (Cols!=Eigen::Dynamic ? Cols : -1);
1900 matdims[0] != -1 && matdims[0] == matdims[1]);
1903 if (vdims.
size() > 2) {
1909 err.setVarName(var.
varName());
1914 static inline RetType decodeValue(
const Var & var)
1919 if (vdims.size() < 2) {
1923 if (vdims.size() > 2 &&
1926 "When collapsing several dimensions into Eigen columns, you must use " 1927 "column-major ordering (sorry).");
1930 const int cols = vdims[vdims.size()-1];
1932 const int rows =
getNumEl(vdims.data(), vdims.data()+vdims.size()-1);
1934 MatrixType matrix(rows, cols);
1938 tomo_internal::init_eigen_matrix<MatrixType, Type>(
1961 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols,
typename Alloc>
1971 static inline void checkShape(
const Var & var)
1974 matdims << (Rows!=Eigen::Dynamic ? Rows : -1)
1975 << (Cols!=Eigen::Dynamic ? Cols : -1)
1983 if (vdims.
size() < 1) {
1986 if (vdims.
size() == 1) {
1988 }
else if (vdims.
size() == 2) {
1999 err.setVarName(var.
varName());
2005 static inline RetType decodeValue(
const Var & var)
2009 tomographer_assert(vardims.size() >= 1);
2013 if (vardims.size() == 1) {
2014 innerdims << vardims[0] << 1;
2015 }
else if (vardims.size() == 2) {
2016 innerdims = vardims;
2019 innerdims << vardims[0] << vardims[1];
2020 outerdim =
getNumEl(vardims.data()+2, vardims.data()+vardims.size());
2023 RetType
value(outerdim);
2032 for (j = 0; j < outerdim; ++j) {
2033 tomo_internal::init_eigen_matrix<MatrixType,Type>(
2070 template<
typename EigenType_>
2074 typedef EigenType_ EigenType;
2092 : tolerance(tolerance_) { }
2116 Tomographer::MathTools::forcePosVecKeepSum<RealVectorType>(d, p.
tolerance);
2118 mat = U * d.asDiagonal() * U.adjoint();
2119 sqrt = U * d.cwiseSqrt().asDiagonal() * U.adjoint();
2123 template<
typename EigenType_>
2127 typedef EigenType_ EigenType;
2134 static inline void checkShape(
const Var & var,
const Params & = Params())
2137 EigenVarDecoder::checkShape(var);
2140 if (d.
size() != 2 || d[0] != d[1]) {
2145 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.
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.