Please, help us to better know about our user community by answering the following short survey: https://forms.gle/wpyrxWi18ox9Z5ae9 Eigen  3.3.90 (git rev ecb7bc9514b12051d050299234b2a74ac76b5a8e) Eigen::VectorwiseOp Class Reference

## Detailed Description

Pseudo expression providing broadcasting and partial reduction operations.

Template Parameters
 ExpressionType the type of the object on which to do partial reductions Direction indicates whether to operate on columns (Vertical) or rows (Horizontal)

This class represents a pseudo expression with broadcasting and partial reduction features. It is the return type of DenseBase::colwise() and DenseBase::rowwise() and most of the time this is the only way it is explicitly used.

To understand the logic of rowwise/colwise expression, let's consider a generic case `A.colwise().foo()` where `foo` is any method of `VectorwiseOp`. This expression is equivalent to applying `foo()` to each column of `A` and then re-assemble the outputs in a matrix expression:

[A.col(0).foo(), A.col(1).foo(), ..., A.col(A.cols()-1).foo()]

Example:

Matrix3d m = Matrix3d::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the sum of each column:" << endl << m.colwise().sum() << endl;
cout << "Here is the maximum absolute value of each column:"
<< endl << m.cwiseAbs().colwise().maxCoeff() << endl;

Output:

```Here is the matrix m:
0.68  0.597  -0.33
-0.211  0.823  0.536
0.566 -0.605 -0.444
Here is the sum of each column:
1.04  0.815 -0.238
Here is the maximum absolute value of each column:
0.68 0.823 0.536
```

The begin() and end() methods are obviously exceptions to the previous rule as they return STL-compatible begin/end iterators to the rows or columns of the nested expression. Typical use cases include for-range-loop and calls to STL algorithms:

Example:

Matrix3i m = Matrix3i::Random();
cout << "Here is the initial matrix m:" << endl << m << endl;
int i = -1;
for(auto c: m.colwise()) {
c *= i;
++i;
}
cout << "Here is the matrix m after the for-range-loop:" << endl << m << endl;
auto cols = m.colwise();
auto it = std::find_if(cols.cbegin(), cols.cend(),
[](Matrix3i::ConstColXpr x) { return x.squaredNorm() == 0; });
cout << "The first empty column is: " << distance(cols.cbegin(),it) << endl;

Output:

```Here is the initial matrix m:
7  6 -3
-2  9  6
6 -6 -5
Here is the matrix m after the for-range-loop:
-7  0 -3
2  0  6
-6  0 -5
The first empty column is: 1
```

For a partial reduction on an empty input, some rules apply. For the sake of clarity, let's consider a vertical reduction:

• If the number of columns is zero, then a 1x0 row-major vector expression is returned.
• Otherwise, if the number of rows is zero, then
• a row vector of zeros is returned for sum-like reductions (sum, squaredNorm, norm, etc.)
• a row vector of ones is returned for a product reduction (e.g., `MatrixXd(n,0).colwise().prod()`)
• an assert is triggered for all other reductions (minCoeff,maxCoeff,redux(bin_op))
DenseBase::colwise(), DenseBase::rowwise(), class PartialReduxExpr

## Public Types

typedef Eigen::Index Index

## Public Member Functions

const AllReturnType all () const

const AnyReturnType any () const

iterator begin ()

const_iterator begin () const

const BlueNormReturnType blueNorm () const

const_iterator cbegin () const

const_iterator cend () const

const CountReturnType count () const

const_reverse_iterator crbegin () const

const_reverse_iterator crend () const

template<typename OtherDerived >
const CrossReturnType cross (const MatrixBase< OtherDerived > &other) const

iterator end ()

const_iterator end () const

const HNormalizedReturnType hnormalized () const
column or row-wise homogeneous normalization More...

HomogeneousReturnType homogeneous () const

const HypotNormReturnType hypotNorm () const

