diff options
author | Gael Guennebaud <g.gael@free.fr> | 2010-05-12 18:11:05 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2010-05-12 18:11:05 +0200 |
commit | c55761e015a3dee80471faf6ca031ff5184536dc (patch) | |
tree | d6088a1c97eaa1146bc5aa00b623ae836ccb3faf /Eigen/src/Core/Product.h | |
parent | 82d898083f4783517c8af430c776105a7ac9f8f9 (diff) |
make inner product return a 1x1 matrix
Diffstat (limited to 'Eigen/src/Core/Product.h')
-rw-r--r-- | Eigen/src/Core/Product.h | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index 791fddda9..e4b9b4d69 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -163,36 +163,39 @@ struct ProductReturnType<Lhs,Rhs,LazyCoeffBasedProductMode> template<typename Lhs, typename Rhs> struct ei_traits<GeneralProduct<Lhs,Rhs,InnerProduct> > - : ei_traits<ProductBase<GeneralProduct<Lhs,Rhs,InnerProduct>, Lhs, Rhs> > + : ei_traits<Matrix<typename Lhs::Scalar,1,1> > {}; template<typename Lhs, typename Rhs> class GeneralProduct<Lhs, Rhs, InnerProduct> - : public ProductBase<GeneralProduct<Lhs,Rhs,InnerProduct>, Lhs, Rhs> + : ei_no_assignment_operator, + public MatrixBase<GeneralProduct<Lhs, Rhs, InnerProduct> > { public: - EIGEN_PRODUCT_PUBLIC_INTERFACE(GeneralProduct) + typedef MatrixBase<GeneralProduct> Base; + EIGEN_DENSE_PUBLIC_INTERFACE(GeneralProduct) - GeneralProduct(const Lhs& lhs, const Rhs& rhs) : Base(lhs,rhs) + EIGEN_DONT_INLINE GeneralProduct(const Lhs& lhs, const Rhs& rhs) { EIGEN_STATIC_ASSERT((ei_is_same_type<typename Lhs::RealScalar, typename Rhs::RealScalar>::ret), YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) - } - EIGEN_STRONG_INLINE Scalar value() const - { - return (m_lhs.transpose().cwiseProduct(m_rhs)).sum(); + m_value = (lhs.transpose().cwiseProduct(rhs)).sum(); } - template<typename Dest> void scaleAndAddTo(Dest& dst, Scalar alpha) const + int rows() const { return 1; } + int cols() const { return 1; } + + EIGEN_STRONG_INLINE Scalar value() const { - ei_assert(dst.rows()==1 && dst.cols()==1); - dst.coeffRef(0,0) += alpha * value(); + return m_value; } EIGEN_STRONG_INLINE Scalar coeff(int, int) const { return value(); } EIGEN_STRONG_INLINE Scalar coeff(int) const { return value(); } + protected: + Scalar m_value; }; /*********************************************************************** |