mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-31 01:03:38 +08:00
simplify inner product
This commit is contained in:
parent
bf09fe55ed
commit
2b6153d3ed
@ -56,7 +56,7 @@ template<typename Derived> class MapBase
|
||||
using Base::IsVectorAtCompileTime;
|
||||
using Base::Flags;
|
||||
using Base::IsRowMajor;
|
||||
|
||||
|
||||
using Base::CoeffReadCost;
|
||||
|
||||
// using Base::derived;
|
||||
@ -78,7 +78,7 @@ template<typename Derived> class MapBase
|
||||
using Base::outerStride;
|
||||
using Base::rowStride;
|
||||
using Base::colStride;
|
||||
|
||||
|
||||
|
||||
typedef typename Base::CoeffReturnType CoeffReturnType;
|
||||
|
||||
|
@ -169,33 +169,19 @@ struct ei_traits<GeneralProduct<Lhs,Rhs,InnerProduct> >
|
||||
template<typename Lhs, typename Rhs>
|
||||
class GeneralProduct<Lhs, Rhs, InnerProduct>
|
||||
: ei_no_assignment_operator,
|
||||
public MatrixBase<GeneralProduct<Lhs, Rhs, InnerProduct> >
|
||||
public Matrix<typename ei_scalar_product_traits<typename Lhs::Scalar, typename Rhs::Scalar>::ReturnType,1,1>
|
||||
{
|
||||
typedef Matrix<typename ei_scalar_product_traits<typename Lhs::Scalar, typename Rhs::Scalar>::ReturnType,1,1> Base;
|
||||
public:
|
||||
typedef MatrixBase<GeneralProduct> Base;
|
||||
EIGEN_DENSE_PUBLIC_INTERFACE(GeneralProduct)
|
||||
|
||||
EIGEN_DONT_INLINE GeneralProduct(const Lhs& lhs, const Rhs& rhs)
|
||||
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)
|
||||
|
||||
m_value = (lhs.transpose().cwiseProduct(rhs)).sum();
|
||||
Base::coeffRef(0,0) = (lhs.transpose().cwiseProduct(rhs)).sum();
|
||||
}
|
||||
|
||||
int rows() const { return 1; }
|
||||
int cols() const { return 1; }
|
||||
|
||||
EIGEN_STRONG_INLINE Scalar value() const
|
||||
{
|
||||
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;
|
||||
typename Base::Scalar value() const { return Base::coeff(0,0); }
|
||||
};
|
||||
|
||||
/***********************************************************************
|
||||
|
@ -29,7 +29,7 @@
|
||||
*
|
||||
*/
|
||||
template<typename Derived, typename _Lhs, typename _Rhs>
|
||||
struct ei_traits<ProductBase<Derived,_Lhs,_Rhs> > //: ei_traits<typename ei_cleantype<_Lhs>::type>
|
||||
struct ei_traits<ProductBase<Derived,_Lhs,_Rhs> >
|
||||
{
|
||||
typedef MatrixXpr XprKind;
|
||||
typedef typename ei_cleantype<_Lhs>::type Lhs;
|
||||
|
Loading…
x
Reference in New Issue
Block a user