template<int p>
const LpNormReturnType< p >::Type lpNorm () const

const MaxCoeffReturnType maxCoeff () const

const MeanReturnType mean () const

const MinCoeffReturnType minCoeff () const

const NormReturnType norm () const

void normalize ()

CwiseBinaryOp< internal::scalar_quotient_op< Scalar >, const ExpressionTypeNestedCleaned, const typename OppositeExtendedType< NormReturnType >::Type > normalized () const

template<typename OtherDerived >
CwiseBinaryOp< internal::scalar_product_op< Scalar >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > operator* (const DenseBase< OtherDerived > &other) const

template<typename OtherDerived >
ExpressionType & operator*= (const DenseBase< OtherDerived > &other)

template<typename OtherDerived >
CwiseBinaryOp< internal::scalar_sum_op< Scalar, typename OtherDerived::Scalar >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > operator+ (const DenseBase< OtherDerived > &other) const

template<typename OtherDerived >
ExpressionType & operator+= (const DenseBase< OtherDerived > &other)

template<typename OtherDerived >
CwiseBinaryOp< internal::scalar_difference_op< Scalar, typename OtherDerived::Scalar >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > operator- (const DenseBase< OtherDerived > &other) const

template<typename OtherDerived >
ExpressionType & operator-= (const DenseBase< OtherDerived > &other)

template<typename OtherDerived >
CwiseBinaryOp< internal::scalar_quotient_op< Scalar >, const ExpressionTypeNestedCleaned, const typename ExtendedType< OtherDerived >::Type > operator/ (const DenseBase< OtherDerived > &other) const

template<typename OtherDerived >
ExpressionType & operator/= (const DenseBase< OtherDerived > &other)

template<typename OtherDerived >
ExpressionType & operator= (const DenseBase< OtherDerived > &other)

const ProdReturnType prod () const

reverse_iterator rbegin ()

const_reverse_iterator rbegin () const

template<typename BinaryOp >
const ReduxReturnType< BinaryOp >::Type redux (const BinaryOp &func=BinaryOp()) const

reverse_iterator rend ()

const_reverse_iterator rend () const

const ReplicateReturnType replicate (Index factor) const

template<int Factor>
const Replicate< ExpressionType, isVertical *Factor+isHorizontal, isHorizontal *Factor+isVertical > replicate (Index factor=Factor) const

ReverseReturnType reverse ()

const ConstReverseReturnType reverse () const

void reverseInPlace ()

const SquaredNormReturnType squaredNorm () const

const StableNormReturnType stableNorm () const

const SumReturnType sum () const

## Public Attributes

random_access_iterator_type const_iterator

random_access_iterator_type iterator

Deprecated:
since Eigen 3.3

## ◆ all()

 const AllReturnType Eigen::VectorwiseOp::all ( ) const
inline
Returns
a row (or column) vector expression representing whether all coefficients of each respective column (or row) are `true`. This expression can be assigned to a vector with entries of type `bool`.
DenseBase::all()

## ◆ any()

 const AnyReturnType Eigen::VectorwiseOp::any ( ) const
inline
Returns
a row (or column) vector expression representing whether at least one coefficient of each respective column (or row) is `true`. This expression can be assigned to a vector with entries of type `bool`.
DenseBase::any()

## ◆ begin() [1/2]

 iterator Eigen::VectorwiseOp::begin ( )
inline

returns an iterator to the first row (rowwise) or column (colwise) of the nested expression.

end(), cbegin()

## ◆ begin() [2/2]

 const_iterator Eigen::VectorwiseOp::begin ( ) const
inline

const version of begin()

## ◆ blueNorm()

 const BlueNormReturnType Eigen::VectorwiseOp::blueNorm ( ) const
inline
Returns
a row (or column) vector expression of the norm of each column (or row) of the referenced expression, using Blue's algorithm. This is a vector with real entries, even if the original matrix has complex entries.
DenseBase::blueNorm()

