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;
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) {}
77 const MemberOp&
functor()
const {
return m_functor; }
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) 119 template <
int p,
typename ResultType,
typename Scalar>
122 enum { Vectorizable = 0 };
126 template<
typename XprType>
128 {
return mat.template lpNorm<p>(); }
131 template <
typename BinaryOpT,
typename Scalar>
141 template<
typename Derived>
143 {
return mat.
redux(m_functor); }
186 template<
typename ExpressionType,
int Direction>
class VectorwiseOp 196 template<
template<
typename OutScalar,
typename InputScalar>
class Functor,
222 isVertical ? 1 : ExpressionType::RowsAtCompileTime,
223 isHorizontal ? 1 : ExpressionType::ColsAtCompileTime>
Type;
228 template<
typename OtherDerived>
234 YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED)
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>
257 YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED)
259 YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED)
262 isHorizontal ? 1 : m_matrix.rows(),
263 isVertical ? 1 : m_matrix.cols());
272 inline const ExpressionType&
_expression()
const {
return m_matrix; }
274 #ifdef EIGEN_PARSED_BY_DOXYGEN 278 random_access_iterator_type
iterator;
291 iterator
begin() {
return iterator (m_matrix, 0); }
293 const_iterator
begin()
const {
return const_iterator(m_matrix, 0); }
295 const_iterator
cbegin()
const {
return const_iterator(m_matrix, 0); }
318 reverse_iterator
rend() {
return reverse_iterator (m_matrix, -1); }
320 const_reverse_iterator
rend()
const {
return const_reverse_iterator (m_matrix, -1); }
322 const_reverse_iterator
crend()
const {
return const_reverse_iterator (m_matrix, -1); }
334 template<
typename BinaryOp>
339 eigen_assert(redux_length()>0 &&
"you are using an empty matrix");
378 eigen_assert(redux_length()>0 &&
"you are using an empty matrix");
379 return MinCoeffReturnType(_expression());
397 eigen_assert(redux_length()>0 &&
"you are using an empty matrix");
398 return MaxCoeffReturnType(_expression());
411 {
return SquaredNormReturnType(m_matrix.cwiseAbs2()); }
422 const NormReturnType
norm()
const 423 {
return NormReturnType(squaredNorm()); }
447 {
return BlueNormReturnType(_expression()); }
458 {
return StableNormReturnType(_expression()); }
469 {
return HypotNormReturnType(_expression()); }
479 const SumReturnType
sum()
const 480 {
return SumReturnType(_expression()); }
487 const MeanReturnType
mean()
const 488 {
return sum() /
Scalar(Direction==
Vertical?m_matrix.rows():m_matrix.cols()); }
496 const AllReturnType
all()
const 497 {
return AllReturnType(_expression()); }
505 const AnyReturnType
any()
const 506 {
return AnyReturnType(_expression()); }
519 {
return CountReturnType(_expression()); }
529 const ProdReturnType
prod()
const 530 {
return ProdReturnType(_expression()); }
542 {
return ConstReverseReturnType( _expression() ); }
550 {
return ReverseReturnType( _expression() ); }
554 const ReplicateReturnType
replicate(Index factor)
const;
571 (_expression(),isVertical?factor:1,isHorizontal?factor:1);
577 template<
typename OtherDerived>
584 return m_matrix = extendedTo(other.derived());
588 template<
typename OtherDerived>
594 return m_matrix += extendedTo(other.derived());
598 template<
typename OtherDerived>
604 return m_matrix -= extendedTo(other.derived());
608 template<
typename OtherDerived>
615 m_matrix *= extendedTo(other.derived());
620 template<
typename OtherDerived>
627 m_matrix /= extendedTo(other.derived());
634 const ExpressionTypeNestedCleaned,
640 return m_matrix + extendedTo(other.derived());
644 template<
typename OtherDerived>
647 const ExpressionTypeNestedCleaned,
653 return m_matrix - extendedTo(other.derived());
660 const ExpressionTypeNestedCleaned,
668 return m_matrix * extendedTo(other.derived());
673 template<
typename OtherDerived>
676 const ExpressionTypeNestedCleaned,
683 return m_matrix / extendedTo(other.derived());
691 CwiseBinaryOp<internal::scalar_quotient_op<Scalar>,
692 const ExpressionTypeNestedCleaned,
694 normalized()
const {
return m_matrix.cwiseQuotient(extendedToOpposite(this->norm())); }
701 m_matrix = this->normalized();
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,
735 Direction==
Vertical ? HNormalized_SizeMinusOne : 1,
736 Direction==
Horizontal ? HNormalized_SizeMinusOne : 1> >
742 # ifdef EIGEN_VECTORWISEOP_PLUGIN 743 # include EIGEN_VECTORWISEOP_PLUGIN 749 return Direction==
Vertical ? m_matrix.rows() : m_matrix.cols();
761 template<
typename Derived>
775 template<
typename Derived>
784 #endif // EIGEN_PARTIAL_REDUX_H const_iterator end() const
internal::remove_all< ExpressionTypeNested >::type ExpressionTypeNestedCleaned
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index subVectors() const
EIGEN_DEVICE_FUNC ResultType operator()(const XprType &mat) const
#define EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(EXPR, SCALAR, OPNAME)
EIGEN_DEVICE_FUNC ExpressionType & operator/=(const DenseBase< OtherDerived > &other)
EIGEN_DEVICE_FUNC void normalize()
#define EIGEN_STRONG_INLINE
EIGEN_DEVICE_FUNC const ConstReverseReturnType reverse() const
ReturnType< internal::member_sum >::Type SumReturnType
EIGEN_DEVICE_FUNC PartialReduxExpr(const MatrixType &mat, const MemberOp &func=MemberOp())
static const Eigen::internal::all_t all
const BinaryOp & binaryFunc() const
PartialReduxExpr< ExpressionType, Functor< ReturnScalar, Scalar >, Direction > Type
EIGEN_DEVICE_FUNC const SumReturnType sum() const
reverse_iterator rbegin()
const_reverse_iterator rbegin() const
ReturnType< internal::member_stableNorm, RealScalar >::Type StableNormReturnType
CwiseUnaryOp< internal::scalar_sqrt_op< RealScalar >, const SquaredNormReturnType > NormReturnType
EIGEN_DEVICE_FUNC const MaxCoeffReturnType maxCoeff() const
ReturnType< internal::member_minCoeff >::Type MinCoeffReturnType
EIGEN_DEVICE_FUNC ConstColwiseReturnType colwise() const
ExpressionType::RealScalar RealScalar
EIGEN_DEVICE_FUNC ReverseReturnType reverse()
EIGEN_DONT_INLINE T::Scalar hypotNorm(T &v)
EIGEN_DEVICE_FUNC const LpNormReturnType< p >::Type lpNorm() const
Namespace containing all symbols from the Eigen library.
EIGEN_DEVICE_FUNC const StableNormReturnType stableNorm() const
result_of< BinaryOp(const Scalar &, const Scalar &) >::type result_type
internal::subvector_stl_iterator< const ExpressionType, DirectionType(Direction)> const_iterator
Generic expression of a partially reduxed matrix.
Replicate< ExpressionType,(isVertical?Dynamic:1),(isHorizontal?Dynamic:1)> ReplicateReturnType
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Pseudo expression providing broadcasting and partial reduction operations.
EIGEN_DEVICE_FUNC const HypotNormReturnType hypotNorm() const
EIGEN_DEVICE_FUNC const ExpressionType & _expression() const
ReturnType< internal::member_any >::Type AnyReturnType
EIGEN_DEVICE_FUNC Scalar redux(const BinaryOp &func) const
EIGEN_DEVICE_FUNC ExtendedType< OtherDerived >::Type extendedTo(const DenseBase< OtherDerived > &other) const
const unsigned int RowMajorBit
Base class for all dense matrices, vectors, and arrays.
#define EIGEN_IMPLIES(a, b)
ReturnType< internal::member_hypotNorm, RealScalar >::Type HypotNormReturnType
internal::ref_selector< ExpressionType >::non_const_type ExpressionTypeNested
EIGEN_DEVICE_FUNC const MeanReturnType mean() const
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
ReturnType< internal::member_all >::Type AllReturnType
EIGEN_DEVICE_FUNC CwiseBinaryOp< internal::scalar_quotient_op< Scalar >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > operator/(const DenseBase< OtherDerived > &other) const
internal::subvector_stl_iterator< ExpressionType, DirectionType(Direction)> iterator
EIGEN_DEVICE_FUNC VectorwiseOp(ExpressionType &matrix)
Generic expression where a coefficient-wise binary operator is applied to two expressions.
EIGEN_DEVICE_FUNC ExpressionType & operator-=(const DenseBase< OtherDerived > &other)
EIGEN_DEVICE_FUNC const CountReturnType count() const
void replicate(const MatrixType &m)
MemberOp::result_type Scalar
EIGEN_DEVICE_FUNC ExpressionType & operator+=(const DenseBase< OtherDerived > &other)
EIGEN_DEVICE_FUNC const AnyReturnType any() const
MatrixType::Nested m_matrix
Point3 cross(const Point3 &p, const Point3 &q, OptionalJacobian< 3, 3 > H1, OptionalJacobian< 3, 3 > H2)
cross product
EIGEN_DEVICE_FUNC OppositeExtendedType< OtherDerived >::Type extendedToOpposite(const DenseBase< OtherDerived > &other) const
PartialReduxExpr< const CwiseUnaryOp< internal::scalar_abs2_op< Scalar >, const ExpressionTypeNestedCleaned >, internal::member_sum< RealScalar, RealScalar >, Direction > SquaredNormReturnType
EIGEN_DEVICE_FUNC const SquaredNormReturnType squaredNorm() const
Reverse< const ExpressionType, Direction > ConstReverseReturnType
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
const_reverse_iterator rend() const
Expression of the multiple replication of a matrix or vector.
EIGEN_DEVICE_FUNC ConstRowwiseReturnType rowwise() const
EIGEN_DEVICE_FUNC member_redux(const BinaryOp func)
ExpressionTypeNested m_matrix
EIGEN_DEVICE_FUNC const BlueNormReturnType blueNorm() const
EIGEN_DONT_INLINE T::Scalar stableNorm(T &v)
Index redux_length() const
EIGEN_DEVICE_FUNC result_type operator()(const DenseBase< Derived > &mat) const
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
Reverse< ExpressionType, Direction > ReverseReturnType
EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(sum,(Size-1) *NumTraits< Scalar >::AddCost, 1, internal::scalar_sum_op)
NumTraits< Scalar >::Real RealScalar
#define EIGEN_STATIC_ASSERT_ARRAYXPR(Derived)
MatrixType::Scalar InputScalar
const_iterator cend() const
EIGEN_DEVICE_FUNC MatrixType::Nested nestedExpression() const
Homogeneous< ExpressionType, Direction > HomogeneousReturnType
EIGEN_DEVICE_FUNC const MemberOp & functor() const
#define EIGEN_DEVICE_FUNC
EIGEN_DEVICE_FUNC const ProdReturnType prod() const
const_iterator begin() const
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
const_iterator cbegin() const
ExpressionType::Scalar Scalar
PartialReduxExpr< ExpressionType, internal::member_lpnorm< p, RealScalar, Scalar >, Direction > Type
EIGEN_DEVICE_FUNC const ReduxReturnType< BinaryOp >::Type redux(const BinaryOp &func=BinaryOp()) const
Expression of a fixed-size or dynamic-size block.
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
EIGEN_DEVICE_FUNC member_lpnorm()
#define EIGEN_STATIC_ASSERT_SAME_XPR_KIND(Derived1, Derived2)
const_reverse_iterator crbegin() const
internal::subvector_stl_reverse_iterator< ExpressionType, DirectionType(Direction)> reverse_iterator
const_reverse_iterator crend() const
traits< MatrixType >::XprKind XprKind
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
ReturnType< internal::member_prod >::Type ProdReturnType
EIGEN_DEVICE_FUNC const MinCoeffReturnType minCoeff() const
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
EIGEN_DEVICE_FUNC ExpressionType & operator=(const DenseBase< OtherDerived > &other)
internal::subvector_stl_reverse_iterator< const ExpressionType, DirectionType(Direction)> const_reverse_iterator
EIGEN_DEVICE_FUNC const AllReturnType all() const
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
EIGEN_MEMBER_FUNCTOR(norm,(Size+5) *NumTraits< Scalar >::MulCost+(Size-1) *NumTraits< Scalar >::AddCost)
EIGEN_DEVICE_FUNC ExpressionType & operator*=(const DenseBase< OtherDerived > &other)
PartialReduxExpr< ExpressionType, internal::member_count< Index, Scalar >, Direction > CountReturnType
EIGEN_DONT_INLINE T::Scalar blueNorm(T &v)
Generic expression where a coefficient-wise unary operator is applied to an expression.
Replicate< OtherDerived, isVertical ? 1 :ExpressionType::RowsAtCompileTime, isHorizontal ? 1 :ExpressionType::ColsAtCompileTime > Type
Block< const ExpressionType, Direction==Vertical ? 1 :int(internal::traits< ExpressionType >::RowsAtCompileTime), Direction==Horizontal ? 1 :int(internal::traits< ExpressionType >::ColsAtCompileTime)> HNormalized_Factors
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
PartialReduxExpr< ExpressionType, internal::member_redux< BinaryOp, Scalar >, Direction > Type
ReturnType< internal::member_blueNorm, RealScalar >::Type BlueNormReturnType
Expression of the reverse of a vector or matrix.
EIGEN_DEVICE_FUNC CwiseBinaryOp< internal::scalar_quotient_op< Scalar >, const ExpressionTypeNestedCleaned, const typename OppositeExtendedType< NormReturnType >::Type > normalized() const
EIGEN_DEVICE_FUNC const NormReturnType norm() const
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
ExpressionType::PlainObject CrossReturnType
Base class for all dense matrices, vectors, and expressions.
ReturnType< internal::member_maxCoeff >::Type MaxCoeffReturnType
internal::dense_xpr_base< PartialReduxExpr >::type Base
const Replicate< ExpressionType, isVertical *Factor+isHorizontal, isHorizontal *Factor+isVertical > EIGEN_DEVICE_FUNC replicate(Index factor=Factor) const
Expression of one (or a set of) homogeneous vector(s)
const Product< Lhs, Rhs > prod(const Lhs &lhs, const Rhs &rhs)
Replicate< OtherDerived, isHorizontal ? 1 :ExpressionType::RowsAtCompileTime, isVertical ? 1 :ExpressionType::ColsAtCompileTime > Type