16 enum { DontAlignCols = 1 };
17 enum { StreamPrecision = -1,
21 template<
typename Derived>
22 std::ostream & print_matrix(std::ostream & s,
const Derived& _m,
const IOFormat& fmt);
53 IOFormat(
int _precision = StreamPrecision,
int _flags = 0,
54 const std::string& _coeffSeparator =
" ",
55 const std::string& _rowSeparator =
"\n",
const std::string& _rowPrefix=
"",
const std::string& _rowSuffix=
"",
56 const std::string& _matPrefix=
"",
const std::string& _matSuffix=
"")
57 : matPrefix(_matPrefix), matSuffix(_matSuffix), rowPrefix(_rowPrefix), rowSuffix(_rowSuffix), rowSeparator(_rowSeparator),
58 rowSpacer(
""), coeffSeparator(_coeffSeparator), precision(_precision), flags(_flags)
62 if((flags & DontAlignCols))
64 int i = int(matSuffix.length())-1;
65 while (i>=0 && matSuffix[i]!=
'\n')
71 std::string matPrefix, matSuffix;
72 std::string rowPrefix, rowSuffix, rowSeparator, rowSpacer;
73 std::string coeffSeparator;
93 template<
typename ExpressionType>
99 : m_matrix(matrix), m_format(format)
102 friend std::ostream & operator << (std::ostream & s,
const WithFormat& wf)
104 return internal::print_matrix(s, wf.m_matrix.eval(), wf.m_format);
108 const typename ExpressionType::Nested m_matrix;
119 template<
typename Derived>
131 template<
typename Scalar>
134 static inline int run()
142 template<
typename Derived>
143 std::ostream & print_matrix(std::ostream & s,
const Derived& _m,
const IOFormat& fmt)
147 s << fmt.matPrefix << fmt.matSuffix;
151 typename Derived::Nested m = _m;
152 typedef typename Derived::Scalar Scalar;
156 std::streamsize explicit_precision;
157 if(fmt.precision == StreamPrecision)
159 explicit_precision = 0;
161 else if(fmt.precision == FullPrecision)
165 explicit_precision = 0;
174 explicit_precision = fmt.precision;
177 std::streamsize old_precision = 0;
178 if(explicit_precision) old_precision = s.precision(explicit_precision);
180 bool align_cols = !(fmt.flags & DontAlignCols);
184 for(
Index j = 0; j < m.cols(); ++j)
185 for(
Index i = 0; i < m.rows(); ++i)
187 std::stringstream sstr;
189 sstr << m.coeff(i,j);
190 width = std::max<Index>(width,
Index(sstr.str().length()));
194 for(
Index i = 0; i < m.rows(); ++i)
199 if(width) s.width(width);
201 for(
Index j = 1; j < m.cols(); ++j)
203 s << fmt.coeffSeparator;
204 if (width) s.width(width);
208 if( i < m.rows() - 1)
209 s << fmt.rowSeparator;
212 if(explicit_precision) s.precision(old_precision);
229 template<
typename Derived>
230 std::ostream &
operator <<
234 return internal::print_matrix(s, m.eval(), EIGEN_DEFAULT_IO_FORMAT);
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
Holds information about the various numeric (i.e.
Definition: NumTraits.h:150
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Definition: BandTriangularSolver.h:13
const WithFormat< Derived > format(const IOFormat &fmt) const
Definition: IO.h:121