## ◆ cbegin()

 const_iterator Eigen::VectorwiseOp::cbegin ( ) const
inline

const version of begin()

## ◆ cend()

 const_iterator Eigen::VectorwiseOp::cend ( ) const
inline

const version of end()

## ◆ count()

 const CountReturnType Eigen::VectorwiseOp::count ( ) const
inline
Returns
a row (or column) vector expression representing the number of `true` coefficients of each respective column (or row). This expression can be assigned to a vector whose entries have the same type as is used to index entries of the original matrix; for dense matrices, this is `std::ptrdiff_t` .

Example:

Matrix3d m = Matrix3d::Random();
cout << "Here is the matrix m:" << endl << m << endl;
Matrix<ptrdiff_t, 3, 1> res = (m.array() >= 0.5).rowwise().count();
cout << "Here is the count of elements larger or equal than 0.5 of each row:" << endl;
cout << res << endl;

Output:

```Here is the matrix m:
0.68  0.597  -0.33
-0.211  0.823  0.536
0.566 -0.605 -0.444
Here is the count of elements larger or equal than 0.5 of each row:
2
2
1
```
DenseBase::count()

## ◆ crbegin()

 const_reverse_iterator Eigen::VectorwiseOp::crbegin ( ) const
inline

const version of rbegin()

## ◆ crend()

 const_reverse_iterator Eigen::VectorwiseOp::crend ( ) const
inline

const version of rend()

## ◆ end() [1/2]

 iterator Eigen::VectorwiseOp::end ( )
inline

returns an iterator to the row (resp. column) following the last row (resp. column) of the nested expression

begin(), cend()

## ◆ end() [2/2]

 const_iterator Eigen::VectorwiseOp::end ( ) const
inline

const version of end()

## ◆ hypotNorm()

 const HypotNormReturnType Eigen::VectorwiseOp::hypotNorm ( ) const
inline
Returns
a row (or column) vector expression of the norm of each column (or row) of the referenced expression, avoiding underflow and overflow using a concatenation of hypot() calls. This is a vector with real entries, even if the original matrix has complex entries.
DenseBase::hypotNorm()

## ◆ lpNorm()

template<int p>
 const LpNormReturnType

::Type Eigen::VectorwiseOp::lpNorm ( ) const

inline
Returns
a row (or column) vector expression of the norm of each column (or row) of the referenced expression. This is a vector with real entries, even if the original matrix has complex entries.

Example:

Matrix3d m = Matrix3d::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the norm of each column:" << endl << m.colwise().norm() << endl;

Output:

```Here is the matrix m:
0.68  0.597  -0.33
-0.211  0.823  0.536
0.566 -0.605 -0.444
Here is the norm of each column:
0.91  1.18 0.771
```
DenseBase::norm()

## ◆ maxCoeff()

 const MaxCoeffReturnType Eigen::VectorwiseOp::maxCoeff ( ) const
inline
Returns
a row (or column) vector expression of the largest coefficient of each column (or row) of the referenced expression.
Warning
the size along the reduction direction must be strictly positive, otherwise an assertion is triggered.
the result is undefined if `*this` contains NaN.

Example:

Matrix3d m = Matrix3d::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the maximum of each column:" << endl << m.colwise().maxCoeff() << endl;

Output:

```Here is the matrix m:
0.68  0.597  -0.33
-0.211  0.823  0.536
0.566 -0.605 -0.444
Here is the maximum of each column:
0.68 0.823 0.536
```
DenseBase::maxCoeff()

## ◆ mean()

 const MeanReturnType Eigen::VectorwiseOp::mean ( ) const
inline
Returns
a row (or column) vector expression of the mean of each column (or row) of the referenced expression.
DenseBase::mean()

## ◆ minCoeff()

 const MinCoeffReturnType Eigen::VectorwiseOp::minCoeff ( ) const
