mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
added optimized matrix times diagonal matrix product via Diagonal flag shortcut.
This commit is contained in:
parent
310f7aa096
commit
fcf4457b78
@ -76,6 +76,14 @@ MatrixBase<Derived>::cwisePow(const Scalar& exponent) const
|
|||||||
(derived(), ei_scalar_pow_op<Scalar>(exponent));
|
(derived(), ei_scalar_pow_op<Scalar>(exponent));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** \returns an expression of the coefficient-wise reciprocal of *this. */
|
||||||
|
template<typename Derived>
|
||||||
|
inline const CwiseUnaryOp<ei_scalar_inverse_op<typename ei_traits<Derived>::Scalar>, Derived>
|
||||||
|
MatrixBase<Derived>::cwiseInverse() const
|
||||||
|
{
|
||||||
|
return derived();
|
||||||
|
}
|
||||||
|
|
||||||
// -- binary operators --
|
// -- binary operators --
|
||||||
|
|
||||||
/** \returns an expression of the coefficient-wise \< operator of *this and \a other
|
/** \returns an expression of the coefficient-wise \< operator of *this and \a other
|
||||||
|
@ -100,6 +100,19 @@ template<typename Scalar>
|
|||||||
struct ei_functor_traits<ei_scalar_pow_op<Scalar> >
|
struct ei_functor_traits<ei_scalar_pow_op<Scalar> >
|
||||||
{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, IsVectorizable = false }; };
|
{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, IsVectorizable = false }; };
|
||||||
|
|
||||||
|
/** \internal
|
||||||
|
* \brief Template functor to compute the reciprocal of a scalar
|
||||||
|
*
|
||||||
|
* \sa class CwiseUnaryOp, MatrixBase::cwiseInverse
|
||||||
|
*/
|
||||||
|
template<typename Scalar>
|
||||||
|
struct ei_scalar_inverse_op {
|
||||||
|
inline Scalar operator() (const Scalar& a) const { return Scalar(1)/a; }
|
||||||
|
};
|
||||||
|
template<typename Scalar>
|
||||||
|
struct ei_functor_traits<ei_scalar_inverse_op<Scalar> >
|
||||||
|
{ enum { Cost = NumTraits<Scalar>::MulCost, IsVectorizable = false }; };
|
||||||
|
|
||||||
// default ei_functor_traits for STL functors:
|
// default ei_functor_traits for STL functors:
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -49,7 +49,7 @@ struct ei_traits<DiagonalMatrix<CoeffsVectorType> >
|
|||||||
ColsAtCompileTime = CoeffsVectorType::SizeAtCompileTime,
|
ColsAtCompileTime = CoeffsVectorType::SizeAtCompileTime,
|
||||||
MaxRowsAtCompileTime = CoeffsVectorType::MaxSizeAtCompileTime,
|
MaxRowsAtCompileTime = CoeffsVectorType::MaxSizeAtCompileTime,
|
||||||
MaxColsAtCompileTime = CoeffsVectorType::MaxSizeAtCompileTime,
|
MaxColsAtCompileTime = CoeffsVectorType::MaxSizeAtCompileTime,
|
||||||
Flags = _CoeffsVectorTypeTypeNested::Flags & HereditaryBits,
|
Flags = _CoeffsVectorTypeTypeNested::Flags & HereditaryBits | Diagonal,
|
||||||
CoeffReadCost = _CoeffsVectorTypeTypeNested::CoeffReadCost
|
CoeffReadCost = _CoeffsVectorTypeTypeNested::CoeffReadCost
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -544,6 +544,7 @@ template<typename Derived> class MatrixBase : public ArrayBase<Derived>
|
|||||||
const CwiseUnaryOp<ei_scalar_sin_op<typename ei_traits<Derived>::Scalar>, Derived> cwiseSin() const;
|
const CwiseUnaryOp<ei_scalar_sin_op<typename ei_traits<Derived>::Scalar>, Derived> cwiseSin() const;
|
||||||
const CwiseUnaryOp<ei_scalar_pow_op<typename ei_traits<Derived>::Scalar>, Derived>
|
const CwiseUnaryOp<ei_scalar_pow_op<typename ei_traits<Derived>::Scalar>, Derived>
|
||||||
cwisePow(const Scalar& exponent) const;
|
cwisePow(const Scalar& exponent) const;
|
||||||
|
const CwiseUnaryOp<ei_scalar_inverse_op<typename ei_traits<Derived>::Scalar>, Derived> cwiseInverse() const;
|
||||||
|
|
||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
const CwiseBinaryOp<std::less<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
|
const CwiseBinaryOp<std::less<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
|
||||||
|
@ -147,6 +147,7 @@ template<typename Lhs, typename Rhs> struct ei_product_eval_mode
|
|||||||
enum{ value = Lhs::MaxRowsAtCompileTime >= EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
|
enum{ value = Lhs::MaxRowsAtCompileTime >= EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
|
||||||
&& Rhs::MaxColsAtCompileTime >= EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
|
&& Rhs::MaxColsAtCompileTime >= EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
|
||||||
&& Lhs::MaxColsAtCompileTime >= EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
|
&& Lhs::MaxColsAtCompileTime >= EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
|
||||||
|
&& Rhs::Flags&Diagonal!=Diagonal
|
||||||
? CacheFriendlyProduct : NormalProduct };
|
? CacheFriendlyProduct : NormalProduct };
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -259,25 +260,40 @@ template<typename Lhs, typename Rhs, int EvalMode> class Product : ei_no_assignm
|
|||||||
|
|
||||||
const Scalar _coeff(int row, int col) const
|
const Scalar _coeff(int row, int col) const
|
||||||
{
|
{
|
||||||
Scalar res;
|
if ((Rhs::Flags&Diagonal)==Diagonal)
|
||||||
const bool unroll = CoeffReadCost <= EIGEN_UNROLLING_LIMIT;
|
{
|
||||||
ei_product_impl<Lhs::ColsAtCompileTime-1,
|
return m_lhs.coeff(row, col) * m_rhs.coeff(col, col);
|
||||||
unroll ? Lhs::ColsAtCompileTime : Dynamic,
|
}
|
||||||
_LhsNested, _RhsNested>
|
else
|
||||||
::run(row, col, m_lhs, m_rhs, res);
|
{
|
||||||
return res;
|
Scalar res;
|
||||||
|
const bool unroll = CoeffReadCost <= EIGEN_UNROLLING_LIMIT;
|
||||||
|
ei_product_impl<Lhs::ColsAtCompileTime-1,
|
||||||
|
unroll ? Lhs::ColsAtCompileTime : Dynamic,
|
||||||
|
_LhsNested, _RhsNested>
|
||||||
|
::run(row, col, m_lhs, m_rhs, res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<int LoadMode>
|
template<int LoadMode>
|
||||||
const PacketScalar _packetCoeff(int row, int col) const
|
const PacketScalar _packetCoeff(int row, int col) const
|
||||||
{
|
{
|
||||||
const bool unroll = CoeffReadCost <= EIGEN_UNROLLING_LIMIT;
|
if ((Rhs::Flags&Diagonal)==Diagonal)
|
||||||
PacketScalar res;
|
{
|
||||||
ei_packet_product_impl<Flags&RowMajorBit ? true : false, Lhs::ColsAtCompileTime-1,
|
assert(_LhsNested::Flags&RowMajorBit==0);
|
||||||
unroll ? Lhs::ColsAtCompileTime : Dynamic,
|
return ei_pmul(m_lhs.template packetCoeff<LoadMode>(row, col), ei_pset1(m_rhs.coeff(col, col)));
|
||||||
_LhsNested, _RhsNested, PacketScalar>
|
}
|
||||||
::run(row, col, m_lhs, m_rhs, res);
|
else
|
||||||
return res;
|
{
|
||||||
|
const bool unroll = CoeffReadCost <= EIGEN_UNROLLING_LIMIT;
|
||||||
|
PacketScalar res;
|
||||||
|
ei_packet_product_impl<Flags&RowMajorBit ? true : false, Lhs::ColsAtCompileTime-1,
|
||||||
|
unroll ? Lhs::ColsAtCompileTime : Dynamic,
|
||||||
|
_LhsNested, _RhsNested, PacketScalar>
|
||||||
|
::run(row, col, m_lhs, m_rhs, res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Lhs_, typename Rhs_, int EvalMode_, typename DestDerived_, bool DirectAccess_>
|
template<typename Lhs_, typename Rhs_, int EvalMode_, typename DestDerived_, bool DirectAccess_>
|
||||||
|
@ -66,6 +66,7 @@ const unsigned int SelfAdjoint = SelfAdjointBit;
|
|||||||
// additional possible values for the Mode parameter of extract()
|
// additional possible values for the Mode parameter of extract()
|
||||||
const unsigned int UnitUpper = UpperTriangularBit | UnitDiagBit;
|
const unsigned int UnitUpper = UpperTriangularBit | UnitDiagBit;
|
||||||
const unsigned int UnitLower = LowerTriangularBit | UnitDiagBit;
|
const unsigned int UnitLower = LowerTriangularBit | UnitDiagBit;
|
||||||
|
const unsigned int Diagonal = Upper | Lower;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,6 +67,7 @@ template<typename Scalar> struct ei_scalar_log_op;
|
|||||||
template<typename Scalar> struct ei_scalar_cos_op;
|
template<typename Scalar> struct ei_scalar_cos_op;
|
||||||
template<typename Scalar> struct ei_scalar_sin_op;
|
template<typename Scalar> struct ei_scalar_sin_op;
|
||||||
template<typename Scalar> struct ei_scalar_pow_op;
|
template<typename Scalar> struct ei_scalar_pow_op;
|
||||||
|
template<typename Scalar> struct ei_scalar_inverse_op;
|
||||||
template<typename Scalar, typename NewType> struct ei_scalar_cast_op;
|
template<typename Scalar, typename NewType> struct ei_scalar_cast_op;
|
||||||
template<typename Scalar, bool IsVectorizable> struct ei_scalar_multiple_op;
|
template<typename Scalar, bool IsVectorizable> struct ei_scalar_multiple_op;
|
||||||
template<typename Scalar> struct ei_scalar_quotient1_op;
|
template<typename Scalar> struct ei_scalar_quotient1_op;
|
||||||
|
@ -212,8 +212,7 @@ template<typename T, int n=1> struct ei_nested
|
|||||||
|
|
||||||
template<unsigned int Flags> struct ei_are_flags_consistent
|
template<unsigned int Flags> struct ei_are_flags_consistent
|
||||||
{
|
{
|
||||||
enum { ret = !( (Flags&UnitDiagBit && Flags&ZeroDiagBit)
|
enum { ret = !( (Flags&UnitDiagBit && Flags&ZeroDiagBit) )
|
||||||
|| (Flags&UpperTriangularBit && Flags&LowerTriangularBit) )
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user