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;
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
55 template<
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;
81 const MemberOp m_functor;
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(); } \ 113 template <
int p,
typename ResultType>
115 typedef ResultType result_type;
116 template<
typename Scalar,
int Size>
struct Cost 119 template<
typename XprType>
120 EIGEN_DEVICE_FUNC
inline ResultType operator()(
const XprType& mat)
const 121 {
return mat.template lpNorm<p>(); }
124 template <
typename BinaryOp,
typename Scalar>
127 BinaryOp(
const Scalar&,
const Scalar&)
129 template<
typename _Scalar,
int Size>
struct Cost 131 EIGEN_DEVICE_FUNC
explicit member_redux(
const BinaryOp
func) : m_functor(func) {}
132 template<
typename Derived>
134 {
return mat.redux(m_functor); }
135 const BinaryOp m_functor;
156 template<
typename ExpressionType,
int Direction>
class VectorwiseOp 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
191 typename ExpressionType::ColXpr,
192 typename ExpressionType::RowXpr>::type
SubVector;
196 SubVector subVector(Index i)
198 return SubVector(m_matrix.derived(),i);
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>
305 {
return MinCoeffReturnType(_expression()); }
318 {
return MaxCoeffReturnType(_expression()); }
330 {
return SquaredNormReturnType(_expression()); }
341 const NormReturnType
norm()
const 342 {
return NormReturnType(_expression()); }
366 {
return BlueNormReturnType(_expression()); }
377 {
return StableNormReturnType(_expression()); }
388 {
return HypotNormReturnType(_expression()); }
398 const SumReturnType
sum()
const 399 {
return SumReturnType(_expression()); }
406 const MeanReturnType
mean()
const 407 {
return MeanReturnType(_expression()); }
415 const AllReturnType
all()
const 416 {
return AllReturnType(_expression()); }
424 const AnyReturnType
any()
const 425 {
return AnyReturnType(_expression()); }
438 {
return CountReturnType(_expression()); }
448 const ProdReturnType
prod()
const 449 {
return ProdReturnType(_expression()); }
461 {
return ConstReverseReturnType( _expression() ); }
469 {
return ReverseReturnType( _expression() ); }
473 const ReplicateReturnType replicate(Index factor)
const;
490 (_expression(),isVertical?factor:1,isHorizontal?factor:1);
496 template<
typename OtherDerived>
500 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
501 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
503 return const_cast<ExpressionType&
>(m_matrix = extendedTo(other.derived()));
507 template<
typename OtherDerived>
511 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
512 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
513 return const_cast<ExpressionType&
>(m_matrix += extendedTo(other.derived()));
517 template<
typename OtherDerived>
521 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
522 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
523 return const_cast<ExpressionType&
>(m_matrix -= extendedTo(other.derived()));
527 template<
typename OtherDerived>
531 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
532 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
533 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
534 m_matrix *= extendedTo(other.derived());
535 return const_cast<ExpressionType&
>(m_matrix);
539 template<
typename OtherDerived>
543 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
544 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
545 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
546 m_matrix /= extendedTo(other.derived());
547 return const_cast<ExpressionType&
>(m_matrix);
551 template<
typename OtherDerived> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
553 const ExpressionTypeNestedCleaned,
557 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
558 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
559 return m_matrix + extendedTo(other.derived());
563 template<
typename OtherDerived>
566 const ExpressionTypeNestedCleaned,
570 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
571 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
572 return m_matrix - extendedTo(other.derived());
577 template<
typename OtherDerived> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
579 const ExpressionTypeNestedCleaned,
584 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
585 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
586 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
587 return m_matrix * extendedTo(other.derived());
592 template<
typename OtherDerived>
595 const ExpressionTypeNestedCleaned,
599 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
600 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
601 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
602 return m_matrix / extendedTo(other.derived());
610 CwiseBinaryOp<internal::scalar_quotient_op<Scalar>,
611 const ExpressionTypeNestedCleaned,
613 normalized()
const {
return m_matrix.cwiseQuotient(extendedToOpposite(this->norm())); }
620 m_matrix = this->normalized();
623 EIGEN_DEVICE_FUNC
inline void reverseInPlace();
629 HomogeneousReturnType homogeneous()
const;
631 typedef typename ExpressionType::PlainObject CrossReturnType;
632 template<
typename OtherDerived>
639 HNormalized_SizeMinusOne = HNormalized_Size==
Dynamic ?
Dynamic : HNormalized_Size-1
641 typedef Block<
const ExpressionType,
642 Direction==
Vertical ? int(HNormalized_SizeMinusOne)
644 Direction==
Horizontal ? int(HNormalized_SizeMinusOne)
647 typedef Block<
const ExpressionType,
654 Direction==
Vertical ? HNormalized_SizeMinusOne : 1,
655 Direction==
Horizontal ? HNormalized_SizeMinusOne : 1> >
662 ExpressionTypeNested m_matrix;
672 template<
typename Derived>
686 template<
typename Derived>
695 #endif // EIGEN_PARTIAL_REDUX_H Definition: NonLinearOptimization.cpp:108
EIGEN_DEVICE_FUNC ExpressionType & operator/=(const DenseBase< OtherDerived > &other)
Divides each subvector of *this by the vector other.
Definition: VectorwiseOp.h:541
EIGEN_DEVICE_FUNC void normalize()
Normalize in-place each row or columns of the referenced matrix.
Definition: VectorwiseOp.h:619
EIGEN_DEVICE_FUNC const ConstReverseReturnType reverse() const
Definition: VectorwiseOp.h:460
EIGEN_DEVICE_FUNC const SumReturnType sum() const
Definition: VectorwiseOp.h:398
Definition: VectorwiseOp.h:230
For Reverse, all columns are reversed; for PartialReduxExpr and VectorwiseOp, act on columns...
Definition: Constants.h:265
EIGEN_DEVICE_FUNC const MaxCoeffReturnType maxCoeff() const
Definition: VectorwiseOp.h:317
Eigen::Index Index
Definition: VectorwiseOp.h:162
EIGEN_DEVICE_FUNC ConstColwiseReturnType colwise() const
Definition: DenseBase.h:506
Definition: VectorwiseOp.h:167
Definition: VectorwiseOp.h:116
EIGEN_DEVICE_FUNC ReverseReturnType reverse()
Definition: VectorwiseOp.h:468
EIGEN_DEVICE_FUNC const LpNormReturnType< p >::Type lpNorm() const
Definition: VectorwiseOp.h:354
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
EIGEN_DEVICE_FUNC const StableNormReturnType stableNorm() const
Definition: VectorwiseOp.h:376
Generic expression of a partially reduxed matrix.
Definition: ForwardDeclarations.h:244
Holds information about the various numeric (i.e.
Definition: NumTraits.h:150
Definition: VectorwiseOp.h:114
Pseudo expression providing partial reduction operations.
Definition: ForwardDeclarations.h:245
EIGEN_DEVICE_FUNC const HypotNormReturnType hypotNorm() const
Definition: VectorwiseOp.h:387
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:613
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:61
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
Definition: XprHelper.h:89
Definition: XprHelper.h:463
EIGEN_DEVICE_FUNC const MeanReturnType mean() const
Definition: VectorwiseOp.h:406
Definition: VectorwiseOp.h:207
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:597
Definition: VectorwiseOp.h:125
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:77
EIGEN_DEVICE_FUNC ExpressionType & operator-=(const DenseBase< OtherDerived > &other)
Substracts the vector other to each subvector of *this.
Definition: VectorwiseOp.h:519
EIGEN_DEVICE_FUNC const CountReturnType count() const
Definition: VectorwiseOp.h:437
EIGEN_DEVICE_FUNC ExpressionType & operator+=(const DenseBase< OtherDerived > &other)
Adds the vector other to each subvector of *this.
Definition: VectorwiseOp.h:509
EIGEN_DEVICE_FUNC const AnyReturnType any() const
Definition: VectorwiseOp.h:424
EIGEN_DEVICE_FUNC const SquaredNormReturnType squaredNorm() const
Definition: VectorwiseOp.h:329
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Expression of the multiple replication of a matrix or vector.
Definition: Replicate.h:61
EIGEN_DEVICE_FUNC ConstRowwiseReturnType rowwise() const
Definition: DenseBase.h:494
EIGEN_DEVICE_FUNC const BlueNormReturnType blueNorm() const
Definition: VectorwiseOp.h:365
Definition: VectorwiseOp.h:175
Definition: VectorwiseOp.h:290
For Reverse, all rows are reversed; for PartialReduxExpr and VectorwiseOp, act on rows...
Definition: Constants.h:268
Definition: benchGeometry.cpp:23
EIGEN_DEVICE_FUNC const ProdReturnType prod() const
Definition: VectorwiseOp.h:448
Definition: BandTriangularSolver.h:13
Definition: XprHelper.h:146
EIGEN_DEVICE_FUNC const ReduxReturnType< BinaryOp >::Type redux(const BinaryOp &func=BinaryOp()) const
Definition: VectorwiseOp.h:271
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:103
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC CwiseBinaryOp< internal::scalar_sum_op< Scalar, typename OtherDerived::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:555
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:582
EIGEN_DEVICE_FUNC const MinCoeffReturnType minCoeff() const
Definition: VectorwiseOp.h:304
EIGEN_DEVICE_FUNC ExpressionType & operator=(const DenseBase< OtherDerived > &other)
Copies the vector other to each subvector of *this.
Definition: VectorwiseOp.h:498
EIGEN_DEVICE_FUNC const AllReturnType all() const
Definition: VectorwiseOp.h:415
EIGEN_DEVICE_FUNC CwiseBinaryOp< internal::scalar_difference_op< Scalar, typename OtherDerived::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:568
Definition: ForwardDeclarations.h:207
EIGEN_DEVICE_FUNC ExpressionType & operator*=(const DenseBase< OtherDerived > &other)
Multiples each subvector of *this by the vector other.
Definition: VectorwiseOp.h:529
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
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:55
Expression of the reverse of a vector or matrix.
Definition: Reverse.h:63
EIGEN_DEVICE_FUNC const NormReturnType norm() const
Definition: VectorwiseOp.h:341
Definition: VectorwiseOp.h:129
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Definition: ForwardDeclarations.h:17
const Replicate< ExpressionType, isVertical *Factor+isHorizontal, isHorizontal *Factor+isVertical > EIGEN_DEVICE_FUNC replicate(Index factor=Factor) const
Definition: VectorwiseOp.h:487
Definition: ForwardDeclarations.h:278