32 #include <boost/scope_exit.hpp>
60 template <
class Type,
class Row,
class Col,
class AT>
class Matrix {
73 typedef AT value_type;
91 #ifndef FMATVEC_NO_BOUNDS_CHECK
106 #ifndef FMATVEC_NO_BOUNDS_CHECK
118 const AT& e(
int i,
int j)
const;
136 operator std::vector<std::vector<AT> >()
const;
141 template <
class Type,
class Row,
class Col,
class AT>
void Matrix<Type,Row,Col,AT>::deepCopy(
const Matrix<Type,Row,Col,AT> &A) {
142 for(
int i=0; i<rows(); i++)
143 for(
int j=0; j<cols(); j++)
154 template <
class Type,
class Row,
class Col,
class AT> std::ostream& operator<<(std::ostream &os, const Matrix<Type,Row,Col,AT> &A) {
155 os << toString(static_cast<std::vector<std::vector<AT>>>(A));
167 std::ios_base::iostate oldEx=is.exceptions();
168 std::ios_base::fmtflags oldFlags=is.flags();
169 BOOST_SCOPE_EXIT_TPL(&is, oldEx, oldFlags) {
170 is.exceptions(oldEx);
172 } BOOST_SCOPE_EXIT_END
173 is.exceptions(std::ios::failbit | std::ios::badbit);
174 is.flags(std::ios_base::skipws);
177 while((c=is.peek())==
' ' || c==
'\n') is.get();
186 std::vector<std::vector<AT>> m(1);
191 while((c=is.peek())==
' ') is.get();
192 if (c==
',' ) { is.get(); }
193 else if(c==
';' || c==
'\n') { is.get(); m.resize(++r + 1); }
194 else if(c==
']' ) { is.get();
break; }
207 std::ofstream os(str);
208 for (
int i=0; i < A.
rows(); ++i) {
209 for (
int j=0; j < A.
cols(); ++j)
210 os << std::setw(14) << A.e(i,j);
212 if (i != A.
rows() - 1)
218 template <
class Type,
class Row,
class Col,
class AT>
220 std::vector<std::vector<AT> > ret(rows());
221 for(
int r=0; r<rows(); r++) {
222 ret[r].resize(cols());
223 for(
int c=0; c<cols(); c++)
232 template <
class Row,
class AT>
class Vector {
235 template <
class Col,
class AT>
class RowVector {
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:41
AT & operator()(int i, int j)
Standard constructor.
Definition: matrix.h:90
void dump(const char *str, const Matrix< Type, Row, Col, AT > &A)
Matrix dump.
Definition: matrix.h:206
int rows() const
Number of rows.
int cols() const
Number of columns.
std::istream & operator>>(std::istream &is, Matrix< Type, Row, Col, AT > &A)
Matrix input.
Definition: matrix.h:166
const AT & operator()(int i, int j) const
Element operator.
Definition: matrix.h:105