aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/IO.h
diff options
context:
space:
mode:
authorGravatar Joel Holdsworth <joel.holdsworth@vcatechnology.com>2019-11-05 12:17:58 +0000
committerGravatar Joel Holdsworth <joel.holdsworth@vcatechnology.com>2019-12-11 18:22:57 +0000
commit3c0ef9f394f7117d58bfd55ee283697337146bc2 (patch)
treee10bd41776977938a4b47689512e2174a16bb409 /Eigen/src/Core/IO.h
parente87af0ed37d2e7df41499fd64e58523d2270d075 (diff)
IO: Fixed printing of char and unsigned char matrices
Diffstat (limited to 'Eigen/src/Core/IO.h')
-rw-r--r--Eigen/src/Core/IO.h25
1 files changed, 22 insertions, 3 deletions
diff --git a/Eigen/src/Core/IO.h b/Eigen/src/Core/IO.h
index 063511f24..e81c31521 100644
--- a/Eigen/src/Core/IO.h
+++ b/Eigen/src/Core/IO.h
@@ -130,6 +130,9 @@ struct significant_decimals_impl
template<typename Derived>
std::ostream & print_matrix(std::ostream & s, const Derived& _m, const IOFormat& fmt)
{
+ using internal::is_same;
+ using internal::conditional;
+
if(_m.size() == 0)
{
s << fmt.matPrefix << fmt.matSuffix;
@@ -138,6 +141,22 @@ std::ostream & print_matrix(std::ostream & s, const Derived& _m, const IOFormat&
typename Derived::Nested m = _m;
typedef typename Derived::Scalar Scalar;
+ typedef typename
+ conditional<
+ is_same<Scalar, char>::value ||
+ is_same<Scalar, unsigned char>::value ||
+ is_same<Scalar, numext::int8_t>::value ||
+ is_same<Scalar, numext::uint8_t>::value,
+ int,
+ typename conditional<
+ is_same<Scalar, std::complex<char> >::value ||
+ is_same<Scalar, std::complex<unsigned char> >::value ||
+ is_same<Scalar, std::complex<numext::int8_t> >::value ||
+ is_same<Scalar, std::complex<numext::uint8_t> >::value,
+ std::complex<int>,
+ const Scalar&
+ >::type
+ >::type PrintType;
Index width = 0;
@@ -174,7 +193,7 @@ std::ostream & print_matrix(std::ostream & s, const Derived& _m, const IOFormat&
{
std::stringstream sstr;
sstr.copyfmt(s);
- sstr << m.coeff(i,j);
+ sstr << static_cast<PrintType>(m.coeff(i,j));
width = std::max<Index>(width, Index(sstr.str().length()));
}
}
@@ -190,7 +209,7 @@ std::ostream & print_matrix(std::ostream & s, const Derived& _m, const IOFormat&
s.fill(fmt.fill);
s.width(width);
}
- s << m.coeff(i, 0);
+ s << static_cast<PrintType>(m.coeff(i, 0));
for(Index j = 1; j < m.cols(); ++j)
{
s << fmt.coeffSeparator;
@@ -198,7 +217,7 @@ std::ostream & print_matrix(std::ostream & s, const Derived& _m, const IOFormat&
s.fill(fmt.fill);
s.width(width);
}
- s << m.coeff(i, j);
+ s << static_cast<PrintType>(m.coeff(i, j));
}
s << fmt.rowSuffix;
if( i < m.rows() - 1)