template<typename ExpressionType, int Direction>
VectorwiseOp class
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) |
Contents
This class represents a pseudo expression with broadcasting and partial reduction features. It is the return type of DenseBase::
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))
Public types
- enum (anonymous) { isVertical = (Direction==Vertical) ? 1 : 0, isHorizontal = (Direction==Horizontal) ? 1 : 0 }
- enum (anonymous) { HNormalized_Size = Direction==Vertical ? internal::traits<ExpressionType>::RowsAtCompileTime : internal::traits<ExpressionType>::ColsAtCompileTime, HNormalized_SizeMinusOne = HNormalized_Size==Dynamic ? Dynamic : HNormalized_Size-1 }
- using AllReturnType = ReturnType<internal::member_all>::Type
- using AnyReturnType = ReturnType<internal::member_any>::Type
- using BlueNormReturnType = ReturnType<internal::member_blueNorm, RealScalar>::Type
- using ConstReverseReturnType = Reverse<const ExpressionType, Direction>
- using CountReturnType = PartialReduxExpr<ExpressionType, internal::member_count<Index, Scalar>, Direction>
- using CrossReturnType = ExpressionType::PlainObject
- using ExpressionTypeNested = internal::ref_selector<ExpressionType>::non_const_type
- using ExpressionTypeNestedCleaned = internal::remove_all<ExpressionTypeNested>::type
- using HNormalized_Block = Block<const ExpressionType, Direction==Vertical ? int(HNormalized_SizeMinusOne) :int(internal::traits<ExpressionType>::RowsAtCompileTime), Direction==Horizontal ? int(HNormalized_SizeMinusOne) :int(internal::traits<ExpressionType>::ColsAtCompileTime)>
- using HNormalized_Factors = Block<const ExpressionType, Direction==Vertical ? 1 :int(internal::traits<ExpressionType>::RowsAtCompileTime), Direction==Horizontal ? 1 :int(internal::traits<ExpressionType>::ColsAtCompileTime)>
-
using HNormalizedReturnType = 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>> - using HomogeneousReturnType = Homogeneous<ExpressionType, Direction>
- using HypotNormReturnType = ReturnType<internal::member_hypotNorm, RealScalar>::Type
-
using Index = Eigen::
Index deprecated - using MaxCoeffReturnType = ReturnType<internal::member_maxCoeff>::Type
- using MinCoeffReturnType = ReturnType<internal::member_minCoeff>::Type
- using NormReturnType = CwiseUnaryOp<internal::scalar_sqrt_op<RealScalar>, const SquaredNormReturnType>
- using ProdReturnType = ReturnType<internal::member_prod>::Type
- using RealScalar = ExpressionType::RealScalar
- using ReplicateReturnType = Replicate<ExpressionType,(isVertical?Dynamic:1),(isHorizontal?Dynamic:1)>
- using ReverseReturnType = Reverse<ExpressionType, Direction>
- using Scalar = ExpressionType::Scalar
- using SquaredNormReturnType = PartialReduxExpr<const CwiseUnaryOp<internal::scalar_abs2_op<Scalar>, const ExpressionTypeNestedCleaned>, internal::member_sum<RealScalar, RealScalar>, Direction>
- using StableNormReturnType = ReturnType<internal::member_stableNorm, RealScalar>::Type
- using SumReturnType = ReturnType<internal::member_sum>::Type
Constructors, destructors, conversion operators
- VectorwiseOp(ExpressionType& matrix) explicit
Public functions
- auto _expression() const -> const ExpressionType&
- auto all() const -> const AllReturnType
- auto any() const -> const AnyReturnType
- auto begin() const -> iterator
- auto blueNorm() const -> const BlueNormReturnType
-
auto cbegin() const -> const_
iterator -
auto cend() const -> const_
iterator - auto count() const -> const CountReturnType
-
template<typename OtherDerived>auto cross(const MatrixBase<OtherDerived>& other) const -> const CrossReturnType
- auto EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(SumReturnType, Scalar, quotient) MeanReturnType -> typedef
- auto end() const -> iterator
- auto hnormalized() const -> const HNormalizedReturnType
- column or row-wise homogeneous normalization
- auto homogeneous() const -> HomogeneousReturnType
- auto hypotNorm() const -> const HypotNormReturnType
-
template<int p>auto lpNorm() const -> const LpNormReturnType<p>::Type
- auto maxCoeff() const -> const MaxCoeffReturnType
- auto mean() const -> const MeanReturnType
- auto minCoeff() const -> const MinCoeffReturnType
- auto norm() const -> const NormReturnType
- void normalize()
- auto normalized() const -> CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, const ExpressionTypeNestedCleaned, const typename OppositeExtendedType<NormReturnType>::Type>
-
template<typename OtherDerived>auto operator*(const DenseBase<OtherDerived>& other) const -> CwiseBinaryOp<internal::scalar_product_op<Scalar>, const ExpressionTypeNestedCleaned, const typename ExtendedType<OtherDerived>::Type>
-
template<typename OtherDerived>auto operator*=(const DenseBase<OtherDerived>& other) -> ExpressionType&
-
template<typename OtherDerived>auto operator+(const DenseBase<OtherDerived>& other) const -> CwiseBinaryOp<internal::scalar_sum_op<Scalar, typename OtherDerived::Scalar>, const ExpressionTypeNestedCleaned, const typename ExtendedType<OtherDerived>::Type>
-
template<typename OtherDerived>auto operator+=(const DenseBase<OtherDerived>& other) -> ExpressionType&
-
template<typename OtherDerived>auto operator-(const DenseBase<OtherDerived>& other) const -> CwiseBinaryOp<internal::scalar_difference_op<Scalar, typename OtherDerived::Scalar>, const ExpressionTypeNestedCleaned, const typename ExtendedType<OtherDerived>::Type>
-
template<typename OtherDerived>auto operator-=(const DenseBase<OtherDerived>& other) -> ExpressionType&
-
template<typename OtherDerived>auto operator/(const DenseBase<OtherDerived>& other) const -> CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, const ExpressionTypeNestedCleaned, const typename ExtendedType<OtherDerived>::Type>
-
template<typename OtherDerived>auto operator/=(const DenseBase<OtherDerived>& other) -> ExpressionType&
-
template<typename OtherDerived>auto operator=(const DenseBase<OtherDerived>& other) -> ExpressionType&
- auto prod() const -> const ProdReturnType
-
template<typename BinaryOp>auto redux(const BinaryOp& func = BinaryOp()) const -> const ReduxReturnType<BinaryOp>::Type
- auto replicate(Index factor) const -> const ReplicateReturnType
-
template<int Factor>auto replicate(Index factor = Factor) const -> const Replicate<ExpressionType, isVertical*Factor+isHorizontal, isHorizontal*Factor+isVertical>
- auto reverse() const -> const ConstReverseReturnType
- auto reverse() -> ReverseReturnType
- void reverseInPlace()
- auto squaredNorm() const -> const SquaredNormReturnType
- auto stableNorm() const -> const StableNormReturnType
- auto sum() const -> const SumReturnType
Public variables
- random_access_iterator_type const_iterator
- random_access_iterator_type iterator
Protected functions
-
template<typename OtherDerived>auto extendedTo(const DenseBase<OtherDerived>& other) const -> ExtendedType<OtherDerived>::Type
-
template<typename OtherDerived>auto extendedToOpposite(const DenseBase<OtherDerived>& other) const -> OppositeExtendedType<OtherDerived>::Type
- auto redux_length() const -> Index
Protected variables
- ExpressionTypeNested m_matrix
Enum documentation
template<typename ExpressionType, int Direction>
enum Eigen:: VectorwiseOp<ExpressionType, Direction>:: (anonymous)
Enumerators | |
---|---|
isVertical | |
isHorizontal |
template<typename ExpressionType, int Direction>
enum Eigen:: VectorwiseOp<ExpressionType, Direction>:: (anonymous)
Enumerators | |
---|---|
HNormalized_Size | |
HNormalized_SizeMinusOne |
Typedef documentation
template<typename ExpressionType, int Direction>
typedef ReturnType<internal::member_all>::Type Eigen:: VectorwiseOp<ExpressionType, Direction>:: AllReturnType
template<typename ExpressionType, int Direction>
typedef ReturnType<internal::member_any>::Type Eigen:: VectorwiseOp<ExpressionType, Direction>:: AnyReturnType
template<typename ExpressionType, int Direction>
typedef ReturnType<internal::member_blueNorm, RealScalar>::Type Eigen:: VectorwiseOp<ExpressionType, Direction>:: BlueNormReturnType
template<typename ExpressionType, int Direction>
typedef Reverse<const ExpressionType, Direction> Eigen:: VectorwiseOp<ExpressionType, Direction>:: ConstReverseReturnType
template<typename ExpressionType, int Direction>
typedef PartialReduxExpr<ExpressionType, internal::member_count<Index, Scalar>, Direction> Eigen:: VectorwiseOp<ExpressionType, Direction>:: CountReturnType
template<typename ExpressionType, int Direction>
typedef ExpressionType::PlainObject Eigen:: VectorwiseOp<ExpressionType, Direction>:: CrossReturnType
template<typename ExpressionType, int Direction>
typedef internal::ref_selector<ExpressionType>::non_const_type Eigen:: VectorwiseOp<ExpressionType, Direction>:: ExpressionTypeNested
template<typename ExpressionType, int Direction>
typedef internal::remove_all<ExpressionTypeNested>::type Eigen:: VectorwiseOp<ExpressionType, Direction>:: ExpressionTypeNestedCleaned
template<typename ExpressionType, int Direction>
typedef Block<const ExpressionType, Direction==Vertical ? int(HNormalized_SizeMinusOne) :int(internal::traits<ExpressionType>::RowsAtCompileTime), Direction==Horizontal ? int(HNormalized_SizeMinusOne) :int(internal::traits<ExpressionType>::ColsAtCompileTime)> Eigen:: VectorwiseOp<ExpressionType, Direction>:: HNormalized_Block
template<typename ExpressionType, int Direction>
typedef Block<const ExpressionType, Direction==Vertical ? 1 :int(internal::traits<ExpressionType>::RowsAtCompileTime), Direction==Horizontal ? 1 :int(internal::traits<ExpressionType>::ColsAtCompileTime)> Eigen:: VectorwiseOp<ExpressionType, Direction>:: HNormalized_Factors
template<typename ExpressionType, int Direction>
typedef 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>> Eigen:: VectorwiseOp<ExpressionType, Direction>:: HNormalizedReturnType
template<typename ExpressionType, int Direction>
typedef Homogeneous<ExpressionType, Direction> Eigen:: VectorwiseOp<ExpressionType, Direction>:: HomogeneousReturnType
template<typename ExpressionType, int Direction>
typedef ReturnType<internal::member_hypotNorm, RealScalar>::Type Eigen:: VectorwiseOp<ExpressionType, Direction>:: HypotNormReturnType
template<typename ExpressionType, int Direction>
typedef Eigen:: Index Eigen:: VectorwiseOp<ExpressionType, Direction>:: Index
template<typename ExpressionType, int Direction>
typedef ReturnType<internal::member_maxCoeff>::Type Eigen:: VectorwiseOp<ExpressionType, Direction>:: MaxCoeffReturnType
template<typename ExpressionType, int Direction>
typedef ReturnType<internal::member_minCoeff>::Type Eigen:: VectorwiseOp<ExpressionType, Direction>:: MinCoeffReturnType
template<typename ExpressionType, int Direction>
typedef CwiseUnaryOp<internal::scalar_sqrt_op<RealScalar>, const SquaredNormReturnType> Eigen:: VectorwiseOp<ExpressionType, Direction>:: NormReturnType
template<typename ExpressionType, int Direction>
typedef ReturnType<internal::member_prod>::Type Eigen:: VectorwiseOp<ExpressionType, Direction>:: ProdReturnType
template<typename ExpressionType, int Direction>
typedef ExpressionType::RealScalar Eigen:: VectorwiseOp<ExpressionType, Direction>:: RealScalar
template<typename ExpressionType, int Direction>
typedef Replicate<ExpressionType,(isVertical?Dynamic:1),(isHorizontal?Dynamic:1)> Eigen:: VectorwiseOp<ExpressionType, Direction>:: ReplicateReturnType
template<typename ExpressionType, int Direction>
typedef Reverse<ExpressionType, Direction> Eigen:: VectorwiseOp<ExpressionType, Direction>:: ReverseReturnType
template<typename ExpressionType, int Direction>
typedef ExpressionType::Scalar Eigen:: VectorwiseOp<ExpressionType, Direction>:: Scalar
template<typename ExpressionType, int Direction>
typedef PartialReduxExpr<const CwiseUnaryOp<internal::scalar_abs2_op<Scalar>, const ExpressionTypeNestedCleaned>, internal::member_sum<RealScalar, RealScalar>, Direction> Eigen:: VectorwiseOp<ExpressionType, Direction>:: SquaredNormReturnType
template<typename ExpressionType, int Direction>
typedef ReturnType<internal::member_stableNorm, RealScalar>::Type Eigen:: VectorwiseOp<ExpressionType, Direction>:: StableNormReturnType
template<typename ExpressionType, int Direction>
typedef ReturnType<internal::member_sum>::Type Eigen:: VectorwiseOp<ExpressionType, Direction>:: SumReturnType
Function documentation
template<typename ExpressionType, int Direction>
Eigen:: VectorwiseOp<ExpressionType, Direction>:: VectorwiseOp(ExpressionType& matrix) explicit
template<typename ExpressionType, int Direction>
const ExpressionType& Eigen:: VectorwiseOp<ExpressionType, Direction>:: _expression() const
template<typename ExpressionType, int Direction>
const AllReturnType Eigen:: VectorwiseOp<ExpressionType, Direction>:: all() const
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 . |
---|
template<typename ExpressionType, int Direction>
const AnyReturnType Eigen:: VectorwiseOp<ExpressionType, Direction>:: any() const
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 . |
---|
template<typename ExpressionType, int Direction>
const BlueNormReturnType Eigen:: VectorwiseOp<ExpressionType, Direction>:: blueNorm() const
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. |
---|
template<typename ExpressionType, int Direction>
const_ iterator Eigen:: VectorwiseOp<ExpressionType, Direction>:: cbegin() const
const version of begin()
template<typename ExpressionType, int Direction>
const_ iterator Eigen:: VectorwiseOp<ExpressionType, Direction>:: cend() const
const version of end()
template<typename ExpressionType, int Direction>
const CountReturnType Eigen:: VectorwiseOp<ExpressionType, Direction>:: count() const
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
template<typename ExpressionType, int Direction>
template<typename OtherDerived>
const CrossReturnType Eigen:: VectorwiseOp<ExpressionType, Direction>:: cross(const MatrixBase<OtherDerived>& other) const
Returns | a matrix expression of the cross product of each column or row of the referenced expression with the other vector. |
---|
This is defined in the Geometry module. #include <Eigen/Geometry>
The referenced matrix must have one dimension equal to 3. The result matrix has the same dimensions than the referenced one.
template<typename ExpressionType, int Direction>
typedef Eigen:: VectorwiseOp<ExpressionType, Direction>:: EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(SumReturnType,
Scalar,
quotient) MeanReturnType
template<typename ExpressionType, int Direction>
const HNormalizedReturnType Eigen:: VectorwiseOp<ExpressionType, Direction>:: hnormalized() const
column or row-wise homogeneous normalization
Returns | an expression of the first N-1 coefficients of each column (or row) of *this divided by the last coefficient of each column (or row). |
---|
This is defined in the Geometry module. #include <Eigen/Geometry>
This can be used to convert homogeneous coordinates to affine coordinates.
It is conceptually equivalent to calling MatrixBase::*this
.
Example:
Matrix4Xd M = Matrix4Xd::Random(4,5); Projective3d P(Matrix4d::Random()); cout << "The matrix M is:" << endl << M << endl << endl; cout << "M.colwise().hnormalized():" << endl << M.colwise().hnormalized() << endl << endl; cout << "P*M:" << endl << P*M << endl << endl; cout << "(P*M).colwise().hnormalized():" << endl << (P*M).colwise().hnormalized() << endl << endl;
Output:
The matrix M is: 0.68 0.823 -0.444 -0.27 0.271 -0.211 -0.605 0.108 0.0268 0.435 0.566 -0.33 -0.0452 0.904 -0.717 0.597 0.536 0.258 0.832 0.214 M.colwise().hnormalized(): 1.14 1.53 -1.72 -0.325 1.27 -0.354 -1.13 0.419 0.0322 2.03 0.949 -0.614 -0.175 1.09 -3.35 P*M: 0.186 -0.589 0.369 1.33 -1.23 -0.871 -0.337 0.127 -0.715 0.091 -0.158 -0.0104 0.312 0.429 -0.478 0.992 0.777 -0.373 0.468 -0.651 (P*M).colwise().hnormalized(): 0.188 -0.759 -0.989 2.85 1.89 -0.877 -0.433 -0.342 -1.53 -0.14 -0.16 -0.0134 -0.837 0.915 0.735
template<typename ExpressionType, int Direction>
HomogeneousReturnType Eigen:: VectorwiseOp<ExpressionType, Direction>:: homogeneous() const
Returns | an expression where the value 1 is symbolically appended as the final coefficient to each column (or row) of the matrix. |
---|
This is defined in the Geometry module. #include <Eigen/Geometry>
This can be used to convert affine coordinates to homogeneous coordinates.
Example:
Matrix3Xd M = Matrix3Xd::Random(3,5); Projective3d P(Matrix4d::Random()); cout << "The matrix M is:" << endl << M << endl << endl; cout << "M.colwise().homogeneous():" << endl << M.colwise().homogeneous() << endl << endl; cout << "P * M.colwise().homogeneous():" << endl << P * M.colwise().homogeneous() << endl << endl; cout << "P * M.colwise().homogeneous().hnormalized(): " << endl << (P * M.colwise().homogeneous()).colwise().hnormalized() << endl << endl;
Output:
The matrix M is: 0.68 0.597 -0.33 0.108 -0.27 -0.211 0.823 0.536 -0.0452 0.0268 0.566 -0.605 -0.444 0.258 0.904 M.colwise().homogeneous(): 0.68 0.597 -0.33 0.108 -0.27 -0.211 0.823 0.536 -0.0452 0.0268 0.566 -0.605 -0.444 0.258 0.904 1 1 1 1 1 P * M.colwise().homogeneous(): 0.0832 -0.477 -1.21 -0.545 -0.452 0.998 0.779 0.695 0.894 0.277 -0.271 -0.608 -0.895 -0.544 -0.874 -0.728 -0.551 0.202 -0.21 -0.469 P * M.colwise().homogeneous().hnormalized(): -0.114 0.866 -6 2.6 0.962 -1.37 -1.41 3.44 -4.27 -0.591 0.373 1.1 -4.43 2.6 1.86
template<typename ExpressionType, int Direction>
const HypotNormReturnType Eigen:: VectorwiseOp<ExpressionType, Direction>:: hypotNorm() const
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. |
---|
template<typename ExpressionType, int Direction>
template<int p>
const LpNormReturnType<p>::Type Eigen:: VectorwiseOp<ExpressionType, Direction>:: lpNorm() const
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
template<typename ExpressionType, int Direction>
const MaxCoeffReturnType Eigen:: VectorwiseOp<ExpressionType, Direction>:: maxCoeff() const
Returns | a row (or column) vector expression of the largest coefficient 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 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
template<typename ExpressionType, int Direction>
const MeanReturnType Eigen:: VectorwiseOp<ExpressionType, Direction>:: mean() const
Returns | a row (or column) vector expression of the mean of each column (or row) of the referenced expression. |
---|
template<typename ExpressionType, int Direction>
const MinCoeffReturnType Eigen:: VectorwiseOp<ExpressionType, Direction>:: minCoeff() const
Returns | a row (or column) vector expression of the smallest coefficient 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 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
template<typename ExpressionType, int Direction>
const NormReturnType Eigen:: VectorwiseOp<ExpressionType, Direction>:: norm() const
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
template<typename ExpressionType, int Direction>
void Eigen:: VectorwiseOp<ExpressionType, Direction>:: normalize()
Normalize in-place each row or columns of the referenced matrix.
template<typename ExpressionType, int Direction>
CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, const ExpressionTypeNestedCleaned, const typename OppositeExtendedType<NormReturnType>::Type> Eigen:: VectorwiseOp<ExpressionType, Direction>:: normalized() const
Returns | an expression where each column (or row) of the referenced matrix are normalized. The referenced matrix is not modified. |
---|
template<typename ExpressionType, int Direction>
template<typename OtherDerived>
CwiseBinaryOp<internal::scalar_product_op<Scalar>, const ExpressionTypeNestedCleaned, const typename ExtendedType<OtherDerived>::Type> Eigen:: VectorwiseOp<ExpressionType, Direction>:: operator*(const DenseBase<OtherDerived>& other) const
Returns the expression where each subvector is the product of the vector other by the corresponding subvector of *this
template<typename ExpressionType, int Direction>
template<typename OtherDerived>
ExpressionType& Eigen:: VectorwiseOp<ExpressionType, Direction>:: operator*=(const DenseBase<OtherDerived>& other)
Multiples each subvector of *this
by the vector other
template<typename ExpressionType, int Direction>
template<typename OtherDerived>
CwiseBinaryOp<internal::scalar_sum_op<Scalar, typename OtherDerived::Scalar>, const ExpressionTypeNestedCleaned, const typename ExtendedType<OtherDerived>::Type> Eigen:: VectorwiseOp<ExpressionType, Direction>:: operator+(const DenseBase<OtherDerived>& other) const
Returns the expression of the sum of the vector other to each subvector of *this
template<typename ExpressionType, int Direction>
template<typename OtherDerived>
ExpressionType& Eigen:: VectorwiseOp<ExpressionType, Direction>:: operator+=(const DenseBase<OtherDerived>& other)
Adds the vector other to each subvector of *this
template<typename ExpressionType, int Direction>
template<typename OtherDerived>
CwiseBinaryOp<internal::scalar_difference_op<Scalar, typename OtherDerived::Scalar>, const ExpressionTypeNestedCleaned, const typename ExtendedType<OtherDerived>::Type> Eigen:: VectorwiseOp<ExpressionType, Direction>:: operator-(const DenseBase<OtherDerived>& other) const
Returns the expression of the difference between each subvector of *this
and the vector other
template<typename ExpressionType, int Direction>
template<typename OtherDerived>
ExpressionType& Eigen:: VectorwiseOp<ExpressionType, Direction>:: operator-=(const DenseBase<OtherDerived>& other)
Substracts the vector other to each subvector of *this
template<typename ExpressionType, int Direction>
template<typename OtherDerived>
CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, const ExpressionTypeNestedCleaned, const typename ExtendedType<OtherDerived>::Type> Eigen:: VectorwiseOp<ExpressionType, Direction>:: operator/(const DenseBase<OtherDerived>& other) const
Returns the expression where each subvector is the quotient of the corresponding subvector of *this
by the vector other
template<typename ExpressionType, int Direction>
template<typename OtherDerived>
ExpressionType& Eigen:: VectorwiseOp<ExpressionType, Direction>:: operator/=(const DenseBase<OtherDerived>& other)
Divides each subvector of *this
by the vector other
template<typename ExpressionType, int Direction>
const ProdReturnType Eigen:: VectorwiseOp<ExpressionType, Direction>:: prod() const
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
template<typename ExpressionType, int Direction>
template<typename BinaryOp>
const ReduxReturnType<BinaryOp>::Type Eigen:: VectorwiseOp<ExpressionType, Direction>:: redux(const BinaryOp& func = BinaryOp()) const
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.
template<typename ExpressionType, int Direction>
const ReplicateReturnType Eigen:: VectorwiseOp<ExpressionType, Direction>:: 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
template<typename ExpressionType, int Direction>
template<int Factor>
const Replicate<ExpressionType, isVertical*Factor+isHorizontal, isHorizontal*Factor+isVertical> Eigen:: VectorwiseOp<ExpressionType, Direction>:: replicate(Index factor = Factor) const
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
template<typename ExpressionType, int Direction>
const ConstReverseReturnType Eigen:: VectorwiseOp<ExpressionType, Direction>:: reverse() const
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
template<typename ExpressionType, int Direction>
ReverseReturnType Eigen:: VectorwiseOp<ExpressionType, Direction>:: reverse()
Returns | a writable matrix expression where each column (or row) are reversed. |
---|
template<typename ExpressionType, int Direction>
void Eigen:: VectorwiseOp<ExpressionType, Direction>:: reverseInPlace()
This is the "in place" version of VectorwiseOp::*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
template<typename ExpressionType, int Direction>
const SquaredNormReturnType Eigen:: VectorwiseOp<ExpressionType, Direction>:: squaredNorm() const
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
template<typename ExpressionType, int Direction>
const StableNormReturnType Eigen:: VectorwiseOp<ExpressionType, Direction>:: stableNorm() const
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. |
---|
template<typename ExpressionType, int Direction>
const SumReturnType Eigen:: VectorwiseOp<ExpressionType, Direction>:: sum() const
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
template<typename ExpressionType, int Direction>
template<typename OtherDerived>
ExtendedType<OtherDerived>::Type Eigen:: VectorwiseOp<ExpressionType, Direction>:: extendedTo(const DenseBase<OtherDerived>& other) const protected
template<typename ExpressionType, int Direction>
template<typename OtherDerived>
OppositeExtendedType<OtherDerived>::Type Eigen:: VectorwiseOp<ExpressionType, Direction>:: extendedToOpposite(const DenseBase<OtherDerived>& other) const protected
template<typename ExpressionType, int Direction>
Index Eigen:: VectorwiseOp<ExpressionType, Direction>:: redux_length() const protected
Variable documentation
template<typename ExpressionType, int Direction>
random_access_iterator_type Eigen:: VectorwiseOp<ExpressionType, Direction>:: const_iterator
This is the const version of iterator (aka read-only)
template<typename ExpressionType, int Direction>
random_access_iterator_type Eigen:: VectorwiseOp<ExpressionType, Direction>:: iterator
STL-like RandomAccessIterator iterator type over the columns or rows as returned by the begin() and end() methods.