WPILibC++ 2023.4.3
VectorwiseOp.h
Go to the documentation of this file.
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2008-2019 Gael Guennebaud <gael.guennebaud@inria.fr>
5// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6//
7// This Source Code Form is subject to the terms of the Mozilla
8// Public License v. 2.0. If a copy of the MPL was not distributed
9// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
11#ifndef EIGEN_PARTIAL_REDUX_H
12#define EIGEN_PARTIAL_REDUX_H
13
14namespace Eigen {
15
16/** \class PartialReduxExpr
17 * \ingroup Core_Module
18 *
19 * \brief Generic expression of a partially reduxed matrix
20 *
21 * \tparam MatrixType the type of the matrix we are applying the redux operation
22 * \tparam MemberOp type of the member functor
23 * \tparam Direction indicates the direction of the redux (#Vertical or #Horizontal)
24 *
25 * This class represents an expression of a partial redux operator of a matrix.
26 * It is the return type of some VectorwiseOp functions,
27 * and most of the time this is the only way it is used.
28 *
29 * \sa class VectorwiseOp
30 */
31
32template< typename MatrixType, typename MemberOp, int Direction>
33class PartialReduxExpr;
34
35namespace internal {
36template<typename MatrixType, typename MemberOp, int Direction>
37struct traits<PartialReduxExpr<MatrixType, MemberOp, Direction> >
38 : traits<MatrixType>
39{
40 typedef typename MemberOp::result_type Scalar;
43 typedef typename MatrixType::Scalar InputScalar;
44 enum {
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,
49 Flags = RowsAtCompileTime == 1 ? RowMajorBit : 0,
50 TraversalSize = Direction==Vertical ? MatrixType::RowsAtCompileTime : MatrixType::ColsAtCompileTime
51 };
52};
53}
54
55template< typename MatrixType, typename MemberOp, int Direction>
56class PartialReduxExpr : public internal::dense_xpr_base< PartialReduxExpr<MatrixType, MemberOp, Direction> >::type,
58{
59 public:
60
63
65 explicit PartialReduxExpr(const MatrixType& mat, const MemberOp& func = MemberOp())
66 : m_matrix(mat), m_functor(func) {}
67
69 Index rows() const EIGEN_NOEXCEPT { return (Direction==Vertical ? 1 : m_matrix.rows()); }
71 Index cols() const EIGEN_NOEXCEPT { return (Direction==Horizontal ? 1 : m_matrix.cols()); }
72
74 typename MatrixType::Nested nestedExpression() const { return m_matrix; }
75
77 const MemberOp& functor() const { return m_functor; }
78
79 protected:
80 typename MatrixType::Nested m_matrix;
81 const MemberOp m_functor;
82};
83
84template<typename A,typename B> struct partial_redux_dummy_func;
85
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(); } \
99 }
100
101#define EIGEN_MEMBER_FUNCTOR(MEMBER,COST) \
102 EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(MEMBER,COST,0,partial_redux_dummy_func)
103
104namespace internal {
105
113
118
119template <int p, typename ResultType,typename Scalar>
121 typedef ResultType result_type;
122 enum { Vectorizable = 0 };
123 template<int Size> struct Cost
124 { enum { value = (Size+5) * NumTraits<Scalar>::MulCost + (Size-1)*NumTraits<Scalar>::AddCost }; };
126 template<typename XprType>
127 EIGEN_DEVICE_FUNC inline ResultType operator()(const XprType& mat) const
128 { return mat.template lpNorm<p>(); }
129};
130
131template <typename BinaryOpT, typename Scalar>
133 typedef BinaryOpT BinaryOp;
134 typedef typename result_of<
135 BinaryOp(const Scalar&,const Scalar&)
137
139 template<int Size> struct Cost { enum { value = (Size-1) * functor_traits<BinaryOp>::Cost }; };
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; }
146};
147}
148
149/** \class VectorwiseOp
150 * \ingroup Core_Module
151 *
152 * \brief Pseudo expression providing broadcasting and partial reduction operations
153 *
154 * \tparam ExpressionType the type of the object on which to do partial reductions
155 * \tparam Direction indicates whether to operate on columns (#Vertical) or rows (#Horizontal)
156 *
157 * This class represents a pseudo expression with broadcasting and partial reduction features.
158 * It is the return type of DenseBase::colwise() and DenseBase::rowwise()
159 * and most of the time this is the only way it is explicitly used.
160 *
161 * To understand the logic of rowwise/colwise expression, let's consider a generic case `A.colwise().foo()`
162 * where `foo` is any method of `VectorwiseOp`. This expression is equivalent to applying `foo()` to each
163 * column of `A` and then re-assemble the outputs in a matrix expression:
164 * \code [A.col(0).foo(), A.col(1).foo(), ..., A.col(A.cols()-1).foo()] \endcode
165 *
166 * Example: \include MatrixBase_colwise.cpp
167 * Output: \verbinclude MatrixBase_colwise.out
168 *
169 * The begin() and end() methods are obviously exceptions to the previous rule as they
170 * return STL-compatible begin/end iterators to the rows or columns of the nested expression.
171 * Typical use cases include for-range-loop and calls to STL algorithms:
172 *
173 * Example: \include MatrixBase_colwise_iterator_cxx11.cpp
174 * Output: \verbinclude MatrixBase_colwise_iterator_cxx11.out
175 *
176 * For a partial reduction on an empty input, some rules apply.
177 * For the sake of clarity, let's consider a vertical reduction:
178 * - If the number of columns is zero, then a 1x0 row-major vector expression is returned.
179 * - Otherwise, if the number of rows is zero, then
180 * - a row vector of zeros is returned for sum-like reductions (sum, squaredNorm, norm, etc.)
181 * - a row vector of ones is returned for a product reduction (e.g., <code>MatrixXd(n,0).colwise().prod()</code>)
182 * - an assert is triggered for all other reductions (minCoeff,maxCoeff,redux(bin_op))
183 *
184 * \sa DenseBase::colwise(), DenseBase::rowwise(), class PartialReduxExpr
185 */
186template<typename ExpressionType, int Direction> class VectorwiseOp
187{
188 public:
189
190 typedef typename ExpressionType::Scalar Scalar;
191 typedef typename ExpressionType::RealScalar RealScalar;
192 typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
195
196 template<template<typename OutScalar,typename InputScalar> class Functor,
197 typename ReturnScalar=Scalar> struct ReturnType
198 {
199 typedef PartialReduxExpr<ExpressionType,
200 Functor<ReturnScalar,Scalar>,
201 Direction
203 };
204
205 template<typename BinaryOp> struct ReduxReturnType
206 {
207 typedef PartialReduxExpr<ExpressionType,
209 Direction
211 };
212
213 enum {
214 isVertical = (Direction==Vertical) ? 1 : 0,
215 isHorizontal = (Direction==Horizontal) ? 1 : 0
216 };
217
218 protected:
219
220 template<typename OtherDerived> struct ExtendedType {
221 typedef Replicate<OtherDerived,
222 isVertical ? 1 : ExpressionType::RowsAtCompileTime,
223 isHorizontal ? 1 : ExpressionType::ColsAtCompileTime> Type;
224 };
225
226 /** \internal
227 * Replicates a vector to match the size of \c *this */
228 template<typename OtherDerived>
232 {
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)
238 (other.derived(),
239 isVertical ? 1 : m_matrix.rows(),
240 isHorizontal ? 1 : m_matrix.cols());
241 }
242
243 template<typename OtherDerived> struct OppositeExtendedType {
244 typedef Replicate<OtherDerived,
245 isHorizontal ? 1 : ExpressionType::RowsAtCompileTime,
246 isVertical ? 1 : ExpressionType::ColsAtCompileTime> Type;
247 };
248
249 /** \internal
250 * Replicates a vector in the opposite direction to match the size of \c *this */
251 template<typename OtherDerived>
255 {
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)
261 (other.derived(),
262 isHorizontal ? 1 : m_matrix.rows(),
263 isVertical ? 1 : m_matrix.cols());
264 }
265
266 public:
268 explicit inline VectorwiseOp(ExpressionType& matrix) : m_matrix(matrix) {}
269
270 /** \internal */
272 inline const ExpressionType& _expression() const { return m_matrix; }
273
274 #ifdef EIGEN_PARSED_BY_DOXYGEN
275 /** STL-like <a href="https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator">RandomAccessIterator</a>
276 * iterator type over the columns or rows as returned by the begin() and end() methods.
277 */
278 random_access_iterator_type iterator;
279 /** This is the const version of iterator (aka read-only) */
280 random_access_iterator_type const_iterator;
281 #else
282 typedef internal::subvector_stl_iterator<ExpressionType, DirectionType(Direction)> iterator;
283 typedef internal::subvector_stl_iterator<const ExpressionType, DirectionType(Direction)> const_iterator;
286 #endif
287
288 /** returns an iterator to the first row (rowwise) or column (colwise) of the nested expression.
289 * \sa end(), cbegin()
290 */
291 iterator begin() { return iterator (m_matrix, 0); }
292 /** const version of begin() */
294 /** const version of begin() */
296
297 /** returns a reverse iterator to the last row (rowwise) or column (colwise) of the nested expression.
298 * \sa rend(), crbegin()
299 */
301 /** const version of rbegin() */
303 /** const version of rbegin() */
305
306 /** returns an iterator to the row (resp. column) following the last row (resp. column) of the nested expression
307 * \sa begin(), cend()
308 */
309 iterator end() { return iterator (m_matrix, m_matrix.template subVectors<DirectionType(Direction)>()); }
310 /** const version of end() */
311 const_iterator end() const { return const_iterator(m_matrix, m_matrix.template subVectors<DirectionType(Direction)>()); }
312 /** const version of end() */
313 const_iterator cend() const { return const_iterator(m_matrix, m_matrix.template subVectors<DirectionType(Direction)>()); }
314
315 /** returns a reverse iterator to the row (resp. column) before the first row (resp. column) of the nested expression
316 * \sa begin(), cend()
317 */
319 /** const version of rend() */
321 /** const version of rend() */
323
324 /** \returns a row or column vector expression of \c *this reduxed by \a func
325 *
326 * The template parameter \a BinaryOp is the type of the functor
327 * of the custom redux operator. Note that func must be an associative operator.
328 *
329 * \warning the size along the reduction direction must be strictly positive,
330 * otherwise an assertion is triggered.
331 *
332 * \sa class VectorwiseOp, DenseBase::colwise(), DenseBase::rowwise()
333 */
334 template<typename BinaryOp>
337 redux(const BinaryOp& func = BinaryOp()) const
338 {
339 eigen_assert(redux_length()>0 && "you are using an empty matrix");
341 }
342
358
359 template<int p> struct LpNormReturnType {
361 };
362
363 /** \returns a row (or column) vector expression of the smallest coefficient
364 * of each column (or row) of the referenced expression.
365 *
366 * \warning the size along the reduction direction must be strictly positive,
367 * otherwise an assertion is triggered.
368 *
369 * \warning the result is undefined if \c *this contains NaN.
370 *
371 * Example: \include PartialRedux_minCoeff.cpp
372 * Output: \verbinclude PartialRedux_minCoeff.out
373 *
374 * \sa DenseBase::minCoeff() */
377 {
378 eigen_assert(redux_length()>0 && "you are using an empty matrix");
380 }
381
382 /** \returns a row (or column) vector expression of the largest coefficient
383 * of each column (or row) of the referenced expression.
384 *
385 * \warning the size along the reduction direction must be strictly positive,
386 * otherwise an assertion is triggered.
387 *
388 * \warning the result is undefined if \c *this contains NaN.
389 *
390 * Example: \include PartialRedux_maxCoeff.cpp
391 * Output: \verbinclude PartialRedux_maxCoeff.out
392 *
393 * \sa DenseBase::maxCoeff() */
396 {
397 eigen_assert(redux_length()>0 && "you are using an empty matrix");
399 }
400
401 /** \returns a row (or column) vector expression of the squared norm
402 * of each column (or row) of the referenced expression.
403 * This is a vector with real entries, even if the original matrix has complex entries.
404 *
405 * Example: \include PartialRedux_squaredNorm.cpp
406 * Output: \verbinclude PartialRedux_squaredNorm.out
407 *
408 * \sa DenseBase::squaredNorm() */
411 { return SquaredNormReturnType(m_matrix.cwiseAbs2()); }
412
413 /** \returns a row (or column) vector expression of the norm
414 * of each column (or row) of the referenced expression.
415 * This is a vector with real entries, even if the original matrix has complex entries.
416 *
417 * Example: \include PartialRedux_norm.cpp
418 * Output: \verbinclude PartialRedux_norm.out
419 *
420 * \sa DenseBase::norm() */
422 const NormReturnType norm() const
423 { return NormReturnType(squaredNorm()); }
424
425 /** \returns a row (or column) vector expression of the norm
426 * of each column (or row) of the referenced expression.
427 * This is a vector with real entries, even if the original matrix has complex entries.
428 *
429 * Example: \include PartialRedux_norm.cpp
430 * Output: \verbinclude PartialRedux_norm.out
431 *
432 * \sa DenseBase::norm() */
433 template<int p>
435 const typename LpNormReturnType<p>::Type lpNorm() const
436 { return typename LpNormReturnType<p>::Type(_expression()); }
437
438
439 /** \returns a row (or column) vector expression of the norm
440 * of each column (or row) of the referenced expression, using
441 * Blue's algorithm.
442 * This is a vector with real entries, even if the original matrix has complex entries.
443 *
444 * \sa DenseBase::blueNorm() */
447 { return BlueNormReturnType(_expression()); }
448
449
450 /** \returns a row (or column) vector expression of the norm
451 * of each column (or row) of the referenced expression, avoiding
452 * underflow and overflow.
453 * This is a vector with real entries, even if the original matrix has complex entries.
454 *
455 * \sa DenseBase::stableNorm() */
458 { return StableNormReturnType(_expression()); }
459
460
461 /** \returns a row (or column) vector expression of the norm
462 * of each column (or row) of the referenced expression, avoiding
463 * underflow and overflow using a concatenation of hypot() calls.
464 * This is a vector with real entries, even if the original matrix has complex entries.
465 *
466 * \sa DenseBase::hypotNorm() */
469 { return HypotNormReturnType(_expression()); }
470
471 /** \returns a row (or column) vector expression of the sum
472 * of each column (or row) of the referenced expression.
473 *
474 * Example: \include PartialRedux_sum.cpp
475 * Output: \verbinclude PartialRedux_sum.out
476 *
477 * \sa DenseBase::sum() */
479 const SumReturnType sum() const
480 { return SumReturnType(_expression()); }
481
482 /** \returns a row (or column) vector expression of the mean
483 * of each column (or row) of the referenced expression.
484 *
485 * \sa DenseBase::mean() */
487 const MeanReturnType mean() const
488 { return sum() / Scalar(Direction==Vertical?m_matrix.rows():m_matrix.cols()); }
489
490 /** \returns a row (or column) vector expression representing
491 * whether \b all coefficients of each respective column (or row) are \c true.
492 * This expression can be assigned to a vector with entries of type \c bool.
493 *
494 * \sa DenseBase::all() */
496 const AllReturnType all() const
497 { return AllReturnType(_expression()); }
498
499 /** \returns a row (or column) vector expression representing
500 * whether \b at \b least one coefficient of each respective column (or row) is \c true.
501 * This expression can be assigned to a vector with entries of type \c bool.
502 *
503 * \sa DenseBase::any() */
505 const AnyReturnType any() const
506 { return AnyReturnType(_expression()); }
507
508 /** \returns a row (or column) vector expression representing
509 * the number of \c true coefficients of each respective column (or row).
510 * This expression can be assigned to a vector whose entries have the same type as is used to
511 * index entries of the original matrix; for dense matrices, this is \c std::ptrdiff_t .
512 *
513 * Example: \include PartialRedux_count.cpp
514 * Output: \verbinclude PartialRedux_count.out
515 *
516 * \sa DenseBase::count() */
518 const CountReturnType count() const
519 { return CountReturnType(_expression()); }
520
521 /** \returns a row (or column) vector expression of the product
522 * of each column (or row) of the referenced expression.
523 *
524 * Example: \include PartialRedux_prod.cpp
525 * Output: \verbinclude PartialRedux_prod.out
526 *
527 * \sa DenseBase::prod() */
529 const ProdReturnType prod() const
530 { return ProdReturnType(_expression()); }
531
532
533 /** \returns a matrix expression
534 * where each column (or row) are reversed.
535 *
536 * Example: \include Vectorwise_reverse.cpp
537 * Output: \verbinclude Vectorwise_reverse.out
538 *
539 * \sa DenseBase::reverse() */
542 { return ConstReverseReturnType( _expression() ); }
543
544 /** \returns a writable matrix expression
545 * where each column (or row) are reversed.
546 *
547 * \sa reverse() const */
550 { return ReverseReturnType( _expression() ); }
551
554 const ReplicateReturnType replicate(Index factor) const;
555
556 /**
557 * \return an expression of the replication of each column (or row) of \c *this
558 *
559 * Example: \include DirectionWise_replicate.cpp
560 * Output: \verbinclude DirectionWise_replicate.out
561 *
562 * \sa VectorwiseOp::replicate(Index), DenseBase::replicate(), class Replicate
563 */
564 // NOTE implemented here because of sunstudio's compilation errors
565 // isVertical*Factor+isHorizontal instead of (isVertical?Factor:1) to handle CUDA bug with ternary operator
568 replicate(Index factor = Factor) const
569 {
571 (_expression(),isVertical?factor:1,isHorizontal?factor:1);
572 }
573
574/////////// Artithmetic operators ///////////
575
576 /** Copies the vector \a other to each subvector of \c *this */
577 template<typename OtherDerived>
579 ExpressionType& operator=(const DenseBase<OtherDerived>& other)
580 {
582 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
583 //eigen_assert((m_matrix.isNull()) == (other.isNull())); FIXME
584 return m_matrix = extendedTo(other.derived());
585 }
586
587 /** Adds the vector \a other to each subvector of \c *this */
588 template<typename OtherDerived>
590 ExpressionType& operator+=(const DenseBase<OtherDerived>& other)
591 {
593 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
594 return m_matrix += extendedTo(other.derived());
595 }
596
597 /** Substracts the vector \a other to each subvector of \c *this */
598 template<typename OtherDerived>
600 ExpressionType& operator-=(const DenseBase<OtherDerived>& other)
601 {
603 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
604 return m_matrix -= extendedTo(other.derived());
605 }
606
607 /** Multiples each subvector of \c *this by the vector \a other */
608 template<typename OtherDerived>
610 ExpressionType& operator*=(const DenseBase<OtherDerived>& other)
611 {
613 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
614 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
615 m_matrix *= extendedTo(other.derived());
616 return m_matrix;
617 }
618
619 /** Divides each subvector of \c *this by the vector \a other */
620 template<typename OtherDerived>
622 ExpressionType& operator/=(const DenseBase<OtherDerived>& other)
623 {
625 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
626 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
627 m_matrix /= extendedTo(other.derived());
628 return m_matrix;
629 }
630
631 /** Returns the expression of the sum of the vector \a other to each subvector of \c *this */
632 template<typename OtherDerived> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
637 {
639 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
640 return m_matrix + extendedTo(other.derived());
641 }
642
643 /** Returns the expression of the difference between each subvector of \c *this and the vector \a other */
644 template<typename OtherDerived>
650 {
652 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
653 return m_matrix - extendedTo(other.derived());
654 }
655
656 /** Returns the expression where each subvector is the product of the vector \a other
657 * by the corresponding subvector of \c *this */
658 template<typename OtherDerived> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
664 {
666 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
667 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
668 return m_matrix * extendedTo(other.derived());
669 }
670
671 /** Returns the expression where each subvector is the quotient of the corresponding
672 * subvector of \c *this by the vector \a other */
673 template<typename OtherDerived>
679 {
681 EIGEN_STATIC_ASSERT_ARRAYXPR(ExpressionType)
682 EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
683 return m_matrix / extendedTo(other.derived());
684 }
685
686 /** \returns an expression where each column (or row) of the referenced matrix are normalized.
687 * The referenced matrix is \b not modified.
688 * \sa MatrixBase::normalized(), normalize()
689 */
694 normalized() const { return m_matrix.cwiseQuotient(extendedToOpposite(this->norm())); }
695
696
697 /** Normalize in-place each row or columns of the referenced matrix.
698 * \sa MatrixBase::normalize(), normalized()
699 */
701 m_matrix = this->normalized();
702 }
703
704 EIGEN_DEVICE_FUNC inline void reverseInPlace();
705
706/////////// Geometry module ///////////
707
711
712 typedef typename ExpressionType::PlainObject CrossReturnType;
713 template<typename OtherDerived>
716
717 enum {
721 };
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,
733 const HNormalized_Block,
735 Direction==Vertical ? HNormalized_SizeMinusOne : 1,
736 Direction==Horizontal ? HNormalized_SizeMinusOne : 1> >
738
741
742# ifdef EIGEN_VECTORWISEOP_PLUGIN
743# include EIGEN_VECTORWISEOP_PLUGIN
744# endif
745
746 protected:
748 {
749 return Direction==Vertical ? m_matrix.rows() : m_matrix.cols();
750 }
752};
753
754//const colwise moved to DenseBase.h due to CUDA compiler bug
755
756
757/** \returns a writable VectorwiseOp wrapper of *this providing additional partial reduction operations
758 *
759 * \sa rowwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting
760 */
761template<typename Derived>
764{
765 return ColwiseReturnType(derived());
766}
767
768//const rowwise moved to DenseBase.h due to CUDA compiler bug
769
770
771/** \returns a writable VectorwiseOp wrapper of *this providing additional partial reduction operations
772 *
773 * \sa colwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting
774 */
775template<typename Derived>
778{
779 return RowwiseReturnType(derived());
780}
781
782} // end namespace Eigen
783
784#endif // EIGEN_PARTIAL_REDUX_H
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index subVectors() const
Definition: BlockMethods.h:1441
#define EIGEN_NOEXCEPT
Definition: Macros.h:1428
#define EIGEN_CONSTEXPR
Definition: Macros.h:797
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:986
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1293
#define eigen_assert(x)
Definition: Macros.h:1047
#define EIGEN_IMPLIES(a, b)
Definition: Macros.h:1325
#define EIGEN_STRONG_INLINE
Definition: Macros.h:927
#define EIGEN_STATIC_ASSERT_ARRAYXPR(Derived)
Definition: StaticAssert.h:206
#define EIGEN_STATIC_ASSERT_SAME_XPR_KIND(Derived1, Derived2)
Definition: StaticAssert.h:210
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:142
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:127
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:105
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:84
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:56
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:47
EIGEN_DEVICE_FUNC ConstColwiseReturnType colwise() const
Definition: DenseBase.h:562
EIGEN_DEVICE_FUNC Scalar redux(const BinaryOp &func) const
EIGEN_DEVICE_FUNC ConstRowwiseReturnType rowwise() const
Definition: DenseBase.h:550
Definition: ForwardDeclarations.h:298
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:50
Generic expression of a partially reduxed matrix.
Definition: VectorwiseOp.h:58
MatrixType::Nested m_matrix
Definition: VectorwiseOp.h:80
const MemberOp m_functor
Definition: VectorwiseOp.h:81
EIGEN_DEVICE_FUNC MatrixType::Nested nestedExpression() const
Definition: VectorwiseOp.h:74
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: VectorwiseOp.h:71
internal::dense_xpr_base< PartialReduxExpr >::type Base
Definition: VectorwiseOp.h:61
EIGEN_DEVICE_FUNC PartialReduxExpr(const MatrixType &mat, const MemberOp &func=MemberOp())
Definition: VectorwiseOp.h:65
EIGEN_DEVICE_FUNC const MemberOp & functor() const
Definition: VectorwiseOp.h:77
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: VectorwiseOp.h:69
Expression of the multiple replication of a matrix or vector.
Definition: Replicate.h:63
Expression of the reverse of a vector or matrix.
Definition: Reverse.h:65
Pseudo expression providing broadcasting and partial reduction operations.
Definition: VectorwiseOp.h:187
internal::subvector_stl_iterator< const ExpressionType, DirectionType(Direction)> const_iterator
Definition: VectorwiseOp.h:283
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
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
Definition: VectorwiseOp.h:737
EIGEN_DEVICE_FUNC HomogeneousReturnType homogeneous() const
ReturnType< internal::member_maxCoeff >::Type MaxCoeffReturnType
Definition: VectorwiseOp.h:344
ReturnType< internal::member_hypotNorm, RealScalar >::Type HypotNormReturnType
Definition: VectorwiseOp.h:349
Reverse< ExpressionType, Direction > ReverseReturnType
Definition: VectorwiseOp.h:357
EIGEN_DEVICE_FUNC const ExpressionType & _expression() const
Definition: VectorwiseOp.h:272
ReturnType< internal::member_any >::Type AnyReturnType
Definition: VectorwiseOp.h:353
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
ExpressionType::PlainObject CrossReturnType
Definition: VectorwiseOp.h:712
EIGEN_DEVICE_FUNC const CrossReturnType cross(const MatrixBase< OtherDerived > &other) const
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
Index redux_length() const
Definition: VectorwiseOp.h:747
EIGEN_DEVICE_FUNC CwiseBinaryOp< internal::scalar_quotient_op< Scalar >, const ExpressionTypeNestedCleaned, const typename OppositeExtendedType< NormReturnType >::Type > normalized() const
Definition: VectorwiseOp.h:694
ExpressionTypeNested m_matrix
Definition: VectorwiseOp.h:751
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
internal::subvector_stl_reverse_iterator< const ExpressionType, DirectionType(Direction)> const_reverse_iterator
Definition: VectorwiseOp.h:285
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
ReturnType< internal::member_minCoeff >::Type MinCoeffReturnType
Definition: VectorwiseOp.h:343
EIGEN_DEVICE_FUNC const MaxCoeffReturnType maxCoeff() const
Definition: VectorwiseOp.h:395
Eigen::Index Index
Definition: VectorwiseOp.h:192
Block< const ExpressionType, Direction==Vertical ? int(HNormalized_SizeMinusOne) :int(internal::traits< ExpressionType >::RowsAtCompileTime), Direction==Horizontal ? int(HNormalized_SizeMinusOne) :int(internal::traits< ExpressionType >::ColsAtCompileTime)> HNormalized_Block
Definition: VectorwiseOp.h:727
ExpressionType::Scalar Scalar
Definition: VectorwiseOp.h:190
EIGEN_DEVICE_FUNC const HNormalizedReturnType hnormalized() const
const_iterator cend() const
const version of end()
Definition: VectorwiseOp.h:313
@ isVertical
Definition: VectorwiseOp.h:214
@ isHorizontal
Definition: VectorwiseOp.h:215
@ HNormalized_Size
Definition: VectorwiseOp.h:718
@ HNormalized_SizeMinusOne
Definition: VectorwiseOp.h:720
EIGEN_DEVICE_FUNC const ProdReturnType prod() const
Definition: VectorwiseOp.h:529
EIGEN_DEVICE_FUNC const SquaredNormReturnType squaredNorm() const
Definition: VectorwiseOp.h:410
ReturnType< internal::member_blueNorm, RealScalar >::Type BlueNormReturnType
Definition: VectorwiseOp.h:347
internal::remove_all< ExpressionTypeNested >::type ExpressionTypeNestedCleaned
Definition: VectorwiseOp.h:194
EIGEN_DEVICE_FUNC const ReplicateReturnType replicate(Index factor) const
Definition: Replicate.h:134
typedef EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(SumReturnType, Scalar, quotient) MeanReturnType
PartialReduxExpr< ExpressionType, internal::member_count< Index, Scalar >, Direction > CountReturnType
Definition: VectorwiseOp.h:354
EIGEN_DEVICE_FUNC ExpressionType & operator/=(const DenseBase< OtherDerived > &other)
Divides each subvector of *this by the vector other.
Definition: VectorwiseOp.h:622
Reverse< const ExpressionType, Direction > ConstReverseReturnType
Definition: VectorwiseOp.h:356
EIGEN_DEVICE_FUNC const AnyReturnType any() const
Definition: VectorwiseOp.h:505
const_iterator cbegin() const
const version of begin()
Definition: VectorwiseOp.h:295
ReturnType< internal::member_stableNorm, RealScalar >::Type StableNormReturnType
Definition: VectorwiseOp.h:348
internal::ref_selector< ExpressionType >::non_const_type ExpressionTypeNested
Definition: VectorwiseOp.h:193
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 OppositeExtendedType< OtherDerived >::Type extendedToOpposite(const DenseBase< OtherDerived > &other) const
Definition: VectorwiseOp.h:254
ReturnType< internal::member_sum >::Type SumReturnType
Definition: VectorwiseOp.h:350
Homogeneous< ExpressionType, Direction > HomogeneousReturnType
Definition: VectorwiseOp.h:708
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
ExpressionType::RealScalar RealScalar
Definition: VectorwiseOp.h:191
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
ReturnType< internal::member_prod >::Type ProdReturnType
Definition: VectorwiseOp.h:355
EIGEN_DEVICE_FUNC ExtendedType< OtherDerived >::Type extendedTo(const DenseBase< OtherDerived > &other) const
Definition: VectorwiseOp.h:231
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
Replicate< ExpressionType,(isVertical?Dynamic:1),(isHorizontal?Dynamic:1)> ReplicateReturnType
Definition: VectorwiseOp.h:552
Block< const ExpressionType, Direction==Vertical ? 1 :int(internal::traits< ExpressionType >::RowsAtCompileTime), Direction==Horizontal ? 1 :int(internal::traits< ExpressionType >::ColsAtCompileTime)> HNormalized_Factors
Definition: VectorwiseOp.h:731
const Replicate< ExpressionType, isVertical *Factor+isHorizontal, isHorizontal *Factor+isVertical > EIGEN_DEVICE_FUNC replicate(Index factor=Factor) const
Definition: VectorwiseOp.h:568
internal::subvector_stl_iterator< ExpressionType, DirectionType(Direction)> iterator
Definition: VectorwiseOp.h:282
internal::subvector_stl_reverse_iterator< ExpressionType, DirectionType(Direction)> reverse_iterator
Definition: VectorwiseOp.h:284
EIGEN_DEVICE_FUNC ExpressionType & operator=(const DenseBase< OtherDerived > &other)
Copies the vector other to each subvector of *this.
Definition: VectorwiseOp.h:579
EIGEN_DEVICE_FUNC VectorwiseOp(ExpressionType &matrix)
Definition: VectorwiseOp.h:268
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
CwiseUnaryOp< internal::scalar_sqrt_op< RealScalar >, const SquaredNormReturnType > NormReturnType
Definition: VectorwiseOp.h:346
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
PartialReduxExpr< const CwiseUnaryOp< internal::scalar_abs2_op< Scalar >, const ExpressionTypeNestedCleaned >, internal::member_sum< RealScalar, RealScalar >, Direction > SquaredNormReturnType
Definition: VectorwiseOp.h:345
ReturnType< internal::member_all >::Type AllReturnType
Definition: VectorwiseOp.h:352
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: core.h:1240
constexpr auto count() -> size_t
Definition: core.h:1204
type
Definition: core.h:575
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
EIGEN_MAKE_PARTIAL_REDUX_FUNCTOR(sum,(Size-1) *NumTraits< Scalar >::AddCost, 1, internal::scalar_sum_op)
EIGEN_MEMBER_FUNCTOR(norm,(Size+5) *NumTraits< Scalar >::MulCost+(Size-1) *NumTraits< Scalar >::AddCost)
Namespace containing all symbols from the Eigen library.
Definition: MatrixExponential.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
Definition: Eigen_Colamd.h:50
Holds information about the various numeric (i.e.
Definition: NumTraits.h:233
Definition: VectorwiseOp.h:220
Replicate< OtherDerived, isVertical ? 1 :ExpressionType::RowsAtCompileTime, isHorizontal ? 1 :ExpressionType::ColsAtCompileTime > Type
Definition: VectorwiseOp.h:223
Definition: VectorwiseOp.h:359
PartialReduxExpr< ExpressionType, internal::member_lpnorm< p, RealScalar, Scalar >, Direction > Type
Definition: VectorwiseOp.h:360
Definition: VectorwiseOp.h:243
Replicate< OtherDerived, isHorizontal ? 1 :ExpressionType::RowsAtCompileTime, isVertical ? 1 :ExpressionType::ColsAtCompileTime > Type
Definition: VectorwiseOp.h:246
Definition: VectorwiseOp.h:206
PartialReduxExpr< ExpressionType, internal::member_redux< BinaryOp, Scalar >, Direction > Type
Definition: VectorwiseOp.h:210
Definition: VectorwiseOp.h:198
PartialReduxExpr< ExpressionType, Functor< ReturnScalar, Scalar >, Direction > Type
Definition: VectorwiseOp.h:202
Definition: XprHelper.h:484
Definition: XprHelper.h:176
Definition: VectorwiseOp.h:124
Definition: VectorwiseOp.h:120
EIGEN_DEVICE_FUNC member_lpnorm()
Definition: VectorwiseOp.h:125
EIGEN_DEVICE_FUNC ResultType operator()(const XprType &mat) const
Definition: VectorwiseOp.h:127
@ Vectorizable
Definition: VectorwiseOp.h:122
ResultType result_type
Definition: VectorwiseOp.h:121
Definition: VectorwiseOp.h:139
Definition: VectorwiseOp.h:132
result_of< BinaryOp(constScalar &, constScalar &)>::type result_type
Definition: VectorwiseOp.h:136
EIGEN_DEVICE_FUNC member_redux(const BinaryOp func)
Definition: VectorwiseOp.h:140
EIGEN_DEVICE_FUNC result_type operator()(const DenseBase< Derived > &mat) const
Definition: VectorwiseOp.h:142
BinaryOpT BinaryOp
Definition: VectorwiseOp.h:133
const BinaryOp & binaryFunc() const
Definition: VectorwiseOp.h:144
@ Vectorizable
Definition: VectorwiseOp.h:138
const BinaryOp m_functor
Definition: VectorwiseOp.h:145
T type
Definition: Meta.h:126
Definition: Meta.h:513
Definition: ForwardDeclarations.h:210
Definition: BinaryFunctors.h:172
Definition: BinaryFunctors.h:139
Definition: BinaryFunctors.h:71
Definition: BinaryFunctors.h:33
traits< MatrixType >::XprKind XprKind
Definition: VectorwiseOp.h:42
traits< MatrixType >::StorageKind StorageKind
Definition: VectorwiseOp.h:41
Definition: ForwardDeclarations.h:17
Definition: Meta.h:96
Definition: VectorwiseOp.h:84