inline
Returns
a row (or column) vector expression of the smallest coefficient of each column (or row) of the referenced expression.
Warning
the size along the reduction direction must be strictly positive, otherwise an assertion is triggered.
the result is undefined if `*this` contains NaN.

Example:

Matrix3d m = Matrix3d::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the minimum of each column:" << endl << m.colwise().minCoeff() << endl;

Output:

```Here is the matrix m:
0.68  0.597  -0.33
-0.211  0.823  0.536
0.566 -0.605 -0.444
Here is the minimum of each column:
-0.211 -0.605 -0.444
```
DenseBase::minCoeff()

## ◆ norm()

 const NormReturnType Eigen::VectorwiseOp::norm ( ) const
inline
Returns
a row (or column) vector expression of the norm of each column (or row) of the referenced expression. This is a vector with real entries, even if the original matrix has complex entries.

Example:

Matrix3d m = Matrix3d::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the norm of each column:" << endl << m.colwise().norm() << endl;

Output:

```Here is the matrix m:
0.68  0.597  -0.33
-0.211  0.823  0.536
0.566 -0.605 -0.444
Here is the norm of each column:
0.91  1.18 0.771
```
DenseBase::norm()

## ◆ normalize()

 void Eigen::VectorwiseOp::normalize ( )
inline

Normalize in-place each row or columns of the referenced matrix.

MatrixBase::normalize(), normalized()

## ◆ normalized()

 CwiseBinaryOp, const ExpressionTypeNestedCleaned, const typename OppositeExtendedType::Type> Eigen::VectorwiseOp::normalized ( ) const
inline
Returns
an expression where each column (or row) of the referenced matrix are normalized. The referenced matrix is not modified.
MatrixBase::normalized(), normalize()

## ◆ operator*()

template<typename OtherDerived >
 CwiseBinaryOp, const ExpressionTypeNestedCleaned, const typename ExtendedType::Type> Eigen::VectorwiseOp::operator* ( const DenseBase< OtherDerived > & other ) const
inline

Returns the expression where each subvector is the product of the vector other by the corresponding subvector of `*this`

## ◆ operator*=()

template<typename OtherDerived >
 ExpressionType& Eigen::VectorwiseOp::operator*= ( const DenseBase< OtherDerived > & other )
inline

Multiples each subvector of `*this` by the vector other

## ◆ operator+()

template<typename OtherDerived >
 CwiseBinaryOp, const ExpressionTypeNestedCleaned, const typename ExtendedType::Type> Eigen::VectorwiseOp::operator+ ( const DenseBase< OtherDerived > & other ) const
inline

Returns the expression of the sum of the vector other to each subvector of `*this`

## ◆ operator+=()

template<typename OtherDerived >
 ExpressionType& Eigen::VectorwiseOp::operator+= ( const DenseBase< OtherDerived > & other )
inline

Adds the vector other to each subvector of `*this`

## ◆ operator-()

template<typename OtherDerived >
 CwiseBinaryOp, const ExpressionTypeNestedCleaned, const typename ExtendedType::Type> Eigen::VectorwiseOp::operator- ( const DenseBase< OtherDerived > & other ) const
inline

Returns the expression of the difference between each subvector of `*this` and the vector other

## ◆ operator-=()

template<typename OtherDerived >
 ExpressionType& Eigen::VectorwiseOp::operator-= ( const DenseBase< OtherDerived > & other )
inline

Substracts the vector other to each subvector of `*this`

## ◆ operator/()

template<typename OtherDerived >
 CwiseBinaryOp, const ExpressionTypeNestedCleaned, const typename ExtendedType::Type> Eigen::VectorwiseOp::operator/ ( const DenseBase< OtherDerived > & other ) const
inline

Returns the expression where each subvector is the quotient of the corresponding subvector of `*this` by the vector other

## ◆ operator/=()

template<typename OtherDerived >
 ExpressionType& Eigen::VectorwiseOp::operator/= ( const DenseBase< OtherDerived > & other )
