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) {}
68 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
69 Index rows()
const EIGEN_NOEXCEPT {
return (Direction==
Vertical ? 1 : m_matrix.rows()); }
70 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
71 Index cols()
const EIGEN_NOEXCEPT {
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;
86#define EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(MEMBER,COST,VECTORIZABLE,BINARYOP) \
87 template <typename ResultType,typename Scalar> \
88 struct member_##MEMBER { \
89 EIGEN_EMPTY_STRUCT_CTOR(member_##MEMBER) \
90 typedef ResultType result_type; \
91 typedef BINARYOP<Scalar,Scalar> BinaryOp; \
92 template<int Size> struct Cost { enum { value = COST }; }; \
93 enum { Vectorizable = VECTORIZABLE }; \
94 template<typename XprType> \
95 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
96 ResultType operator()(const XprType& mat) const \
97 { return mat.MEMBER(); } \
98 BinaryOp binaryFunc() const { return BinaryOp(); } \
101#define EIGEN_MEMBER_FUNCTOR(MEMBER,COST) \
102 EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(MEMBER,COST,0,partial_redux_dummy_func)
119template <
int p,
typename ResultType,
typename Scalar>
121 typedef ResultType result_type;
122 enum { Vectorizable = 0 };
126 template<
typename XprType>
127 EIGEN_DEVICE_FUNC
inline ResultType operator()(
const XprType&
mat)
const
131template <
typename BinaryOpT,
typename Scalar>
135 BinaryOp(
const Scalar&,
const Scalar&)
140 EIGEN_DEVICE_FUNC
explicit member_redux(
const BinaryOp func) : m_functor(func) {}
141 template<
typename Derived>
143 {
return mat.redux(m_functor); }
144 const BinaryOp& binaryFunc()
const {
return m_functor; }
145 const BinaryOp m_functor;
190 typedef typename ExpressionType::Scalar Scalar;
191 typedef typename ExpressionType::RealScalar RealScalar;
194 typedef typename internal::remove_all<ExpressionTypeNested>::type ExpressionTypeNestedCleaned;
196 template<
template<
typename OutScalar,
typename InputScalar>
class Functor,
214 isVertical = (Direction==
Vertical) ? 1 : 0,
215 isHorizontal = (Direction==
Horizontal) ? 1 : 0
222 isVertical ? 1 : ExpressionType::RowsAtCompileTime,
223 isHorizontal ? 1 : ExpressionType::ColsAtCompileTime>
Type;
228 template<
typename OtherDerived>
233 EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(isVertical, OtherDerived::MaxColsAtCompileTime==1),
234 YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED)
235 EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(isHorizontal, OtherDerived::MaxRowsAtCompileTime==1),
236 YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED)
239 isVertical ? 1 : m_matrix.rows(),
240 isHorizontal ? 1 : m_matrix.cols());
245 isHorizontal ? 1 : ExpressionType::RowsAtCompileTime,
246 isVertical ? 1 : ExpressionType::ColsAtCompileTime>
Type;
251 template<
typename OtherDerived>
256 EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(isHorizontal, OtherDerived::MaxColsAtCompileTime==1),
257 YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED)
258 EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(isVertical, OtherDerived::MaxRowsAtCompileTime==1),
259 YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED)
262 isHorizontal ? 1 : m_matrix.rows(),
263 isVertical ? 1 : m_matrix.cols());
268 explicit inline VectorwiseOp(ExpressionType& matrix) : m_matrix(matrix) {}
272 inline const ExpressionType& _expression()
const {
return m_matrix; }
274 #ifdef EIGEN_PARSED_BY_DOXYGEN
278 random_access_iterator_type iterator;
280 random_access_iterator_type const_iterator;
282 typedef internal::subvector_stl_iterator<ExpressionType,
DirectionType(Direction)> iterator;
283 typedef internal::subvector_stl_iterator<
const ExpressionType,
DirectionType(Direction)> const_iterator;
284 typedef internal::subvector_stl_reverse_iterator<ExpressionType,
DirectionType(Direction)> reverse_iterator;
285 typedef internal::subvector_stl_reverse_iterator<
const ExpressionType,
DirectionType(Direction)> const_reverse_iterator;
334 template<
typename BinaryOp>
336 const typename ReduxReturnType<BinaryOp>::Type
337 redux(
const BinaryOp& func = BinaryOp())
const
339 eigen_assert(redux_length()>0 &&
"you are using an empty matrix");
343 typedef typename ReturnType<internal::member_minCoeff>::Type MinCoeffReturnType;
344 typedef typename ReturnType<internal::member_maxCoeff>::Type MaxCoeffReturnType;
347 typedef typename ReturnType<internal::member_blueNorm,RealScalar>::Type BlueNormReturnType;
348 typedef typename ReturnType<internal::member_stableNorm,RealScalar>::Type StableNormReturnType;
349 typedef typename ReturnType<internal::member_hypotNorm,RealScalar>::Type HypotNormReturnType;
350 typedef typename ReturnType<internal::member_sum>::Type SumReturnType;
352 typedef typename ReturnType<internal::member_all>::Type AllReturnType;
353 typedef typename ReturnType<internal::member_any>::Type AnyReturnType;
355 typedef typename ReturnType<internal::member_prod>::Type ProdReturnType;
378 eigen_assert(redux_length()>0 &&
"you are using an empty matrix");
397 eigen_assert(redux_length()>0 &&
"you are using an empty matrix");
488 {
return sum() / Scalar(Direction==
Vertical?m_matrix.rows():m_matrix.cols()); }
571 (_expression(),isVertical?factor:1,isHorizontal?factor:1);
577 template<
typename OtherDerived>
582 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType,
OtherDerived)
584 return m_matrix = extendedTo(other.derived());
588 template<
typename OtherDerived>
593 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType,
OtherDerived)
594 return m_matrix += extendedTo(other.derived());
598 template<
typename OtherDerived>
603 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType,
OtherDerived)
604 return m_matrix -= extendedTo(other.derived());
608 template<
typename OtherDerived>
613 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
614 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType,
OtherDerived)
615 m_matrix *= extendedTo(other.derived());
620 template<
typename OtherDerived>
625 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
626 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType,
OtherDerived)
627 m_matrix /= extendedTo(other.derived());
632 template<
typename OtherDerived> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
634 const ExpressionTypeNestedCleaned,
635 const typename ExtendedType<OtherDerived>::Type>
639 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType,
OtherDerived)
640 return m_matrix + extendedTo(other.derived());
644 template<
typename OtherDerived>
647 const ExpressionTypeNestedCleaned,
648 const typename ExtendedType<OtherDerived>::Type>
652 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType,
OtherDerived)
653 return m_matrix - extendedTo(other.derived());
658 template<
typename OtherDerived> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
660 const ExpressionTypeNestedCleaned,
661 const typename ExtendedType<OtherDerived>::Type>
666 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
667 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType,
OtherDerived)
668 return m_matrix * extendedTo(other.derived());
673 template<
typename OtherDerived>
676 const ExpressionTypeNestedCleaned,
677 const typename ExtendedType<OtherDerived>::Type>
681 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
682 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType,
OtherDerived)
683 return m_matrix / extendedTo(other.derived());
692 const ExpressionTypeNestedCleaned,
693 const typename OppositeExtendedType<NormReturnType>::Type>
694 normalized()
const {
return m_matrix.cwiseQuotient(extendedToOpposite(this->
norm())); }
712 typedef typename ExpressionType::PlainObject CrossReturnType;
713 template<
typename OtherDerived>
720 HNormalized_SizeMinusOne = HNormalized_Size==
Dynamic ?
Dynamic : HNormalized_Size-1
722 typedef Block<
const ExpressionType,
723 Direction==
Vertical ? int(HNormalized_SizeMinusOne)
724 : int(internal::traits<ExpressionType>::RowsAtCompileTime),
725 Direction==
Horizontal ? int(HNormalized_SizeMinusOne)
726 : int(internal::traits<ExpressionType>::ColsAtCompileTime)>
728 typedef Block<
const ExpressionType,
729 Direction==
Vertical ? 1 : int(internal::traits<ExpressionType>::RowsAtCompileTime),
730 Direction==
Horizontal ? 1 : int(internal::traits<ExpressionType>::ColsAtCompileTime)>
732 typedef CwiseBinaryOp<internal::scalar_quotient_op<typename internal::traits<ExpressionType>::Scalar>,
733 const HNormalized_Block,
734 const Replicate<HNormalized_Factors,
735 Direction==
Vertical ? HNormalized_SizeMinusOne : 1,
736 Direction==
Horizontal ? HNormalized_SizeMinusOne : 1> >
737 HNormalizedReturnType;
742# ifdef EIGEN_VECTORWISEOP_PLUGIN
743# include EIGEN_VECTORWISEOP_PLUGIN
747 Index redux_length()
const
749 return Direction==
Vertical ? m_matrix.rows() : m_matrix.cols();
751 ExpressionTypeNested m_matrix;
761template<
typename Derived>
762EIGEN_DEVICE_FUNC
inline typename DenseBase<Derived>::ColwiseReturnType
775template<
typename Derived>
EIGEN_DEVICE_FUNC ConstColwiseReturnType colwise() const
Definition DenseBase.h:562
EIGEN_DEVICE_FUNC ConstRowwiseReturnType rowwise() const
Definition DenseBase.h:550
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
Generic expression of a partially reduxed matrix.
Definition VectorwiseOp.h:58
Expression of the multiple replication of a matrix or vector.
Definition Replicate.h:63
Pseudo expression providing broadcasting and partial reduction operations.
Definition VectorwiseOp.h:187
EIGEN_DEVICE_FUNC const ConstReverseReturnType reverse() const
Definition VectorwiseOp.h:541
EIGEN_DEVICE_FUNC const MinCoeffReturnType minCoeff() const
Definition VectorwiseOp.h:376
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:649
EIGEN_DEVICE_FUNC ReverseReturnType reverse()
Definition VectorwiseOp.h:549
EIGEN_DEVICE_FUNC const NormReturnType norm() const
Definition VectorwiseOp.h:422
EIGEN_DEVICE_FUNC void normalize()
Normalize in-place each row or columns of the referenced matrix.
Definition VectorwiseOp.h:700
EIGEN_DEVICE_FUNC const SumReturnType sum() const
Definition VectorwiseOp.h:479
const_reverse_iterator crend() const
const version of rend()
Definition VectorwiseOp.h:322
EIGEN_DEVICE_FUNC const AllReturnType all() const
Definition VectorwiseOp.h:496
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:210
EIGEN_DEVICE_FUNC CwiseBinaryOp< internal::scalar_quotient_op< Scalar >, const ExpressionTypeNestedCleaned, const typename OppositeExtendedType< NormReturnType >::Type > normalized() const
Definition VectorwiseOp.h:694
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:663
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:636
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:678
EIGEN_DEVICE_FUNC const MaxCoeffReturnType maxCoeff() const
Definition VectorwiseOp.h:395
Eigen::Index Index
Definition VectorwiseOp.h:192
const_iterator cend() const
const version of end()
Definition VectorwiseOp.h:313
EIGEN_DEVICE_FUNC const ProdReturnType prod() const
Definition VectorwiseOp.h:529
EIGEN_DEVICE_FUNC const SquaredNormReturnType squaredNorm() const
Definition VectorwiseOp.h:410
EIGEN_DEVICE_FUNC const ReplicateReturnType replicate(Index factor) const
Definition Replicate.h:134
EIGEN_DEVICE_FUNC ExpressionType & operator/=(const DenseBase< OtherDerived > &other)
Divides each subvector of *this by the vector other.
Definition VectorwiseOp.h:622
EIGEN_DEVICE_FUNC const AnyReturnType any() const
Definition VectorwiseOp.h:505
const_iterator cbegin() const
const version of begin()
Definition VectorwiseOp.h:295
reverse_iterator rbegin()
returns a reverse iterator to the last row (rowwise) or column (colwise) of the nested expression.
Definition VectorwiseOp.h:300
EIGEN_DEVICE_FUNC const HypotNormReturnType hypotNorm() const
Definition VectorwiseOp.h:468
iterator end()
returns an iterator to the row (resp.
Definition VectorwiseOp.h:309
const_reverse_iterator rbegin() const
const version of rbegin()
Definition VectorwiseOp.h:302
reverse_iterator rend()
returns a reverse iterator to the row (resp.
Definition VectorwiseOp.h:318
const_iterator begin() const
const version of begin()
Definition VectorwiseOp.h:293
iterator begin()
returns an iterator to the first row (rowwise) or column (colwise) of the nested expression.
Definition VectorwiseOp.h:291
EIGEN_DEVICE_FUNC const CountReturnType count() const
Definition VectorwiseOp.h:518
const Replicate< ExpressionType, isVertical *Factor+isHorizontal, isHorizontal *Factor+isVertical > EIGEN_DEVICE_FUNC replicate(Index factor=Factor) const
Definition VectorwiseOp.h:568
EIGEN_DEVICE_FUNC ExpressionType & operator=(const DenseBase< OtherDerived > &other)
Copies the vector other to each subvector of *this.
Definition VectorwiseOp.h:579
const_iterator end() const
const version of end()
Definition VectorwiseOp.h:311
EIGEN_DEVICE_FUNC ExpressionType & operator*=(const DenseBase< OtherDerived > &other)
Multiples each subvector of *this by the vector other.
Definition VectorwiseOp.h:610
EIGEN_DEVICE_FUNC const LpNormReturnType< p >::Type lpNorm() const
Definition VectorwiseOp.h:435
EIGEN_DEVICE_FUNC const StableNormReturnType stableNorm() const
Definition VectorwiseOp.h:457
EIGEN_DEVICE_FUNC ExpressionType & operator+=(const DenseBase< OtherDerived > &other)
Adds the vector other to each subvector of *this.
Definition VectorwiseOp.h:590
EIGEN_DEVICE_FUNC const BlueNormReturnType blueNorm() const
Definition VectorwiseOp.h:446
EIGEN_DEVICE_FUNC const MeanReturnType mean() const
Definition VectorwiseOp.h:487
const_reverse_iterator crbegin() const
const version of rbegin()
Definition VectorwiseOp.h:304
EIGEN_DEVICE_FUNC ExpressionType & operator-=(const DenseBase< OtherDerived > &other)
Substracts the vector other to each subvector of *this.
Definition VectorwiseOp.h:600
EIGEN_DEVICE_FUNC const ReduxReturnType< BinaryOp >::Type redux(const BinaryOp &func=BinaryOp()) const
Definition VectorwiseOp.h:337
const_reverse_iterator rend() const
const version of rend()
Definition VectorwiseOp.h:320
Definition XprHelper.h:110
Definition StlIterators.h:314
Definition StlIterators.h:362
EIGEN_DEVICE_FUNC HomogeneousReturnType homogeneous() const
\geometry_module
Definition Homogeneous.h:150
EIGEN_DEVICE_FUNC const HNormalizedReturnType hnormalized() const
\geometry_module
Definition Homogeneous.h:198
EIGEN_DEVICE_FUNC const CrossReturnType cross(const MatrixBase< OtherDerived > &other) const
\geometry_module
Definition OrthoMethods.h:111
DirectionType
Enum containing possible values for the Direction parameter of Reverse, PartialReduxExpr and Vectorwi...
Definition Constants.h:261
@ Horizontal
For Reverse, all rows are reversed; for PartialReduxExpr and VectorwiseOp, act on rows.
Definition Constants.h:267
@ Vertical
For Reverse, all columns are reversed; for PartialReduxExpr and VectorwiseOp, act on columns.
Definition Constants.h:264
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition Constants.h:66
Namespace containing all symbols from the Eigen library.
Definition LDLT.h:16
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time,...
Definition Constants.h:22
Holds information about the various numeric (i.e.
Definition NumTraits.h:236
Definition VectorwiseOp.h:220
Definition VectorwiseOp.h:359
Definition VectorwiseOp.h:243
Definition VectorwiseOp.h:206
Definition VectorwiseOp.h:198
Definition XprHelper.h:484
Definition XprHelper.h:176
Definition VectorwiseOp.h:124
Definition VectorwiseOp.h:120
Definition VectorwiseOp.h:139
Definition VectorwiseOp.h:132
Definition BinaryFunctors.h:172
Definition BinaryFunctors.h:139
Definition BinaryFunctors.h:71
Definition BinaryFunctors.h:33
Definition ForwardDeclarations.h:17
Definition VectorwiseOp.h:84