Eigen::VectorBlock< VectorType, Size > Class Template Reference

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

#include <VectorBlock.h>

+ Inheritance diagram for Eigen::VectorBlock< VectorType, Size >:

Public Member Functions

EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE VectorBlock (VectorType &vector, Index start, Index size)
 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE VectorBlock (VectorType &vector, Index start)
 
- Public Member Functions inherited from Eigen::Block< VectorType, internal::traits< VectorType >::Flags &RowMajorBit ? 1 :Size, internal::traits< VectorType >::Flags &RowMajorBit ? Size :1 >
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Block (VectorType &xpr, Index i)
 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Block (VectorType &xpr, Index startRow, Index startCol)
 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Block (VectorType &xpr, Index startRow, Index startCol, Index blockRows, Index blockCols)
 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ConstUnwindReturnType unwind () const
 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE UnwindReturnType unwind ()
 

Private Types

enum  { IsColVector = !(internal::traits<VectorType>::Flags & RowMajorBit) }
 
typedef Block< VectorType, internal::traits< VectorType >::Flags &RowMajorBit ? 1 :Size, internal::traits< VectorType >::Flags &RowMajorBit ? Size :1 > Base
 

Additional Inherited Members

- Public Types inherited from Eigen::Block< VectorType, internal::traits< VectorType >::Flags &RowMajorBit ? 1 :Size, internal::traits< VectorType >::Flags &RowMajorBit ? Size :1 >
typedef Impl Base
 
typedef internal::remove_all_t< VectorTypeNestedExpression
 
using ConstUnwindReturnType = Block< const typename BlockHelper::BaseType, BlockRows, BlockCols, InnerPanel >
 
using UnwindReturnType = Block< typename BlockHelper::BaseType, BlockRows, BlockCols, InnerPanel >
 

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>
return Eigen::VectorBlock<Derived>(v.derived(), start, end - start);
}
template <typename Derived>
}
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;
}
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
int main(int argc, char *argv[])
Definition: T_protectiveWall.cpp:194
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
Expression of a fixed-size or dynamic-size sub-vector.
Definition: VectorBlock.h:58
Eigen::VectorBlock< Derived > segmentFromRange(Eigen::MatrixBase< Derived > &v, int start, int end)
Definition: class_VectorBlock.cpp:5
static constexpr lastp1_t end
Definition: IndexedViewHelper.h:79
void start(const unsigned &i)
(Re-)start i-th timer
Definition: oomph_utilities.cc:243

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>
return Eigen::VectorBlock<Derived, 2>(v.derived(), 0);
}
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;
}
Eigen::VectorBlock< Derived, 2 > firstTwo(Eigen::MatrixBase< Derived > &v)
Definition: class_FixedVectorBlock.cpp:5

Output:

See also
class Block, DenseBase::segment(Index,Index,Index,Index), DenseBase::segment(Index,Index)

Member Typedef Documentation

◆ Base

template<typename VectorType , int Size>
typedef Block<VectorType, internal::traits<VectorType>::Flags & RowMajorBit ? 1 : Size, internal::traits<VectorType>::Flags & RowMajorBit ? Size : 1> Eigen::VectorBlock< VectorType, Size >::Base
private

Member Enumeration Documentation

◆ anonymous enum

template<typename VectorType , int Size>
anonymous enum
private
Enumerator
IsColVector 
62 { IsColVector = !(internal::traits<VectorType>::Flags & RowMajorBit) };
@ IsColVector
Definition: VectorBlock.h:62
const unsigned int RowMajorBit
Definition: Constants.h:70

Constructor & Destructor Documentation

◆ VectorBlock() [1/2]

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

Dynamic-size constructor

72  : Base(vector, IsColVector ? start : 0, IsColVector ? 0 : start, IsColVector ? size : 1, IsColVector ? 1 : size) {
73  }
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
Block< VectorType, internal::traits< VectorType >::Flags &RowMajorBit ? 1 :Size, internal::traits< VectorType >::Flags &RowMajorBit ? Size :1 > Base
Definition: VectorBlock.h:61

◆ VectorBlock() [2/2]

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

Fixed-size constructor

78  : Base(vector, IsColVector ? start : 0, IsColVector ? 0 : start) {}

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