inline

Divides each subvector of `*this` by the vector other

## ◆ operator=()

template<typename OtherDerived >
 ExpressionType& Eigen::VectorwiseOp::operator= ( const DenseBase< OtherDerived > & other )
inline

Copies the vector other to each subvector of `*this`

## ◆ prod()

 const ProdReturnType Eigen::VectorwiseOp::prod ( ) const
inline
Returns
a row (or column) vector expression of the product of each column (or row) of the referenced expression.

Example:

Matrix3d m = Matrix3d::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the product of each row:" << endl << m.rowwise().prod() << endl;

Output:

```Here is the matrix m:
0.68  0.597  -0.33
-0.211  0.823  0.536
0.566 -0.605 -0.444
Here is the product of each row:
-0.134
-0.0933
0.152
```
DenseBase::prod()

## ◆ rbegin() [1/2]

 reverse_iterator Eigen::VectorwiseOp::rbegin ( )
inline

returns a reverse iterator to the last row (rowwise) or column (colwise) of the nested expression.

rend(), crbegin()

## ◆ rbegin() [2/2]

 const_reverse_iterator Eigen::VectorwiseOp::rbegin ( ) const
inline

const version of rbegin()

## ◆ redux()

template<typename BinaryOp >
 const ReduxReturnType::Type Eigen::VectorwiseOp::redux ( const BinaryOp & func = `BinaryOp()` ) const
inline
Returns
a row or column vector expression of `*this` reduxed by func

The template parameter BinaryOp is the type of the functor of the custom redux operator. Note that func must be an associative operator.

Warning
the size along the reduction direction must be strictly positive, otherwise an assertion is triggered.
class VectorwiseOp, DenseBase::colwise(), DenseBase::rowwise()

## ◆ rend() [1/2]

 reverse_iterator Eigen::VectorwiseOp::rend ( )
inline

returns a reverse iterator to the row (resp. column) before the first row (resp. column) of the nested expression

begin(), cend()

## ◆ rend() [2/2]

 const_reverse_iterator Eigen::VectorwiseOp::rend ( ) const
inline

const version of rend()

## ◆ replicate() [1/2]

 const VectorwiseOp< ExpressionType, Direction >::ReplicateReturnType Eigen::VectorwiseOp::replicate ( Index factor ) const
Returns
an expression of the replication of each column (or row) of `*this`

Example:

Vector3i v = Vector3i::Random();
cout << "Here is the vector v:" << endl << v << endl;
cout << "v.rowwise().replicate(5) = ..." << endl;
cout << v.rowwise().replicate(5) << endl;

Output:

```Here is the vector v:
7
-2
6
v.rowwise().replicate(5) = ...
7  7  7  7  7
-2 -2 -2 -2 -2
6  6  6  6  6
```
VectorwiseOp::replicate(), DenseBase::replicate(), class Replicate

## ◆ replicate() [2/2]

template<int Factor>
 const Replicate Eigen::VectorwiseOp::replicate ( Index factor = `Factor` ) const
inline
Returns
an expression of the replication of each column (or row) of `*this`

Example:

MatrixXi m = MatrixXi::Random(2,3);
cout << "Here is the matrix m:" << endl << m << endl;
cout << "m.colwise().replicate<3>() = ..." << endl;
cout << m.colwise().replicate<3>() << endl;

Output:

```Here is the matrix m:
7  6  9
-2  6 -6
m.colwise().replicate<3>() = ...
7  6  9
-2  6 -6
7  6  9
-2  6 -6
7  6  9
-2  6 -6
```
VectorwiseOp::replicate(Index), DenseBase::replicate(), class Replicate

## ◆ reverse() [1/2]

 ReverseReturnType Eigen::VectorwiseOp::reverse ( )
inline
Returns
a writable matrix expression where each column (or row) are reversed.
reverse() const

