11#ifndef EIGEN_PARTIAL_REDUX_H
12#define EIGEN_PARTIAL_REDUX_H
32template<
typename MatrixType,
typename MemberOp,
int Direction>
33class PartialReduxExpr;
36template<
typename MatrixType,
typename MemberOp,
int Direction>
40 typedef typename MemberOp::result_type Scalar;
43 typedef typename MatrixType::Scalar InputScalar;
45 RowsAtCompileTime = Direction==
Vertical ? 1 : MatrixType::RowsAtCompileTime,
46 ColsAtCompileTime = Direction==
Horizontal ? 1 : MatrixType::ColsAtCompileTime,
47 MaxRowsAtCompileTime = Direction==
Vertical ? 1 : MatrixType::MaxRowsAtCompileTime,
48 MaxColsAtCompileTime = Direction==
Horizontal ? 1 : MatrixType::MaxColsAtCompileTime,
50 TraversalSize = Direction==
Vertical ? MatrixType::RowsAtCompileTime : MatrixType::ColsAtCompileTime
55template<
typename MatrixType,
typename MemberOp,
int Direction>
66 : m_matrix(
mat), m_functor(func) {}
69 Index rows()
const {
return (Direction==
Vertical ? 1 : m_matrix.rows()); }
71 Index cols()
const {
return (Direction==
Horizontal ? 1 : m_matrix.cols()); }
74 typename MatrixType::Nested nestedExpression()
const {
return m_matrix; }
77 const MemberOp& functor()
const {
return m_functor; }
80 typename MatrixType::Nested m_matrix;
84#define EIGEN_MEMBER_FUNCTOR(MEMBER,COST) \
85 template <typename ResultType> \
86 struct member_##MEMBER { \
87 EIGEN_EMPTY_STRUCT_CTOR(member_##MEMBER) \
88 typedef ResultType result_type; \
89 template<typename Scalar, int Size> struct Cost \
90 { enum { value = COST }; }; \
91 template<typename XprType> \
92 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
93 ResultType operator()(const XprType& mat) const \
94 { return mat.MEMBER(); } \
113template <
int p,
typename ResultType>
115 typedef ResultType result_type;
116 template<
typename Scalar,
int Size>
struct Cost
119 template<
typename XprType>
124template <
typename BinaryOp,
typename Scalar>
127 BinaryOp(Scalar,Scalar)
129 template<
typename _Scalar,
int Size>
struct Cost
132 template<
typename Derived>
134 {
return mat.redux(m_functor); }
135 const BinaryOp m_functor;
160 typedef typename ExpressionType::Scalar Scalar;
161 typedef typename ExpressionType::RealScalar RealScalar;
166 template<
template<
typename _Scalar>
class Functor,
184 isVertical = (Direction==
Vertical) ? 1 : 0,
185 isHorizontal = (Direction==
Horizontal) ? 1 : 0
193 typename ExpressionType::ColXpr,
194 typename ExpressionType::RowXpr>::type
SubVector;
204 Index subVectors()
const
205 {
return isVertical?m_matrix.cols():m_matrix.rows(); }
209 isVertical ? 1 : ExpressionType::RowsAtCompileTime,
210 isHorizontal ? 1 : ExpressionType::ColsAtCompileTime>
Type;
215 template<
typename OtherDerived>
220 EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(isVertical, OtherDerived::MaxColsAtCompileTime==1),
221 YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED)
222 EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(isHorizontal, OtherDerived::MaxRowsAtCompileTime==1),
223 YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED)
226 isVertical ? 1 : m_matrix.rows(),
227 isHorizontal ? 1 : m_matrix.cols());
232 isHorizontal ? 1 : ExpressionType::RowsAtCompileTime,
233 isVertical ? 1 : ExpressionType::ColsAtCompileTime>
Type;
238 template<
typename OtherDerived>
243 EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(isHorizontal, OtherDerived::MaxColsAtCompileTime==1),
244 YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED)
245 EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(isVertical, OtherDerived::MaxRowsAtCompileTime==1),
246 YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED)
249 isHorizontal ? 1 : m_matrix.rows(),
250 isVertical ? 1 : m_matrix.cols());
255 explicit inline VectorwiseOp(ExpressionType& matrix) : m_matrix(matrix) {}
259 inline const ExpressionType& _expression()
const {
return m_matrix; }
268 template<
typename BinaryOp>
270 const typename ReduxReturnType<BinaryOp>::Type
271 redux(
const BinaryOp& func = BinaryOp())
const
274 typedef typename ReturnType<internal::member_minCoeff>::Type MinCoeffReturnType;
275 typedef typename ReturnType<internal::member_maxCoeff>::Type MaxCoeffReturnType;
276 typedef typename ReturnType<internal::member_squaredNorm,RealScalar>::Type SquaredNormReturnType;
277 typedef typename ReturnType<internal::member_norm,RealScalar>::Type NormReturnType;
278 typedef typename ReturnType<internal::member_blueNorm,RealScalar>::Type BlueNormReturnType;
279 typedef typename ReturnType<internal::member_stableNorm,RealScalar>::Type StableNormReturnType;
280 typedef typename ReturnType<internal::member_hypotNorm,RealScalar>::Type HypotNormReturnType;
281 typedef typename ReturnType<internal::member_sum>::Type SumReturnType;
282 typedef typename ReturnType<internal::member_mean>::Type MeanReturnType;
283 typedef typename ReturnType<internal::member_all>::Type AllReturnType;
284 typedef typename ReturnType<internal::member_any>::Type AnyReturnType;
286 typedef typename ReturnType<internal::member_prod>::Type ProdReturnType;
462 typedef Replicate<ExpressionType,(isVertical?Dynamic:1),(isHorizontal?Dynamic:1)> ReplicateReturnType;
464 const ReplicateReturnType
replicate(Index factor)
const;
481 (_expression(),isVertical?factor:1,isHorizontal?factor:1);
487 template<
typename OtherDerived>
492 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType,
OtherDerived)
494 return const_cast<ExpressionType&
>(m_matrix = extendedTo(other.derived()));
498 template<
typename OtherDerived>
503 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType,
OtherDerived)
504 return const_cast<ExpressionType&
>(m_matrix += extendedTo(other.derived()));
508 template<
typename OtherDerived>
514 return const_cast<ExpressionType&>(m_matrix -= extendedTo(other.derived()));
523 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
524 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType,
OtherDerived)
525 m_matrix *= extendedTo(other.derived());
526 return const_cast<ExpressionType&
>(m_matrix);
530 template<
typename OtherDerived>
535 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
536 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType,
OtherDerived)
537 m_matrix /= extendedTo(other.derived());
538 return const_cast<ExpressionType&
>(m_matrix);
544 const ExpressionTypeNestedCleaned,
545 const typename ExtendedType<OtherDerived>::Type>
549 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType,
OtherDerived)
550 return m_matrix + extendedTo(other.derived());
554 template<
typename OtherDerived>
557 const ExpressionTypeNestedCleaned,
558 const typename ExtendedType<OtherDerived>::Type>
562 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType,
OtherDerived)
563 return m_matrix - extendedTo(other.derived());
570 const ExpressionTypeNestedCleaned,
571 const typename ExtendedType<OtherDerived>::Type>
576 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
577 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType,
OtherDerived)
578 return m_matrix * extendedTo(other.derived());
583 template<
typename OtherDerived>
586 const ExpressionTypeNestedCleaned,
587 const typename ExtendedType<OtherDerived>::Type>
591 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
592 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType,
OtherDerived)
593 return m_matrix / extendedTo(other.derived());
602 const ExpressionTypeNestedCleaned,
604 normalized()
const {
return m_matrix.cwiseQuotient(extendedToOpposite(this->
norm())); }
621 typedef typename ExpressionType::PlainObject CrossReturnType;
622 template<
typename OtherDerived>
629 HNormalized_SizeMinusOne = HNormalized_Size==Dynamic ? Dynamic : HNormalized_Size-1
631 typedef Block<
const ExpressionType,
632 Direction==
Vertical ? int(HNormalized_SizeMinusOne)
633 : int(internal::traits<ExpressionType>::RowsAtCompileTime),
634 Direction==
Horizontal ? int(HNormalized_SizeMinusOne)
635 : int(internal::traits<ExpressionType>::ColsAtCompileTime)>
637 typedef Block<
const ExpressionType,
638 Direction==
Vertical ? 1 : int(internal::traits<ExpressionType>::RowsAtCompileTime),
639 Direction==
Horizontal ? 1 : int(internal::traits<ExpressionType>::ColsAtCompileTime)>
641 typedef CwiseBinaryOp<internal::scalar_quotient_op<typename internal::traits<ExpressionType>::Scalar>,
642 const HNormalized_Block,
643 const Replicate<HNormalized_Factors,
644 Direction==
Vertical ? HNormalized_SizeMinusOne : 1,
645 Direction==
Horizontal ? HNormalized_SizeMinusOne : 1> >
646 HNormalizedReturnType;
651 ExpressionTypeNested m_matrix;
661template<
typename Derived>
662inline typename DenseBase<Derived>::ColwiseReturnType
675template<
typename Derived>
Base class for all dense matrices, vectors, and arrays.
Definition DenseBase.h:49
EIGEN_DEVICE_FUNC ConstColwiseReturnType colwise() const
Definition DenseBase.h:510
EIGEN_DEVICE_FUNC ConstRowwiseReturnType rowwise() const
Definition DenseBase.h:498
Generic expression of a partially reduxed matrix.
Definition VectorwiseOp.h:58
Expression of the multiple replication of a matrix or vector.
Definition Replicate.h:62
Pseudo expression representing a solving operation.
Definition Solve.h:63
Pseudo expression providing partial reduction operations.
Definition VectorwiseOp.h:157
EIGEN_DEVICE_FUNC const MinCoeffReturnType minCoeff() const
Definition VectorwiseOp.h:303
EIGEN_DEVICE_FUNC const NormReturnType norm() const
Definition VectorwiseOp.h:340
EIGEN_DEVICE_FUNC void normalize()
Normalize in-place each row or columns of the referenced matrix.
Definition VectorwiseOp.h:610
const HNormalizedReturnType hnormalized() const
\geometry_module
Definition Homogeneous.h:177
EIGEN_DEVICE_FUNC const SumReturnType sum() const
Definition VectorwiseOp.h:397
EIGEN_DEVICE_FUNC const AllReturnType all() const
Definition VectorwiseOp.h:414
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC CwiseBinaryOp< internal::scalar_product_op< Scalar >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > EIGEN_DEVICE_FUNC operator*(const DenseBase< OtherDerived > &other) const
Returns the expression where each subvector is the product of the vector other by the corresponding s...
Definition VectorwiseOp.h:573
EIGEN_DEVICE_FUNC CwiseBinaryOp< internal::scalar_quotient_op< Scalar >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > operator/(const DenseBase< OtherDerived > &other) const
Returns the expression where each subvector is the quotient of the corresponding subvector of *this b...
Definition VectorwiseOp.h:588
EIGEN_DEVICE_FUNC const MaxCoeffReturnType maxCoeff() const
Definition VectorwiseOp.h:316
Eigen::Index Index
Definition VectorwiseOp.h:162
EIGEN_DEVICE_FUNC const ReplicateReturnType replicate(Index factor) const
Definition Replicate.h:133
EIGEN_DEVICE_FUNC const ProdReturnType prod() const
Definition VectorwiseOp.h:447
EIGEN_DEVICE_FUNC CwiseBinaryOp< internal::scalar_quotient_op< Scalar >, const ExpressionTypeNestedCleaned, const typename OppositeExtendedType< typename ReturnType< internal::member_norm, RealScalar >::Type >::Type > normalized() const
Definition VectorwiseOp.h:604
EIGEN_DEVICE_FUNC CwiseBinaryOp< internal::scalar_difference_op< Scalar >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > operator-(const DenseBase< OtherDerived > &other) const
Returns the expression of the difference between each subvector of *this and the vector other.
Definition VectorwiseOp.h:559
EIGEN_DEVICE_FUNC const SquaredNormReturnType squaredNorm() const
Definition VectorwiseOp.h:328
EIGEN_DEVICE_FUNC ExpressionType & operator/=(const DenseBase< OtherDerived > &other)
Divides each subvector of *this by the vector other.
Definition VectorwiseOp.h:532
EIGEN_DEVICE_FUNC const AnyReturnType any() const
Definition VectorwiseOp.h:423
EIGEN_DEVICE_FUNC const HypotNormReturnType hypotNorm() const
Definition VectorwiseOp.h:386
EIGEN_DEVICE_FUNC void reverseInPlace()
This is the "in place" version of VectorwiseOp::reverse: it reverses each column or row of *this.
Definition Reverse.h:204
EIGEN_DEVICE_FUNC const CountReturnType count() const
Definition VectorwiseOp.h:436
const Replicate< ExpressionType, isVertical *Factor+isHorizontal, isHorizontal *Factor+isVertical > EIGEN_DEVICE_FUNC replicate(Index factor=Factor) const
Definition VectorwiseOp.h:478
EIGEN_DEVICE_FUNC const ReverseReturnType reverse() const
Definition VectorwiseOp.h:459
EIGEN_DEVICE_FUNC ExpressionType & operator=(const DenseBase< OtherDerived > &other)
Copies the vector other to each subvector of *this.
Definition VectorwiseOp.h:489
EIGEN_DEVICE_FUNC const LpNormReturnType< p >::Type lpNorm() const
Definition VectorwiseOp.h:353
EIGEN_DEVICE_FUNC const StableNormReturnType stableNorm() const
Definition VectorwiseOp.h:375
EIGEN_DEVICE_FUNC ExpressionType & operator+=(const DenseBase< OtherDerived > &other)
Adds the vector other to each subvector of *this.
Definition VectorwiseOp.h:500
EIGEN_DEVICE_FUNC const BlueNormReturnType blueNorm() const
Definition VectorwiseOp.h:364
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC CwiseBinaryOp< internal::scalar_sum_op< Scalar >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > operator+(const DenseBase< OtherDerived > &other) const
Returns the expression of the sum of the vector other to each subvector of *this.
Definition VectorwiseOp.h:546
EIGEN_DEVICE_FUNC const MeanReturnType mean() const
Definition VectorwiseOp.h:405
EIGEN_DEVICE_FUNC ExpressionType & operator-=(const DenseBase< OtherDerived > &other)
Substracts the vector other to each subvector of *this.
Definition VectorwiseOp.h:510
EIGEN_DEVICE_FUNC const ReduxReturnType< BinaryOp >::Type redux(const BinaryOp &func=BinaryOp()) const
Definition VectorwiseOp.h:271
HomogeneousReturnType homogeneous() const
\geometry_module
Definition Homogeneous.h:144
Definition XprHelper.h:50
@ Horizontal
For Reverse, all rows are reversed; for PartialReduxExpr and VectorwiseOp, act on rows.
Definition Constants.h:268
@ Vertical
For Reverse, all columns are reversed; for PartialReduxExpr and VectorwiseOp, act on columns.
Definition Constants.h:265
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition Constants.h:61
Holds information about the various numeric (i.e.
Definition NumTraits.h:108
Definition VectorwiseOp.h:207
Definition VectorwiseOp.h:289
Definition VectorwiseOp.h:230
Definition VectorwiseOp.h:176
Definition VectorwiseOp.h:168
Definition XprHelper.h:428
Definition XprHelper.h:107
Definition VectorwiseOp.h:117
Definition VectorwiseOp.h:114
Definition VectorwiseOp.h:130
Definition VectorwiseOp.h:125
Definition ForwardDeclarations.h:17