diff options
author | Gael Guennebaud <g.gael@free.fr> | 2014-02-18 17:43:16 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2014-02-18 17:43:16 +0100 |
commit | 5b78780deffd4a5728cfc6ae5371f56e038e2ac0 (patch) | |
tree | 8a09f0007ed1a65a0ecd170e575aa3500c918f1b /Eigen/src/Core/TriangularMatrix.h | |
parent | 8169c6ac59ce78a7340ebae40f8eabe9df1c8f62 (diff) |
Add evaluator shortcut for triangular ?= product
Diffstat (limited to 'Eigen/src/Core/TriangularMatrix.h')
-rw-r--r-- | Eigen/src/Core/TriangularMatrix.h | 70 |
1 files changed, 67 insertions, 3 deletions
diff --git a/Eigen/src/Core/TriangularMatrix.h b/Eigen/src/Core/TriangularMatrix.h index c5f137ab8..ffa2faeaa 100644 --- a/Eigen/src/Core/TriangularMatrix.h +++ b/Eigen/src/Core/TriangularMatrix.h @@ -233,6 +233,24 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView EIGEN_DEVICE_FUNC inline Index innerStride() const { return m_matrix.innerStride(); } +#ifdef EIGEN_TEST_EVALUATORS + + /** \sa MatrixBase::operator+=() */ + template<typename Other> + EIGEN_DEVICE_FUNC + TriangularView& operator+=(const DenseBase<Other>& other) { + internal::call_assignment_no_alias(*this, other.derived(), internal::add_assign_op<Scalar>()); + return *this; + } + /** \sa MatrixBase::operator-=() */ + template<typename Other> + EIGEN_DEVICE_FUNC + TriangularView& operator-=(const DenseBase<Other>& other) { + internal::call_assignment_no_alias(*this, other.derived(), internal::sub_assign_op<Scalar>()); + return *this; + } + +#else /** \sa MatrixBase::operator+=() */ template<typename Other> EIGEN_DEVICE_FUNC @@ -241,6 +259,7 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView template<typename Other> EIGEN_DEVICE_FUNC TriangularView& operator-=(const DenseBase<Other>& other) { return *this = m_matrix - other.derived(); } +#endif /** \sa MatrixBase::operator*=() */ EIGEN_DEVICE_FUNC TriangularView& operator*=(const typename internal::traits<MatrixType>::Scalar& other) { return *this = m_matrix * other; } @@ -527,12 +546,18 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView #endif // EIGEN_TEST_EVALUATORS - protected: +#ifdef EIGEN_TEST_EVALUATORS + template<typename ProductType> + EIGEN_DEVICE_FUNC + EIGEN_STRONG_INLINE TriangularView& _assignProduct(const ProductType& prod, const Scalar& alpha); + protected: +#else + protected: template<typename ProductDerived, typename Lhs, typename Rhs> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TriangularView& assignProduct(const ProductBase<ProductDerived, Lhs,Rhs>& prod, const Scalar& alpha); - +#endif MatrixTypeNested m_matrix; }; @@ -720,7 +745,7 @@ template<typename OtherDerived> inline TriangularView<MatrixType, Mode>& TriangularView<MatrixType, Mode>::operator=(const MatrixBase<OtherDerived>& other) { - internal::call_assignment(*this, other.template triangularView<Mode>(), internal::assign_op<Scalar>()); + internal::call_assignment_no_alias(*this, other.derived(), internal::assign_op<Scalar>()); return *this; } @@ -1253,6 +1278,45 @@ void TriangularBase<Derived>::evalToLazy(MatrixBase<DenseDerived> &other) const other.derived().resize(this->rows(), this->cols()); internal::call_triangular_assignment_loop<Derived::Mode,(Derived::Mode&SelfAdjoint)==0 /* SetOpposite */>(other.derived(), derived().nestedExpression()); } + +namespace internal { + +// Triangular = Product +template< typename DstXprType, typename Lhs, typename Rhs, typename Scalar> +struct Assignment<DstXprType, Product<Lhs,Rhs,DefaultProduct>, internal::assign_op<Scalar>, Dense2Triangular, Scalar> +{ + typedef Product<Lhs,Rhs,DefaultProduct> SrcXprType; + static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar> &) + { + dst.setZero(); + dst._assignProduct(src, 1); + } +}; + +// Triangular += Product +template< typename DstXprType, typename Lhs, typename Rhs, typename Scalar> +struct Assignment<DstXprType, Product<Lhs,Rhs,DefaultProduct>, internal::add_assign_op<Scalar>, Dense2Triangular, Scalar> +{ + typedef Product<Lhs,Rhs,DefaultProduct> SrcXprType; + static void run(DstXprType &dst, const SrcXprType &src, const internal::add_assign_op<Scalar> &) + { + dst._assignProduct(src, 1); + } +}; + +// Triangular -= Product +template< typename DstXprType, typename Lhs, typename Rhs, typename Scalar> +struct Assignment<DstXprType, Product<Lhs,Rhs,DefaultProduct>, internal::sub_assign_op<Scalar>, Dense2Triangular, Scalar> +{ + typedef Product<Lhs,Rhs,DefaultProduct> SrcXprType; + static void run(DstXprType &dst, const SrcXprType &src, const internal::sub_assign_op<Scalar> &) + { + dst._assignProduct(src, -1); + } +}; + + +} // end namespace internal #endif #endif // EIGEN_ENABLE_EVALUATORS |