## ◆ reverse() [2/2]

 const ConstReverseReturnType Eigen::VectorwiseOp::reverse ( ) const
inline
Returns
a matrix expression where each column (or row) are reversed.

Example:

MatrixXi m = MatrixXi::Random(3,4);
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the rowwise reverse of m:" << endl << m.rowwise().reverse() << endl;
cout << "Here is the colwise reverse of m:" << endl << m.colwise().reverse() << endl;
cout << "Here is the coefficient (1,0) in the rowise reverse of m:" << endl
<< m.rowwise().reverse()(1,0) << endl;
cout << "Let us overwrite this coefficient with the value 4." << endl;
//m.colwise().reverse()(1,0) = 4;
cout << "Now the matrix m is:" << endl << m << endl;

Output:

```Here is the matrix m:
7  6 -3  1
-2  9  6  0
6 -6 -5  3
Here is the rowwise reverse of m:
1 -3  6  7
0  6  9 -2
3 -5 -6  6
Here is the colwise reverse of m:
6 -6 -5  3
-2  9  6  0
7  6 -3  1
Here is the coefficient (1,0) in the rowise reverse of m:
0
Let us overwrite this coefficient with the value 4.
Now the matrix m is:
7  6 -3  1
-2  9  6  0
6 -6 -5  3
```
DenseBase::reverse()

## ◆ reverseInPlace()

 void Eigen::VectorwiseOp::reverseInPlace ( )
inline

This is the "in place" version of VectorwiseOp::reverse: it reverses each column or row of `*this`.

In most cases it is probably better to simply use the reversed expression of a matrix. However, when reversing the matrix data itself is really needed, then this "in-place" version is probably the right choice because it provides the following additional benefits:

• less error prone: doing the same operation with .reverse() requires special care:
m = m.reverse().eval();
• this API enables reverse operations without the need for a temporary
DenseBase::reverseInPlace(), reverse()

## ◆ squaredNorm()

 const SquaredNormReturnType Eigen::VectorwiseOp::squaredNorm ( ) const
inline
Returns
a row (or column) vector expression of the squared norm of each column (or row) of the referenced expression. This is a vector with real entries, even if the original matrix has complex entries.

Example:

Matrix3d m = Matrix3d::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the square norm of each row:" << endl << m.rowwise().squaredNorm() << endl;

Output:

```Here is the matrix m:
0.68  0.597  -0.33
-0.211  0.823  0.536
0.566 -0.605 -0.444
Here is the square norm of each row:
0.928
1.01
0.884
```
DenseBase::squaredNorm()

## ◆ stableNorm()

 const StableNormReturnType Eigen::VectorwiseOp::stableNorm ( ) const
inline
Returns
a row (or column) vector expression of the norm of each column (or row) of the referenced expression, avoiding underflow and overflow. This is a vector with real entries, even if the original matrix has complex entries.
DenseBase::stableNorm()

## ◆ sum()

 const SumReturnType Eigen::VectorwiseOp::sum ( ) const
inline
Returns
a row (or column) vector expression of the sum of each column (or row) of the referenced expression.

Example:

Matrix3d m = Matrix3d::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the sum of each row:" << endl << m.rowwise().sum() << endl;

Output:

```Here is the matrix m:
0.68  0.597  -0.33
-0.211  0.823  0.536
0.566 -0.605 -0.444
Here is the sum of each row:
0.948
1.15
-0.483
```
DenseBase::sum()

## ◆ const_iterator

 random_access_iterator_type Eigen::VectorwiseOp::const_iterator

This is the const version of iterator (aka read-only)

## ◆ iterator

 random_access_iterator_type Eigen::VectorwiseOp::iterator

STL-like RandomAccessIterator iterator type over the columns or rows as returned by the begin() and end() methods.

The documentation for this class was generated from the following files:
Eigen::DenseBase::Random
static const RandomReturnType Random()
Definition: Random.h:113