Print diagonal matrix

This commit is contained in:
Charles Schlosser 2023-02-10 18:07:29 +00:00 committed by Rasmus Munk Larsen
parent fba12e02b3
commit c999284bad
2 changed files with 12 additions and 0 deletions

View File

@ -72,6 +72,13 @@ class DiagonalBase : public EigenBase<Derived>
EIGEN_DEVICE_FUNC
inline DiagonalVectorType& diagonal() { return derived().diagonal(); }
/** \returns the value of the coefficient as if \c *this was a dense matrix. */
EIGEN_DEVICE_FUNC
inline Scalar coeff(Index row, Index col) const {
eigen_assert(row >= 0 && col >= 0 && row < rows() && col <= cols());
return row == col ? diagonal().coeff(row) : Scalar(0);
}
/** \returns the number of rows. */
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index rows() const { return diagonal().size(); }

View File

@ -253,6 +253,11 @@ std::ostream & operator <<
return internal::print_matrix(s, m.eval(), EIGEN_DEFAULT_IO_FORMAT);
}
template <typename Derived>
std::ostream& operator<<(std::ostream& s, const DiagonalBase<Derived>& m) {
return internal::print_matrix(s, m.derived(), EIGEN_DEFAULT_IO_FORMAT);
}
} // end namespace Eigen
#endif // EIGEN_IO_H