11 #ifndef EIGEN_PARTIAL_REDUX_H 12 #define EIGEN_PARTIAL_REDUX_H 32 template<
typename MatrixType,
typename MemberOp,
int Direction>
33 class PartialReduxExpr;
36 template<
typename MatrixType,
typename MemberOp,
int Direction>
40 typedef typename MemberOp::result_type
Scalar;
47 RowsAtCompileTime = Direction==
Vertical ? 1 : MatrixType::RowsAtCompileTime,
48 ColsAtCompileTime = Direction==
Horizontal ? 1 : MatrixType::ColsAtCompileTime,
49 MaxRowsAtCompileTime = Direction==
Vertical ? 1 : MatrixType::MaxRowsAtCompileTime,
50 MaxColsAtCompileTime = Direction==
Horizontal ? 1 : MatrixType::MaxColsAtCompileTime,
53 TraversalSize = Direction==
Vertical ? RowsAtCompileTime : ColsAtCompileTime
55 #if EIGEN_GNUC_AT_LEAST(3,4) 56 typedef typename MemberOp::template Cost<InputScalar,int(TraversalSize)>
CostOpType;
58 typedef typename MemberOp::template Cost<InputScalar,TraversalSize>
CostOpType;
66 template<
typename MatrixType,
typename MemberOp,
int Direction>
78 : m_matrix(mat), m_functor(func) {}
80 Index
rows()
const {
return (Direction==
Vertical ? 1 : m_matrix.rows()); }
86 return m_functor(m_matrix.col(j));
88 return m_functor(m_matrix.row(i));
91 const Scalar
coeff(Index index)
const 94 return m_functor(m_matrix.col(index));
96 return m_functor(m_matrix.row(index));
104 #define EIGEN_MEMBER_FUNCTOR(MEMBER,COST) \ 105 template <typename ResultType> \ 106 struct member_##MEMBER { \ 107 EIGEN_EMPTY_STRUCT_CTOR(member_##MEMBER) \ 108 typedef ResultType result_type; \ 109 template<typename Scalar, int Size> struct Cost \ 110 { enum { value = COST }; }; \ 111 template<typename XprType> \ 112 EIGEN_STRONG_INLINE ResultType operator()(const XprType& mat) const \ 113 { return mat.MEMBER(); } \ 133 template <
typename BinaryOp,
typename Scalar>
138 template<
typename _Scalar,
int Size>
struct Cost 141 template<
typename Derived>
143 {
return mat.
redux(m_functor); }
165 template<
typename ExpressionType,
int Direction>
class VectorwiseOp 169 typedef typename ExpressionType::Scalar
Scalar;
171 typedef typename ExpressionType::Index
Index;
176 template<
template<
typename _Scalar>
class Functor,
207 return SubVector(m_matrix.derived(),i);
213 {
return Direction==
Vertical?m_matrix.cols():m_matrix.rows(); }
217 Direction==
Vertical ? 1 : ExpressionType::RowsAtCompileTime,
223 template<
typename OtherDerived>
228 YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED)
230 YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED)
233 Direction==
Vertical ? 1 : m_matrix.rows(),
239 Direction==
Horizontal ? 1 : ExpressionType::RowsAtCompileTime,
245 template<
typename OtherDerived>
250 YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED)
252 YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED)
256 Direction==
Vertical ? 1 : m_matrix.cols());
273 template<
typename BinaryOp>
275 redux(
const BinaryOp& func = BinaryOp())
const 288 {
return _expression(); }
300 {
return _expression(); }
310 {
return _expression(); }
320 {
return _expression(); }
329 {
return _expression(); }
338 {
return _expression(); }
347 {
return _expression(); }
357 {
return _expression(); }
364 {
return _expression(); }
371 {
return _expression(); }
378 {
return _expression(); }
388 {
return _expression(); }
398 {
return _expression(); }
412 const ReplicateReturnType replicate(Index factor)
const;
433 template<
typename OtherDerived>
439 return const_cast<ExpressionType&
>(m_matrix = extendedTo(other.derived()));
443 template<
typename OtherDerived>
448 return const_cast<ExpressionType&
>(m_matrix += extendedTo(other.derived()));
452 template<
typename OtherDerived>
457 return const_cast<ExpressionType&
>(m_matrix -= extendedTo(other.derived()));
461 template<
typename OtherDerived>
467 m_matrix *= extendedTo(other.derived());
472 template<
typename OtherDerived>
478 m_matrix /= extendedTo(other.derived());
485 const ExpressionTypeNestedCleaned,
491 return m_matrix + extendedTo(other.derived());
495 template<
typename OtherDerived>
497 const ExpressionTypeNestedCleaned,
503 return m_matrix - extendedTo(other.derived());
510 const ExpressionTypeNestedCleaned,
517 return m_matrix * extendedTo(other.derived());
522 template<
typename OtherDerived>
524 const ExpressionTypeNestedCleaned,
531 return m_matrix / extendedTo(other.derived());
538 CwiseBinaryOp<internal::scalar_quotient_op<Scalar>,
539 const ExpressionTypeNestedCleaned,
541 normalized()
const {
return m_matrix.cwiseQuotient(extendedToOpposite(this->norm())); }
548 m_matrix = this->normalized();
553 #if EIGEN2_SUPPORT_STAGE > STAGE20_RESOLVE_API_CONFLICTS 558 template<
typename OtherDerived>
564 HNormalized_SizeMinusOne = HNormalized_Size==
Dynamic ?
Dynamic : HNormalized_Size-1
567 Direction==
Vertical ? int(HNormalized_SizeMinusOne)
568 : int(
internal::traits<ExpressionType>::RowsAtCompileTime),
569 Direction==
Horizontal ? int(HNormalized_SizeMinusOne)
570 : int(
internal::traits<ExpressionType>::ColsAtCompileTime)>
572 typedef Block<
const ExpressionType,
579 Direction==
Vertical ? HNormalized_SizeMinusOne : 1,
580 Direction==
Horizontal ? HNormalized_SizeMinusOne : 1> >
596 template<
typename Derived>
607 template<
typename Derived>
621 template<
typename Derived>
632 template<
typename Derived>
641 #endif // EIGEN_PARTIAL_REDUX_H const ReturnType< internal::member_mean >::Type mean() const
CwiseBinaryOp< internal::scalar_quotient_op< Scalar >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > operator/(const DenseBase< OtherDerived > &other) const
Block< Derived, 1, internal::traits< Derived >::ColsAtCompileTime, IsRowMajor > RowXpr
internal::remove_all< ExpressionTypeNested >::type ExpressionTypeNestedCleaned
ExpressionType & operator+=(const DenseBase< OtherDerived > &other)
CwiseBinaryOp< internal::scalar_quotient_op< Scalar >, const ExpressionTypeNestedCleaned, const typename OppositeExtendedType< typename ReturnType< internal::member_norm, RealScalar >::Type >::Type > normalized() const
const ReturnType< internal::member_sum >::Type sum() const
const ReturnType< internal::member_stableNorm, RealScalar >::Type stableNorm() const
#define EIGEN_STRONG_INLINE
const ExpressionType & _expression() const
ExpressionType & operator*=(const DenseBase< OtherDerived > &other)
ExtendedType< OtherDerived >::Type extendedTo(const DenseBase< OtherDerived > &other) const
ExpressionType::Index Index
Replicate< ExpressionType, Direction==Vertical?Dynamic:1, Direction==Horizontal?Dynamic:1 > ReplicateReturnType
internal::conditional< internal::must_nest_by_value< ExpressionType >::ret, ExpressionType, ExpressionType & >::type ExpressionTypeNested
nested< MatrixType >::type MatrixTypeNested
result_type operator()(const DenseBase< Derived > &mat) const
Replicate< OtherDerived, Direction==Horizontal?1:ExpressionType::RowsAtCompileTime, Direction==Vertical?1:ExpressionType::ColsAtCompileTime > Type
OppositeExtendedType< OtherDerived >::Type extendedToOpposite(const DenseBase< OtherDerived > &other) const
ExpressionType::RealScalar RealScalar
ExpressionType & operator=(const DenseBase< OtherDerived > &other)
iterative scaling algorithm to equilibrate rows and column norms in matrices
Block< Derived, internal::traits< Derived >::RowsAtCompileTime, 1,!IsRowMajor > ColXpr
MatrixTypeNested m_matrix
ExpressionType & operator-=(const DenseBase< OtherDerived > &other)
Generic expression of a partially reduxed matrix.
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Pseudo expression providing partial reduction operations.
PartialReduxExpr< ExpressionType, internal::member_redux< BinaryOp, typename internal::traits< ExpressionType >::Scalar >, Direction > Type
const ReturnType< internal::member_maxCoeff >::Type maxCoeff() const
internal::conditional< Direction==Vertical, typename ExpressionType::ColXpr, typename ExpressionType::RowXpr >::type SubVector
const unsigned int RowMajorBit
Base class for all dense matrices, vectors, and arrays.
internal::traits< PartialReduxExpr >::_MatrixTypeNested _MatrixTypeNested
SubVector subVector(Index i)
Replicate< OtherDerived, Direction==Vertical?1:ExpressionType::RowsAtCompileTime, Direction==Horizontal?1:ExpressionType::ColsAtCompileTime > Type
EIGEN_STRONG_INLINE CwiseBinaryOp< internal::scalar_sum_op< Scalar >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > operator+(const DenseBase< OtherDerived > &other) const
const Reverse< ExpressionType, Direction > reverse() const
MemberOp::template Cost< InputScalar, TraversalSize > CostOpType
PartialReduxExpr< ExpressionType, Functor< Scalar >, Direction > Type
result_of< BinaryOp(Scalar) >::type result_type
Generic expression where a coefficient-wise binary operator is applied to two expressions.
const unsigned int HereditaryBits
EIGEN_STRONG_INLINE const Scalar coeff(Index i, Index j) const
internal::result_of< BinaryOp(typename internal::traits< Derived >::Scalar)>::type redux(const BinaryOp &func) const
MemberOp::result_type Scalar
ConstColwiseReturnType colwise() const
const ReturnType< internal::member_any >::Type any() const
const ReturnType< internal::member_minCoeff >::Type minCoeff() const
remove_all< MatrixTypeNested >::type _MatrixTypeNested
EIGEN_MEMBER_FUNCTOR(squaredNorm, Size *NumTraits< Scalar >::MulCost+(Size-1)*NumTraits< Scalar >::AddCost)
Expression of the multiple replication of a matrix or vector.
ExpressionTypeNested m_matrix
traits< MatrixType >::StorageKind StorageKind
CwiseBinaryOp< internal::scalar_quotient_op< typename internal::traits< ExpressionType >::Scalar >, const HNormalized_Block, const Replicate< HNormalized_Factors, Direction==Vertical?HNormalized_SizeMinusOne:1, Direction==Horizontal?HNormalized_SizeMinusOne:1 > > HNormalizedReturnType
internal::traits< PartialReduxExpr >::MatrixTypeNested MatrixTypeNested
#define EIGEN_STATIC_ASSERT_ARRAYXPR(Derived)
MatrixType::Scalar InputScalar
const ReturnType< internal::member_all >::Type all() const
const Scalar coeff(Index index) const
const ReturnType< internal::member_norm, RealScalar >::Type norm() const
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
ExpressionType::Scalar Scalar
Expression of a fixed-size or dynamic-size block.
ExpressionType & operator/=(const DenseBase< OtherDerived > &other)
#define EIGEN_STATIC_ASSERT_SAME_XPR_KIND(Derived1, Derived2)
const ReturnType< internal::member_hypotNorm, RealScalar >::Type hypotNorm() const
traits< MatrixType >::XprKind XprKind
VectorwiseOp(ExpressionType &matrix)
#define EIGEN_IMPLIES(a, b)
const ReduxReturnType< BinaryOp >::Type redux(const BinaryOp &func=BinaryOp()) const
CwiseBinaryOp< internal::scalar_difference_op< Scalar >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > operator-(const DenseBase< OtherDerived > &other) const
ConstRowwiseReturnType rowwise() const
Block< const ExpressionType, Direction==Vertical?1:int(internal::traits< ExpressionType >::RowsAtCompileTime), Direction==Horizontal?1:int(internal::traits< ExpressionType >::ColsAtCompileTime)> HNormalized_Factors
member_redux(const BinaryOp func)
const PartialReduxExpr< ExpressionType, internal::member_count< Index >, Direction > count() const
const ReturnType< internal::member_blueNorm, RealScalar >::Type blueNorm() const
Expression of the reverse of a vector or matrix.
const ReturnType< internal::member_squaredNorm, RealScalar >::Type squaredNorm() const
const ReturnType< internal::member_prod >::Type prod() const
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
ExpressionType::PlainObject CrossReturnType
EIGEN_STRONG_INLINE CwiseBinaryOp< internal::scalar_product_op< Scalar >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > operator*(const DenseBase< OtherDerived > &other) const
Base class for all dense matrices, vectors, and expressions.
const Replicate< ExpressionType,(IsVertical?Factor:1),(IsHorizontal?Factor:1)> replicate(Index factor=Factor) const
internal::dense_xpr_base< PartialReduxExpr >::type Base
Expression of one (or a set of) homogeneous vector(s)