template<typename ExpressionType, int Direction>
class Eigen::VectorwiseOp< ExpressionType, Direction >
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:
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;
Matrix< double, 3, 3 > Matrix3d
3×3 matrix of type double.
Definition Matrix.h:479
Output:
Here is the matrix m:
0.696 0.334 0.445
0.205 -0.47 -0.633
-0.415 0.928 0.0241
Here is the sum of each column:
0.487 0.792 -0.163
Here is the maximum absolute value of each column:
0.696 0.928 0.633
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:
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;
Matrix< int, 3, 3 > Matrix3i
3×3 matrix of type int.
Definition Matrix.h:477
Output:
Here is the initial matrix m:
1804289383 719885386 -1364114958
-465790871 -1550966999 2044897763
-189735855 -1122281286 1365180540
Here is the matrix m after the for-range-loop:
-1804289383 0 -1364114958
465790871 0 2044897763
189735855 0 1365180540
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))
- See also
- DenseBase::colwise(), DenseBase::rowwise(), class PartialReduxExpr
|
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
|
|
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 |
|