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,
51 Flags0 = (
unsigned int)_MatrixTypeNested::Flags & HereditaryBits,
53 TraversalSize = Direction==
Vertical ? MatrixType::RowsAtCompileTime : MatrixType::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;
67 template<
typename MatrixType,
typename MemberOp,
int Direction>
79 : m_matrix(mat), m_functor(
func) {}
81 Index rows()
const {
return (Direction==
Vertical ? 1 : m_matrix.rows()); }
82 Index cols()
const {
return (Direction==
Horizontal ? 1 : m_matrix.cols()); }
84 EIGEN_STRONG_INLINE
const Scalar coeff(Index i, Index j)
const 87 return m_functor(m_matrix.col(j));
89 return m_functor(m_matrix.row(i));
92 const Scalar coeff(Index index)
const 95 return m_functor(m_matrix.col(index));
97 return m_functor(m_matrix.row(index));
101 MatrixTypeNested m_matrix;
102 const MemberOp m_functor;
105 #define EIGEN_MEMBER_FUNCTOR(MEMBER,COST) \ 106 template <typename ResultType> \ 107 struct member_##MEMBER { \ 108 EIGEN_EMPTY_STRUCT_CTOR(member_##MEMBER) \ 109 typedef ResultType result_type; \ 110 template<typename Scalar, int Size> struct Cost \ 111 { enum { value = COST }; }; \ 112 template<typename XprType> \ 113 EIGEN_STRONG_INLINE ResultType operator()(const XprType& mat) const \ 114 { return mat.MEMBER(); } \ 134 template <
typename BinaryOp,
typename Scalar>
139 template<
typename _Scalar,
int Size>
struct Cost 142 template<
typename Derived>
144 {
return mat.redux(m_functor); }
145 const BinaryOp m_functor;
166 template<
typename ExpressionType,
int Direction>
class VectorwiseOp 171 typedef typename ExpressionType::RealScalar RealScalar;
172 typedef typename ExpressionType::Index Index;
174 ExpressionType, ExpressionType&>::type ExpressionTypeNested;
177 template<
template<
typename _Scalar>
class Functor,
195 IsVertical = (Direction==
Vertical) ? 1 : 0,
196 IsHorizontal = (Direction==
Horizontal) ? 1 : 0
204 typename ExpressionType::ColXpr,
205 typename ExpressionType::RowXpr>::type
SubVector;
206 SubVector subVector(Index i)
208 return SubVector(m_matrix.derived(),i);
213 Index subVectors()
const 214 {
return Direction==
Vertical?m_matrix.cols():m_matrix.rows(); }
218 Direction==
Vertical ? 1 : ExpressionType::RowsAtCompileTime,
219 Direction==
Horizontal ? 1 : ExpressionType::ColsAtCompileTime>
Type;
224 template<
typename OtherDerived>
228 EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(Direction==
Vertical, OtherDerived::MaxColsAtCompileTime==1),
229 YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED)
230 EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(Direction==
Horizontal, OtherDerived::MaxRowsAtCompileTime==1),
231 YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED)
234 Direction==
Vertical ? 1 : m_matrix.rows(),
240 Direction==
Horizontal ? 1 : ExpressionType::RowsAtCompileTime,
241 Direction==
Vertical ? 1 : ExpressionType::ColsAtCompileTime>
Type;
246 template<
typename OtherDerived>
250 EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(Direction==
Horizontal, OtherDerived::MaxColsAtCompileTime==1),
251 YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED)
252 EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(Direction==
Vertical, OtherDerived::MaxRowsAtCompileTime==1),
253 YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED)
257 Direction==
Vertical ? 1 : m_matrix.cols());
262 inline VectorwiseOp(ExpressionType& matrix) : m_matrix(matrix) {}
265 inline const ExpressionType& _expression()
const {
return m_matrix; }
274 template<
typename BinaryOp>
289 {
return _expression(); }
301 {
return _expression(); }
311 {
return _expression(); }
321 {
return _expression(); }
330 {
return _expression(); }
339 {
return _expression(); }
348 {
return _expression(); }
358 {
return _expression(); }
365 {
return _expression(); }
372 {
return _expression(); }
379 {
return _expression(); }
389 {
return _expression(); }
399 {
return _expression(); }
413 const ReplicateReturnType replicate(Index factor)
const;
434 template<
typename OtherDerived>
437 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
438 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
440 return const_cast<ExpressionType&
>(m_matrix = extendedTo(other.derived()));
444 template<
typename OtherDerived>
447 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
448 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
449 return const_cast<ExpressionType&
>(m_matrix += extendedTo(other.derived()));
453 template<
typename OtherDerived>
456 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
457 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
458 return const_cast<ExpressionType&
>(m_matrix -= extendedTo(other.derived()));
462 template<
typename OtherDerived>
465 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
466 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
467 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
468 m_matrix *= extendedTo(other.derived());
469 return const_cast<ExpressionType&
>(m_matrix);
473 template<
typename OtherDerived>
476 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
477 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
478 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
479 m_matrix /= extendedTo(other.derived());
480 return const_cast<ExpressionType&
>(m_matrix);
484 template<
typename OtherDerived> EIGEN_STRONG_INLINE
486 const ExpressionTypeNestedCleaned,
490 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
491 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
492 return m_matrix + extendedTo(other.derived());
496 template<
typename OtherDerived>
498 const ExpressionTypeNestedCleaned,
502 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
503 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
504 return m_matrix - extendedTo(other.derived());
509 template<
typename OtherDerived> EIGEN_STRONG_INLINE
511 const ExpressionTypeNestedCleaned,
515 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
516 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
517 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
518 return m_matrix * extendedTo(other.derived());
523 template<
typename OtherDerived>
525 const ExpressionTypeNestedCleaned,
529 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
530 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
531 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
532 return m_matrix / extendedTo(other.derived());
539 CwiseBinaryOp<internal::scalar_quotient_op<Scalar>,
540 const ExpressionTypeNestedCleaned,
542 normalized()
const {
return m_matrix.cwiseQuotient(extendedToOpposite(this->norm())); }
549 m_matrix = this->normalized();
554 #if EIGEN2_SUPPORT_STAGE > STAGE20_RESOLVE_API_CONFLICTS 558 typedef typename ExpressionType::PlainObject CrossReturnType;
559 template<
typename OtherDerived>
565 HNormalized_SizeMinusOne = HNormalized_Size==
Dynamic ?
Dynamic : HNormalized_Size-1
567 typedef Block<
const ExpressionType,
568 Direction==
Vertical ? int(HNormalized_SizeMinusOne)
570 Direction==
Horizontal ? int(HNormalized_SizeMinusOne)
573 typedef Block<
const ExpressionType,
580 Direction==
Vertical ? HNormalized_SizeMinusOne : 1,
581 Direction==
Horizontal ? HNormalized_SizeMinusOne : 1> >
587 ExpressionTypeNested m_matrix;
597 template<
typename Derived>
608 template<
typename Derived>
622 template<
typename Derived>
633 template<
typename Derived>
642 #endif // EIGEN_PARTIAL_REDUX_H ExpressionType & operator+=(const DenseBase< OtherDerived > &other)
Adds the vector other to each subvector of *this.
Definition: VectorwiseOp.h:445
Definition: gtest_unittest.cc:5031
Definition: NonLinearOptimization.cpp:107
const ReturnType< internal::member_minCoeff >::Type minCoeff() const
Definition: VectorwiseOp.h:288
ExpressionType & operator*=(const DenseBase< OtherDerived > &other)
Multiples each subvector of *this by the vector other.
Definition: VectorwiseOp.h:463
Definition: VectorwiseOp.h:238
For Reverse, all columns are reversed; for PartialReduxExpr and VectorwiseOp, act on columns...
Definition: Constants.h:209
void normalize()
Normalize in-place each row or columns of the referenced matrix.
Definition: VectorwiseOp.h:548
const ReturnType< internal::member_blueNorm, RealScalar >::Type blueNorm() const
Definition: VectorwiseOp.h:329
EIGEN_STRONG_INLINE CwiseBinaryOp< internal::scalar_product_op< Scalar >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > 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:513
Definition: VectorwiseOp.h:178
const ReturnType< internal::member_any >::Type any() const
Definition: VectorwiseOp.h:378
ExpressionType & operator=(const DenseBase< OtherDerived > &other)
Copies the vector other to each subvector of *this.
Definition: VectorwiseOp.h:435
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
ExpressionType & operator-=(const DenseBase< OtherDerived > &other)
Substracts the vector other to each subvector of *this.
Definition: VectorwiseOp.h:454
Generic expression of a partially reduxed matrix.
Definition: ForwardDeclarations.h:211
Holds information about the various numeric (i.e.
Definition: NumTraits.h:88
Pseudo expression providing partial reduction operations.
Definition: ForwardDeclarations.h:212
const ReturnType< internal::member_sum >::Type sum() const
Definition: VectorwiseOp.h:357
const ReturnType< internal::member_stableNorm, RealScalar >::Type stableNorm() const
Definition: VectorwiseOp.h:338
const ReturnType< internal::member_maxCoeff >::Type maxCoeff() const
Definition: VectorwiseOp.h:300
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:53
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
const ReturnType< internal::member_squaredNorm, RealScalar >::Type squaredNorm() const
Definition: VectorwiseOp.h:310
const Replicate< ExpressionType,(IsVertical?Factor:1),(IsHorizontal?Factor:1)> replicate(Index factor=Factor) const
Definition: VectorwiseOp.h:425
Definition: XprHelper.h:32
Definition: XprHelper.h:350
ConstRowwiseReturnType rowwise() const
Definition: VectorwiseOp.h:624
Definition: VectorwiseOp.h:216
Definition: VectorwiseOp.h:135
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:107
const ReduxReturnType< BinaryOp >::Type redux(const BinaryOp &func=BinaryOp()) const
Definition: VectorwiseOp.h:276
Expression of the multiple replication of a matrix or vector.
Definition: Replicate.h:62
const ReturnType< internal::member_all >::Type all() const
Definition: VectorwiseOp.h:371
const Reverse< ExpressionType, Direction > reverse() const
Definition: VectorwiseOp.h:409
Definition: VectorwiseOp.h:186
const PartialReduxExpr< ExpressionType, internal::member_count< Index >, Direction > count() const
Definition: VectorwiseOp.h:388
const ReturnType< internal::member_hypotNorm, RealScalar >::Type hypotNorm() const
Definition: VectorwiseOp.h:347
EIGEN_STRONG_INLINE 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:488
For Reverse, all rows are reversed; for PartialReduxExpr and VectorwiseOp, act on rows...
Definition: Constants.h:212
const ReturnType< internal::member_prod >::Type prod() const
Definition: VectorwiseOp.h:398
Definition: benchGeometry.cpp:23
Definition: BandTriangularSolver.h:13
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:500
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:527
Definition: XprHelper.h:89
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:103
CwiseBinaryOp< internal::scalar_quotient_op< Scalar >, const ExpressionTypeNestedCleaned, const typename OppositeExtendedType< typename ReturnType< internal::member_norm, RealScalar >::Type >::Type > normalized() const
Definition: VectorwiseOp.h:542
ExpressionType & operator/=(const DenseBase< OtherDerived > &other)
Divides each subvector of *this by the vector other.
Definition: VectorwiseOp.h:474
Definition: Functors.h:150
const ReturnType< internal::member_norm, RealScalar >::Type norm() const
Definition: VectorwiseOp.h:320
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time, and that instead the value is stored in some runtime variable.
Definition: Constants.h:21
const ReturnType< internal::member_mean >::Type mean() const
Definition: VectorwiseOp.h:364
Expression of the reverse of a vector or matrix.
Definition: Reverse.h:70
Definition: VectorwiseOp.h:139
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Definition: ForwardDeclarations.h:17
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48
ConstColwiseReturnType colwise() const
Definition: VectorwiseOp.h:599
Definition: Homogeneous.h:61