12#ifndef EIGEN_PARTIAL_REDUX_H
13#define EIGEN_PARTIAL_REDUX_H
16#include "./InternalHeaderCheck.h"
36template <
typename MatrixType,
typename MemberOp,
int Direction>
41template <
typename MatrixType,
typename MemberOp,
int Direction>
42struct traits<PartialReduxExpr<MatrixType, MemberOp, Direction>> : traits<MatrixType> {
43 using Scalar =
typename MemberOp::result_type;
44 using StorageKind =
typename traits<MatrixType>::StorageKind;
45 using XprKind =
typename traits<MatrixType>::XprKind;
46 using InputScalar =
typename MatrixType::Scalar;
48 RowsAtCompileTime = Direction ==
Vertical ? 1 : MatrixType::RowsAtCompileTime,
49 ColsAtCompileTime = Direction ==
Horizontal ? 1 : MatrixType::ColsAtCompileTime,
50 MaxRowsAtCompileTime = Direction ==
Vertical ? 1 : MatrixType::MaxRowsAtCompileTime,
51 MaxColsAtCompileTime = Direction ==
Horizontal ? 1 : MatrixType::MaxColsAtCompileTime,
53 TraversalSize = Direction ==
Vertical ? MatrixType::RowsAtCompileTime : MatrixType::ColsAtCompileTime
58template <
typename MatrixType,
typename MemberOp,
int Direction>
59class PartialReduxExpr :
public internal::dense_xpr_base<PartialReduxExpr<MatrixType, MemberOp, Direction>>::type,
60 internal::no_assignment_operator {
62 using Base =
typename internal::dense_xpr_base<PartialReduxExpr>::type;
63 EIGEN_DENSE_PUBLIC_INTERFACE(PartialReduxExpr)
65 EIGEN_DEVICE_FUNC
explicit PartialReduxExpr(
const MatrixType& mat,
const MemberOp& func = MemberOp())
66 : m_matrix(mat), m_functor(func) {}
68 EIGEN_DEVICE_FUNC
constexpr Index rows()
const noexcept {
return (Direction ==
Vertical ? 1 : m_matrix.rows()); }
69 EIGEN_DEVICE_FUNC
constexpr Index cols()
const noexcept {
return (Direction ==
Horizontal ? 1 : m_matrix.cols()); }
71 EIGEN_DEVICE_FUNC
typename MatrixType::Nested nestedExpression()
const {
return m_matrix; }
73 EIGEN_DEVICE_FUNC
const MemberOp& functor()
const {
return m_functor; }
76 typename MatrixType::Nested m_matrix;
77 const MemberOp m_functor;
80template <
typename A,
typename B>
81struct partial_redux_dummy_func;
83#define EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(MEMBER, COST, VECTORIZABLE, BINARYOP) \
84 template <typename ResultType, typename Scalar> \
85 struct member_##MEMBER { \
86 typedef ResultType result_type; \
87 typedef BINARYOP<Scalar, Scalar> BinaryOp; \
89 struct Cost : std::integral_constant<int, COST> {}; \
90 enum { Vectorizable = VECTORIZABLE }; \
91 template <typename XprType> \
92 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType operator()(const XprType& mat) const { \
93 return mat.MEMBER(); \
95 BinaryOp binaryFunc() const { return BinaryOp(); } \
98#define EIGEN_MEMBER_FUNCTOR(MEMBER, COST) EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(MEMBER, COST, 0, partial_redux_dummy_func)
102EIGEN_MEMBER_FUNCTOR(norm, (Size + 5) * NumTraits<Scalar>::MulCost + (Size - 1) * NumTraits<Scalar>::AddCost);
105EIGEN_MEMBER_FUNCTOR(stableNorm, Size* NumTraits<Scalar>::ReadCost + (2 * Size + 5) * NumTraits<Scalar>::MulCost +
106 (2 * Size - 1) * NumTraits<Scalar>::AddCost);
107EIGEN_MEMBER_FUNCTOR(blueNorm, Size* NumTraits<Scalar>::ReadCost + (2 * Size + 8) * NumTraits<Scalar>::MulCost +
108 (3 * Size - 1) * NumTraits<Scalar>::AddCost);
111 ((NumTraits<Scalar>::IsComplex ? 2 * Size : Size) - 1) *
113 scalar_hypot_op<
typename stable_norm_accumulator<
typename NumTraits<Scalar>::Real>::type>>::Cost);
114EIGEN_MEMBER_FUNCTOR(all, (Size - 1) * NumTraits<Scalar>::AddCost);
115EIGEN_MEMBER_FUNCTOR(any, (Size - 1) * NumTraits<Scalar>::AddCost);
116EIGEN_MEMBER_FUNCTOR(count, (Size - 1) * NumTraits<Scalar>::AddCost);
118EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(sum, (Size - 1) * NumTraits<Scalar>::AddCost, 1, internal::scalar_sum_op);
119EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(minCoeff, (Size - 1) * NumTraits<Scalar>::AddCost, 1, internal::scalar_min_op);
120EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(maxCoeff, (Size - 1) * NumTraits<Scalar>::AddCost, 1, internal::scalar_max_op);
121EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(prod, (Size - 1) * NumTraits<Scalar>::MulCost, 1, internal::scalar_product_op);
123template <
typename ResultType,
typename Scalar>
124struct member_squaredNorm {
125 using result_type = ResultType;
126 static constexpr bool Vectorizable =
false;
128 struct Cost : std::integral_constant<int, Size * functor_traits<scalar_abs2_op<Scalar>>::Cost +
129 (Size - 1) * NumTraits<ResultType>::AddCost> {};
130 template <
typename XprType>
131 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType operator()(
const XprType& mat)
const {
132 return mat.matrix().squaredNorm();
136template <
typename ExpressionType,
int Direction,
137 bool ComplexInnerReduction =
138 NumTraits<typename ExpressionType::Scalar>::IsComplex &&
139 complex_array_access<typename ExpressionType::Scalar>::value &&
142struct partial_squared_norm {
143 using Scalar =
typename ExpressionType::Scalar;
144 using RealScalar =
typename ExpressionType::RealScalar;
145 using Type = PartialReduxExpr<const CwiseUnaryOp<scalar_abs2_op<Scalar>,
const ExpressionType>,
146 member_sum<RealScalar, RealScalar>, Direction>;
147 EIGEN_DEVICE_FUNC
static Type run(
const ExpressionType& matrix) {
return Type(matrix.cwiseAbs2()); }
153template <
typename ExpressionType,
int Direction>
154struct partial_squared_norm<ExpressionType, Direction, true> {
156 PartialReduxExpr<
const ExpressionType,
157 member_squaredNorm<typename ExpressionType::RealScalar, typename ExpressionType::Scalar>,
159 EIGEN_DEVICE_FUNC
static Type run(
const ExpressionType& matrix) {
return Type(matrix); }
162template <
int p,
typename ResultType,
typename Scalar>
163struct member_lpnorm {
164 using result_type = ResultType;
165 enum { Vectorizable = 0 };
168 : std::integral_constant<int, (Size + 5) * NumTraits<Scalar>::MulCost + (Size - 1) * NumTraits<Scalar>::AddCost> {
170 EIGEN_DEVICE_FUNC member_lpnorm() =
default;
171 template <
typename XprType>
172 EIGEN_DEVICE_FUNC
inline ResultType operator()(
const XprType& mat)
const {
173 return mat.template lpNorm<p>();
177template <
typename BinaryOpT,
typename Scalar>
179 using BinaryOp = BinaryOpT;
180 using result_type =
typename result_of<BinaryOp(
const Scalar&,
const Scalar&)>::type;
182 enum { Vectorizable = functor_traits<BinaryOp>::PacketAccess };
184 struct Cost : std::integral_constant<int, (Size - 1) * functor_traits<BinaryOp>::Cost> {};
185 EIGEN_DEVICE_FUNC
explicit member_redux(
const BinaryOp func) : m_functor(func) {}
186 template <
typename Derived>
187 EIGEN_DEVICE_FUNC
inline result_type operator()(
const DenseBase<Derived>& mat)
const {
188 return mat.redux(m_functor);
190 const BinaryOp& binaryFunc()
const {
return m_functor; }
191 const BinaryOp m_functor;
194template <
typename Scalar>
195struct scalar_replace_zero_with_one_op {
196 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(
const Scalar& x)
const {
197 return numext::is_exactly_zero(x) ? Scalar(1) : x;
199 template <
typename Packet>
200 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(
const Packet& x)
const {
201 return pselect(pcmp_eq(x, pzero(x)), pset1<Packet>(Scalar(1)), x);
204template <
typename Scalar>
205struct functor_traits<scalar_replace_zero_with_one_op<Scalar>> {
206 enum { Cost = 1, PacketAccess = packet_traits<Scalar>::HasCmp };
248template <
typename ExpressionType,
int Direction>
251 using Scalar =
typename ExpressionType::Scalar;
252 using RealScalar =
typename ExpressionType::RealScalar;
254 using ExpressionTypeNested =
typename internal::ref_selector<ExpressionType>::non_const_type;
255 using ExpressionTypeNestedCleaned = internal::remove_all_t<ExpressionTypeNested>;
257 template <
template <
typename OutScalar,
typename InputScalar>
class Functor,
typename ReturnScalar = Scalar>
262 template <
typename BinaryOp>
263 struct ReduxReturnType {
267 enum { isVertical = (Direction ==
Vertical) ? 1 : 0, isHorizontal = (Direction ==
Horizontal) ? 1 : 0 };
270 template <
typename OtherDerived>
271 struct ExtendedType {
272 using Type = Replicate<OtherDerived, isVertical ? 1 : ExpressionType::RowsAtCompileTime,
273 isHorizontal ? 1 : ExpressionType::ColsAtCompileTime>;
278 template <
typename OtherDerived>
279 EIGEN_DEVICE_FUNC
typename ExtendedType<OtherDerived>::Type extendedTo(
const DenseBase<OtherDerived>& other)
const {
280 EIGEN_STATIC_ASSERT(internal::check_implication(isVertical, OtherDerived::MaxColsAtCompileTime == 1),
281 YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED)
282 EIGEN_STATIC_ASSERT(internal::check_implication(isHorizontal, OtherDerived::MaxRowsAtCompileTime == 1),
283 YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED)
284 return typename ExtendedType<OtherDerived>::Type(other.derived(), isVertical ? 1 : m_matrix.rows(),
285 isHorizontal ? 1 : m_matrix.cols());
288 template <
typename OtherDerived>
289 struct OppositeExtendedType {
290 using Type = Replicate<OtherDerived, isHorizontal ? 1 : ExpressionType::RowsAtCompileTime,
291 isVertical ? 1 : ExpressionType::ColsAtCompileTime>;
296 template <
typename OtherDerived>
297 EIGEN_DEVICE_FUNC
typename OppositeExtendedType<OtherDerived>::Type extendedToOpposite(
298 const DenseBase<OtherDerived>& other)
const {
299 EIGEN_STATIC_ASSERT(internal::check_implication(isHorizontal, OtherDerived::MaxColsAtCompileTime == 1),
300 YOU_PASSED_A_ROW_VECTOR_BUT_A_COLUMN_VECTOR_WAS_EXPECTED)
301 EIGEN_STATIC_ASSERT(internal::check_implication(isVertical, OtherDerived::MaxRowsAtCompileTime == 1),
302 YOU_PASSED_A_COLUMN_VECTOR_BUT_A_ROW_VECTOR_WAS_EXPECTED)
303 return typename OppositeExtendedType<OtherDerived>::Type(other.derived(), isHorizontal ? 1 : m_matrix.rows(),
304 isVertical ? 1 : m_matrix.cols());
308 EIGEN_DEVICE_FUNC
explicit inline VectorwiseOp(ExpressionType& matrix) : m_matrix(matrix) {}
311 EIGEN_DEVICE_FUNC
inline const ExpressionType& _expression()
const {
return m_matrix; }
313#ifdef EIGEN_PARSED_BY_DOXYGEN
323 using reverse_iterator = internal::subvector_stl_reverse_iterator<ExpressionType,
DirectionType(Direction)>;
324 using const_reverse_iterator =
325 internal::subvector_stl_reverse_iterator<
const ExpressionType,
DirectionType(Direction)>;
341 return reverse_iterator(m_matrix, m_matrix.template subVectors<
DirectionType(Direction)>() - 1);
345 return const_reverse_iterator(m_matrix, m_matrix.template subVectors<
DirectionType(Direction)>() - 1);
349 return const_reverse_iterator(m_matrix, m_matrix.template subVectors<
DirectionType(Direction)>() - 1);
368 reverse_iterator
rend() {
return reverse_iterator(m_matrix, -1); }
370 const_reverse_iterator
rend()
const {
return const_reverse_iterator(m_matrix, -1); }
372 const_reverse_iterator
crend()
const {
return const_reverse_iterator(m_matrix, -1); }
384 template <
typename BinaryOp>
385 EIGEN_DEVICE_FUNC
const typename ReduxReturnType<BinaryOp>::Type
redux(
const BinaryOp& func = BinaryOp())
const {
386 eigen_assert(redux_length() > 0 &&
"you are using an empty matrix");
387 return typename ReduxReturnType<BinaryOp>::Type(_expression(), internal::member_redux<BinaryOp, Scalar>(func));
390 using MinCoeffReturnType =
typename ReturnType<Eigen::internal::member_minCoeff>::Type;
391 using MaxCoeffReturnType =
typename ReturnType<Eigen::internal::member_maxCoeff>::Type;
392 using SquaredNormReturnType =
typename internal::partial_squared_norm<ExpressionTypeNestedCleaned, Direction>::Type;
394 using BlueNormReturnType =
typename ReturnType<Eigen::internal::member_blueNorm, RealScalar>::Type;
395 using StableNormReturnType =
typename ReturnType<Eigen::internal::member_stableNorm, RealScalar>::Type;
396 using HypotNormReturnType =
typename ReturnType<Eigen::internal::member_hypotNorm, RealScalar>::Type;
397 using SumReturnType =
typename ReturnType<Eigen::internal::member_sum>::Type;
398 using MeanReturnType = EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(SumReturnType, Scalar, internal::scalar_quotient_op);
399 using AllReturnType =
typename ReturnType<Eigen::internal::member_all, bool>::Type;
400 using AnyReturnType =
typename ReturnType<Eigen::internal::member_any, bool>::Type;
402 using ProdReturnType =
typename ReturnType<Eigen::internal::member_prod>::Type;
407 struct LpNormReturnType {
423 EIGEN_DEVICE_FUNC
const MinCoeffReturnType
minCoeff()
const {
424 eigen_assert(redux_length() > 0 &&
"you are using an empty matrix");
425 return MinCoeffReturnType(_expression());
440 EIGEN_DEVICE_FUNC
const MaxCoeffReturnType
maxCoeff()
const {
441 eigen_assert(redux_length() > 0 &&
"you are using an empty matrix");
442 return MaxCoeffReturnType(_expression());
453 EIGEN_DEVICE_FUNC
const SquaredNormReturnType
squaredNorm()
const {
454 return internal::partial_squared_norm<ExpressionTypeNestedCleaned, Direction>::run(m_matrix);
465 EIGEN_DEVICE_FUNC
const NormReturnType
norm()
const {
return NormReturnType(
squaredNorm()); }
476 EIGEN_DEVICE_FUNC
const typename LpNormReturnType<p>::Type
lpNorm()
const {
477 return typename LpNormReturnType<p>::Type(_expression());
486 EIGEN_DEVICE_FUNC
const BlueNormReturnType
blueNorm()
const {
return BlueNormReturnType(_expression()); }
494 EIGEN_DEVICE_FUNC
const StableNormReturnType
stableNorm()
const {
return StableNormReturnType(_expression()); }
502 EIGEN_DEVICE_FUNC
const HypotNormReturnType
hypotNorm()
const {
return HypotNormReturnType(_expression()); }
511 EIGEN_DEVICE_FUNC
const SumReturnType
sum()
const {
return SumReturnType(_expression()); }
517 EIGEN_DEVICE_FUNC
const MeanReturnType
mean()
const {
518 return sum() / Scalar(Direction ==
Vertical ? m_matrix.rows() : m_matrix.cols());
526 EIGEN_DEVICE_FUNC
const AllReturnType
all()
const {
return AllReturnType(_expression()); }
533 EIGEN_DEVICE_FUNC
const AnyReturnType
any()
const {
return AnyReturnType(_expression()); }
544 EIGEN_DEVICE_FUNC
const CountReturnType
count()
const {
return CountReturnType(_expression()); }
553 EIGEN_DEVICE_FUNC
const ProdReturnType
prod()
const {
return ProdReturnType(_expression()); }
562 EIGEN_DEVICE_FUNC
const ConstReverseReturnType
reverse()
const {
return ConstReverseReturnType(_expression()); }
568 EIGEN_DEVICE_FUNC ReverseReturnType
reverse() {
return ReverseReturnType(_expression()); }
570 using ReplicateReturnType =
Replicate<ExpressionType, (isVertical ? Dynamic : 1), (isHorizontal ? Dynamic : 1)>;
584 template <
int Factor>
585 const Replicate<ExpressionType, isVertical * Factor + isHorizontal,
586 isHorizontal * Factor + isVertical> EIGEN_DEVICE_FUNC
589 _expression(), isVertical ? factor : 1, isHorizontal ? factor : 1);
601 template <
typename NFactorType>
602 EIGEN_DEVICE_FUNC
const
604 isHorizontal * internal::get_fixed_value<NFactorType>::value + isVertical>
617 template <
typename OtherDerived>
619 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
620 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
622 typename internal::nested_eval<OtherDerived, Dynamic>::type other_eval(other.derived());
623 return m_matrix = extendedTo(other_eval);
627 template <
typename OtherDerived>
629 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
630 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
631 typename internal::nested_eval<OtherDerived, Dynamic>::type other_eval(other.derived());
632 return m_matrix += extendedTo(other_eval);
636 template <
typename OtherDerived>
638 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
639 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
640 typename internal::nested_eval<OtherDerived, Dynamic>::type other_eval(other.derived());
641 return m_matrix -= extendedTo(other_eval);
645 template <
typename OtherDerived>
647 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
648 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
649 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
650 typename internal::nested_eval<OtherDerived, Dynamic>::type other_eval(other.derived());
651 m_matrix *= extendedTo(other_eval);
656 template <
typename OtherDerived>
658 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
659 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
660 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
661 typename internal::nested_eval<OtherDerived, Dynamic>::type other_eval(other.derived());
662 m_matrix /= extendedTo(other_eval);
667 template <
typename OtherDerived>
668 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
670 const typename ExtendedType<OtherDerived>::Type>
672 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
673 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
674 return m_matrix + extendedTo(other.derived());
678 template <
typename OtherDerived>
679 friend EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
681 const typename ExtendedType<OtherDerived>::Type,
const ExpressionTypeNestedCleaned>
683 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
684 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
686 const typename ExtendedType<OtherDerived>::Type,
const ExpressionTypeNestedCleaned>(
687 xpr.extendedTo(other.derived()), xpr._expression());
691 template <
typename OtherDerived>
693 const ExpressionTypeNestedCleaned,
const typename ExtendedType<OtherDerived>::Type>
695 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
696 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
697 return m_matrix - extendedTo(other.derived());
701 template <
typename OtherDerived>
702 friend EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
704 const typename ExtendedType<OtherDerived>::Type,
const ExpressionTypeNestedCleaned>
706 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
707 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
709 const typename ExtendedType<OtherDerived>::Type,
const ExpressionTypeNestedCleaned>(
710 xpr.extendedTo(other.derived()), xpr._expression());
715 template <
typename OtherDerived>
717 const ExpressionTypeNestedCleaned,
const typename ExtendedType<OtherDerived>::Type>
719 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
720 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
721 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
722 return m_matrix * extendedTo(other.derived());
726 template <
typename OtherDerived>
727 friend EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
729 const typename ExtendedType<OtherDerived>::Type,
const ExpressionTypeNestedCleaned>
731 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
732 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
733 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
735 const typename ExtendedType<OtherDerived>::Type,
const ExpressionTypeNestedCleaned>(
736 xpr.extendedTo(other.derived()), xpr._expression());
741 template <
typename OtherDerived>
743 const ExpressionTypeNestedCleaned,
const typename ExtendedType<OtherDerived>::Type>
745 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
746 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
747 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
748 return m_matrix / extendedTo(other.derived());
752 template <
typename OtherDerived>
753 friend EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
755 const typename ExtendedType<OtherDerived>::Type,
const ExpressionTypeNestedCleaned>
757 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
758 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
759 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
761 const typename ExtendedType<OtherDerived>::Type,
const ExpressionTypeNestedCleaned>(
762 xpr.extendedTo(other.derived()), xpr._expression());
766 template <
typename CustomBinaryOp,
typename OtherDerived>
767 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const
770 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
771 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
772 return CwiseBinaryOp<CustomBinaryOp,
const ExpressionTypeNestedCleaned,
773 const typename ExtendedType<OtherDerived>::Type>(_expression(), extendedTo(other.derived()),
778 template <
int NaNPropagation = PropagateFast,
typename OtherDerived>
779 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
const
781 const ExpressionTypeNestedCleaned,
const typename ExtendedType<OtherDerived>::Type>
783 return binaryExpr(other, internal::scalar_min_op<Scalar, typename OtherDerived::Scalar, NaNPropagation>());
787 template <
int NaNPropagation = PropagateFast>
788 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
const
790 const typename ExpressionTypeNestedCleaned::ConstantReturnType>
793 const typename ExpressionTypeNestedCleaned::ConstantReturnType>(
794 _expression(), ExpressionTypeNestedCleaned::Constant(m_matrix.rows(), m_matrix.cols(), other));
798 template <
int NaNPropagation = PropagateFast,
typename OtherDerived>
799 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
const
801 const ExpressionTypeNestedCleaned,
const typename ExtendedType<OtherDerived>::Type>
803 return binaryExpr(other, internal::scalar_max_op<Scalar, typename OtherDerived::Scalar, NaNPropagation>());
807 template <
int NaNPropagation = PropagateFast>
808 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
const
810 const typename ExpressionTypeNestedCleaned::ConstantReturnType>
813 const typename ExpressionTypeNestedCleaned::ConstantReturnType>(
814 _expression(), ExpressionTypeNestedCleaned::Constant(m_matrix.rows(), m_matrix.cols(), other));
817 using Normalized_NonzeroNormType =
820 const typename OppositeExtendedType<Normalized_NonzeroNormType>::Type>;
831 return m_matrix.cwiseQuotient(extendedToOpposite(Normalized_NonzeroNormType(this->
norm())));
849 using CrossReturnType =
typename ExpressionType::PlainObject;
850 template <
typename OtherDerived>
854 HNormalized_Size = Direction ==
Vertical ? internal::traits<ExpressionType>::RowsAtCompileTime
855 : internal::traits<ExpressionType>::ColsAtCompileTime,
856 HNormalized_SizeMinusOne = HNormalized_Size == Dynamic ? Dynamic : HNormalized_Size - 1
858 using HNormalized_Block =
Block<
const ExpressionType,
859 Direction ==
Vertical ? int(HNormalized_SizeMinusOne)
860 : int(internal::traits<ExpressionType>::RowsAtCompileTime),
861 Direction ==
Horizontal ? int(HNormalized_SizeMinusOne)
862 : int(internal::traits<ExpressionType>::ColsAtCompileTime)>;
863 using HNormalized_Factors =
864 Block<
const ExpressionType, Direction ==
Vertical ? 1 : int(internal::traits<ExpressionType>::RowsAtCompileTime),
865 Direction ==
Horizontal ? 1 : int(internal::traits<ExpressionType>::ColsAtCompileTime)>;
866 using HNormalizedReturnType =
868 const HNormalized_Block,
869 const Replicate<HNormalized_Factors, Direction ==
Vertical ? HNormalized_SizeMinusOne : 1,
870 Direction ==
Horizontal ? HNormalized_SizeMinusOne : 1>>;
872 EIGEN_DEVICE_FUNC
const HNormalizedReturnType
hnormalized()
const;
874#ifdef EIGEN_VECTORWISEOP_PLUGIN
875#include EIGEN_VECTORWISEOP_PLUGIN
879 EIGEN_DEVICE_FUNC
Index redux_length()
const {
return Direction ==
Vertical ? m_matrix.rows() : m_matrix.cols(); }
880 ExpressionTypeNested m_matrix;
889template <
typename Derived>
891 return ColwiseReturnType(derived());
900template <
typename Derived>
902 return RowwiseReturnType(derived());
Expression of a fixed-size or dynamic-size block.
Definition Block.h:111
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition CwiseBinaryOp.h:80
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition CwiseUnaryOp.h:55
Base class for all dense matrices, vectors, and arrays.
Definition DenseBase.h:45
ConstColwiseReturnType colwise() const
Definition DenseBase.h:482
ConstRowwiseReturnType rowwise() const
Definition DenseBase.h:472
Expression of one (or a set of) homogeneous vector(s)
Definition Homogeneous.h:63
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
Generic expression of a partially reduxed matrix.
Definition VectorwiseOp.h:60
Expression of the multiple replication of a matrix or vector.
Definition Replicate.h:65
Expression of the reverse of a vector or matrix.
Definition Reverse.h:66
const HypotNormReturnType hypotNorm() const
Definition VectorwiseOp.h:502
const SquaredNormReturnType squaredNorm() const
Definition VectorwiseOp.h:453
const Replicate< ExpressionType, isVertical *Factor+isHorizontal, isHorizontal *Factor+isVertical > replicate(Index factor=Factor) const
Definition VectorwiseOp.h:587
const ProdReturnType prod() const
Definition VectorwiseOp.h:553
CwiseBinaryOp< internal::scalar_difference_op< Scalar, typename OtherDerived::Scalar >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > operator-(const DenseBase< OtherDerived > &other) const
Definition VectorwiseOp.h:694
NormalizedReturnType normalized() const
Definition VectorwiseOp.h:830
friend CwiseBinaryOp< internal::scalar_product_op< typename OtherDerived::Scalar, Scalar >, const typename ExtendedType< OtherDerived >::Type, const ExpressionTypeNestedCleaned > operator*(const DenseBase< OtherDerived > &other, const VectorwiseOp &xpr)
Definition VectorwiseOp.h:730
const_reverse_iterator crend() const
Definition VectorwiseOp.h:372
const Replicate< ExpressionType, isVertical *internal::get_fixed_value< NFactorType >::value+isHorizontal, isHorizontal *internal::get_fixed_value< NFactorType >::value+isVertical > replicate(NFactorType nFactor) const
Definition VectorwiseOp.h:605
constexpr const CwiseBinaryOp< internal::scalar_min_op< Scalar, typename OtherDerived::Scalar, NaNPropagation >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > cwiseMin(const DenseBase< OtherDerived > &other) const
Definition VectorwiseOp.h:782
friend CwiseBinaryOp< internal::scalar_sum_op< typename OtherDerived::Scalar, Scalar >, const typename ExtendedType< OtherDerived >::Type, const ExpressionTypeNestedCleaned > operator+(const DenseBase< OtherDerived > &other, const VectorwiseOp &xpr)
Definition VectorwiseOp.h:682
ExpressionType & operator-=(const DenseBase< OtherDerived > &other)
Definition VectorwiseOp.h:637
CwiseBinaryOp< internal::scalar_sum_op< Scalar, typename OtherDerived::Scalar >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > operator+(const DenseBase< OtherDerived > &other) const
Definition VectorwiseOp.h:671
const BlueNormReturnType blueNorm() const
Definition VectorwiseOp.h:486
ExpressionType & operator/=(const DenseBase< OtherDerived > &other)
Definition VectorwiseOp.h:657
const_iterator cend() const
Definition VectorwiseOp.h:361
random_access_iterator_type const_iterator
Definition VectorwiseOp.h:319
const CountReturnType count() const
Definition VectorwiseOp.h:544
const ReplicateReturnType replicate(Index factor) const
Definition Replicate.h:125
const MaxCoeffReturnType maxCoeff() const
Definition VectorwiseOp.h:440
const SumReturnType sum() const
Definition VectorwiseOp.h:511
ExpressionType & operator*=(const DenseBase< OtherDerived > &other)
Definition VectorwiseOp.h:646
const_iterator cbegin() const
Definition VectorwiseOp.h:335
const MinCoeffReturnType minCoeff() const
Definition VectorwiseOp.h:423
constexpr const CwiseBinaryOp< internal::scalar_max_op< Scalar, typename OtherDerived::Scalar, NaNPropagation >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > cwiseMax(const DenseBase< OtherDerived > &other) const
Definition VectorwiseOp.h:802
CwiseBinaryOp< internal::scalar_quotient_op< Scalar, typename OtherDerived::Scalar >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > operator/(const DenseBase< OtherDerived > &other) const
Definition VectorwiseOp.h:744
reverse_iterator rbegin()
Definition VectorwiseOp.h:340
const AnyReturnType any() const
Definition VectorwiseOp.h:533
const AllReturnType all() const
Definition VectorwiseOp.h:526
iterator end()
Definition VectorwiseOp.h:355
random_access_iterator_type iterator
Definition VectorwiseOp.h:317
const_reverse_iterator rbegin() const
Definition VectorwiseOp.h:344
reverse_iterator rend()
Definition VectorwiseOp.h:368
const MeanReturnType mean() const
Definition VectorwiseOp.h:517
const_iterator begin() const
Definition VectorwiseOp.h:333
friend CwiseBinaryOp< internal::scalar_quotient_op< typename OtherDerived::Scalar, Scalar >, const typename ExtendedType< OtherDerived >::Type, const ExpressionTypeNestedCleaned > operator/(const DenseBase< OtherDerived > &other, const VectorwiseOp &xpr)
Definition VectorwiseOp.h:756
ExpressionType & operator=(const DenseBase< OtherDerived > &other)
Definition VectorwiseOp.h:618
ReverseReturnType reverse()
Definition VectorwiseOp.h:568
void reverseInPlace()
Definition Reverse.h:197
iterator begin()
Definition VectorwiseOp.h:331
ExpressionType & operator+=(const DenseBase< OtherDerived > &other)
Definition VectorwiseOp.h:628
Eigen::Index Index
Definition VectorwiseOp.h:253
const_iterator end() const
Definition VectorwiseOp.h:357
friend CwiseBinaryOp< internal::scalar_difference_op< typename OtherDerived::Scalar, Scalar >, const typename ExtendedType< OtherDerived >::Type, const ExpressionTypeNestedCleaned > operator-(const DenseBase< OtherDerived > &other, const VectorwiseOp &xpr)
Definition VectorwiseOp.h:705
void normalize()
Definition VectorwiseOp.h:840
const StableNormReturnType stableNorm() const
Definition VectorwiseOp.h:494
const LpNormReturnType< p >::Type lpNorm() const
Definition VectorwiseOp.h:476
const CwiseBinaryOp< CustomBinaryOp, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > binaryExpr(const DenseBase< OtherDerived > &other, const CustomBinaryOp &func=CustomBinaryOp()) const
Definition VectorwiseOp.h:769
constexpr const CwiseBinaryOp< internal::scalar_min_op< Scalar, Scalar, NaNPropagation >, const ExpressionTypeNestedCleaned, const typename ExpressionTypeNestedCleaned::ConstantReturnType > cwiseMin(const Scalar &other) const
Definition VectorwiseOp.h:791
const ConstReverseReturnType reverse() const
Definition VectorwiseOp.h:562
const_reverse_iterator crbegin() const
Definition VectorwiseOp.h:348
CwiseBinaryOp< internal::scalar_product_op< Scalar, typename OtherDerived::Scalar >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > operator*(const DenseBase< OtherDerived > &other) const
Definition VectorwiseOp.h:718
const NormReturnType norm() const
Definition VectorwiseOp.h:465
const ReduxReturnType< BinaryOp >::Type redux(const BinaryOp &func=BinaryOp()) const
Definition VectorwiseOp.h:385
constexpr const CwiseBinaryOp< internal::scalar_max_op< Scalar, Scalar, NaNPropagation >, const ExpressionTypeNestedCleaned, const typename ExpressionTypeNestedCleaned::ConstantReturnType > cwiseMax(const Scalar &other) const
Definition VectorwiseOp.h:811
const_reverse_iterator rend() const
Definition VectorwiseOp.h:370
const HNormalizedReturnType hnormalized() const
column or row-wise homogeneous normalization
Definition Homogeneous.h:190
const CrossReturnType cross(const MatrixBase< OtherDerived > &other) const
Definition OrthoMethods.h:150
HomogeneousReturnType homogeneous() const
Definition Homogeneous.h:142
DirectionType
Definition Constants.h:264
@ Horizontal
Definition Constants.h:270
@ Vertical
Definition Constants.h:267
constexpr unsigned int PacketAccessBit
Definition Constants.h:98
constexpr unsigned int DirectAccessBit
Definition Constants.h:160
constexpr unsigned int RowMajorBit
Definition Constants.h:71