Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
Eigen::VectorBlock< VectorType, Size > Class Template Reference

Detailed Description

template<typename VectorType, int Size>
class Eigen::VectorBlock< VectorType, Size >

Expression of a fixed-size or dynamic-size sub-vector.

Template Parameters
VectorTypethe type of the object in which we are taking a sub-vector
Sizesize of the sub-vector we are taking at compile time (optional)

This class represents an expression of either a fixed-size or dynamic-size sub-vector. It is the return type of DenseBase::segment(Index,Index) and DenseBase::segment<int>(Index) and most of the time this is the only way it is used.

However, if you want to directly manipulate sub-vector expressions, for instance if you want to write a function returning such an expression, you will need to use this class.

Here is an example illustrating the dynamic case:

#include <Eigen/Core>
#include <iostream>
template <typename Derived>
Eigen::VectorBlock<Derived> segmentFromRange(Eigen::MatrixBase<Derived>& v, int start, int end) {
return Eigen::VectorBlock<Derived>(v.derived(), start, end - start);
}
template <typename Derived>
const Eigen::VectorBlock<const Derived> segmentFromRange(const Eigen::MatrixBase<Derived>& v, int start, int end) {
return Eigen::VectorBlock<const Derived>(v.derived(), start, end - start);
}
int main(int, char**) {
v << 1, 2, 3, 4, 5, 6;
std::cout << segmentFromRange(2 * v, 2, 4) << std::endl; // calls the const version
segmentFromRange(v, 1, 3) *= 5; // calls the non-const version
std::cout << "Now the vector v is:" << std::endl << v << std::endl;
return 0;
}
Derived & derived()
Definition EigenBase.h:49
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:52
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:186
Expression of a fixed-size or dynamic-size sub-vector.
Definition VectorBlock.h:58

Output:

Note
Even though this expression has dynamic size, in the case where VectorType has fixed size, this expression inherits a fixed maximal size which means that evaluating it does not cause a dynamic memory allocation.

Here is an example illustrating the fixed-size case:

#include <Eigen/Core>
#include <iostream>
template <typename Derived>
}
template <typename Derived>
}
int main(int, char**) {
v << 1, 2, 3, 4, 5, 6;
std::cout << firstTwo(4 * v) << std::endl; // calls the const version
firstTwo(v) *= 2; // calls the non-const version
std::cout << "Now the vector v is:" << std::endl << v << std::endl;
return 0;
}

Output:

See also
class Block, DenseBase::segment(Index,Index,Index,Index), DenseBase::segment(Index,Index)
+ Inheritance diagram for Eigen::VectorBlock< VectorType, Size >:

Public Member Functions

 VectorBlock (VectorType &vector, Index start)
 
 VectorBlock (VectorType &vector, Index start, Index size)
 

Constructor & Destructor Documentation

◆ VectorBlock() [1/2]

template<typename VectorType , int Size>
Eigen::VectorBlock< VectorType, Size >::VectorBlock ( VectorType & vector,
Index start,
Index size )
inline

Dynamic-size constructor

◆ VectorBlock() [2/2]

template<typename VectorType , int Size>
Eigen::VectorBlock< VectorType, Size >::VectorBlock ( VectorType & vector,
Index start )
inline

Fixed-size constructor


The documentation for this class was generated from the following file: