From 8915d5bd2217d4ebbf8fe54ebd2dfbf3f0c420c4 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 1 Feb 2011 17:21:20 +0100 Subject: fix 168 : now TriangularView::solve returns by value making TriangularView::solveInPlace less important. Also fix the very outdated documentation of this function. --- Eigen/src/Core/SolveTriangular.h | 71 ++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 24 deletions(-) (limited to 'Eigen/src/Core/SolveTriangular.h') diff --git a/Eigen/src/Core/SolveTriangular.h b/Eigen/src/Core/SolveTriangular.h index d186b5a4b..b59cdbf85 100644 --- a/Eigen/src/Core/SolveTriangular.h +++ b/Eigen/src/Core/SolveTriangular.h @@ -173,8 +173,6 @@ struct triangular_solver_selector { ***************************************************************************/ /** "in-place" version of TriangularView::solve() where the result is written in \a other - * - * * * \warning The parameter is only marked 'const' to make the C++ compiler accept a temporary expression here. * This function will const_cast it, so constness isn't honored here. @@ -205,43 +203,68 @@ void TriangularView::solveInPlace(const MatrixBase T.transpose().solveInPlace(M.transpose()); - * \endcode - * * \sa TriangularView::solveInPlace() */ template -template -typename internal::plain_matrix_type_column_major::type -TriangularView::solve(const MatrixBase& rhs) const +template +const internal::triangular_solve_retval,Other> +TriangularView::solve(const MatrixBase& other) const { - typename internal::plain_matrix_type_column_major::type res(rhs); - solveInPlace(res); - return res; + return internal::triangular_solve_retval(*this, other.derived()); } +namespace internal { + + +template +struct traits > +{ + typedef typename internal::plain_matrix_type_column_major::type ReturnType; +}; + +template struct triangular_solve_retval + : public ReturnByValue > +{ + typedef typename remove_all::type RhsNestedCleaned; + typedef ReturnByValue Base; + typedef typename Base::Index Index; + + triangular_solve_retval(const TriangularType& tri, const Rhs& rhs) + : m_triangularMatrix(tri), m_rhs(rhs) + {} + + inline Index rows() const { return m_rhs.rows(); } + inline Index cols() const { return m_rhs.cols(); } + + template inline void evalTo(Dest& dst) const + { + if(!(is_same::value && extract_data(dst) == extract_data(m_rhs))) + dst = m_rhs; + m_triangularMatrix.template solveInPlace(dst); + } + + protected: + const TriangularType& m_triangularMatrix; + const typename Rhs::Nested m_rhs; +}; + +} // namespace internal + #endif // EIGEN_SOLVETRIANGULAR_H -- cgit v1.2.3