Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel > Class Template Reference

Expression of a fixed-size or dynamic-size block. More...

#include <Block.h>

+ Inheritance diagram for Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >:

Public Types

typedef Impl Base
 
typedef internal::remove_all_t< XprTypeNestedExpression
 
using ConstUnwindReturnType = Block< const typename BlockHelper::BaseType, BlockRows, BlockCols, InnerPanel >
 
using UnwindReturnType = Block< typename BlockHelper::BaseType, BlockRows, BlockCols, InnerPanel >
 

Public Member Functions

EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Block (XprType &xpr, Index i)
 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Block (XprType &xpr, Index startRow, Index startCol)
 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Block (XprType &xpr, Index startRow, Index startCol, Index blockRows, Index blockCols)
 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ConstUnwindReturnType unwind () const
 
template<typename T = Block, typename EnableIf = std::enable_if_t<!std::is_const<T>::value>>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE UnwindReturnType unwind ()
 

Private Types

typedef BlockImpl< XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits< XprType >::StorageKind > Impl
 
using BlockHelper = internal::block_xpr_helper< Block >
 

Detailed Description

template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
class Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >

Expression of a fixed-size or dynamic-size block.

Template Parameters
XprTypethe type of the expression in which we are taking a block
BlockRowsthe number of rows of the block we are taking at compile time (optional)
BlockColsthe number of columns of the block we are taking at compile time (optional)
InnerPanelis true, if the block maps to a set of rows of a row major matrix or to set of columns of a column major matrix (optional). The parameter allows to determine at compile time whether aligned access is possible on the block expression.

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

However, if you want to directly manipulate block 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::Block<Derived>(m.derived(), 0, 0, rows, cols);
}
template <typename Derived>
return Eigen::Block<const Derived>(m.derived(), 0, 0, rows, cols);
}
int main(int, char**) {
Eigen::Matrix4d m = Eigen::Matrix4d::Identity();
std::cout << topLeftCorner(4 * m, 2, 3) << std::endl; // calls the const version
topLeftCorner(m, 2, 3) *= 5; // calls the non-const version
std::cout << "Now the matrix m is:" << std::endl << m << std::endl;
return 0;
}
int main(int argc, char *argv[])
Definition: T_protectiveWall.cpp:194
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:110
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
Eigen::Block< Derived > topLeftCorner(Eigen::MatrixBase< Derived > &m, int rows, int cols)
Definition: class_Block.cpp:5
int * m
Definition: level2_cplx_impl.h:294

Output:

Note
Even though this expression has dynamic size, in the case where XprType 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::Block<Derived, 2, 2>(m.derived(), 0, 0);
}
template <typename Derived>
return Eigen::Block<const Derived, 2, 2>(m.derived(), 0, 0);
}
int main(int, char**) {
Eigen::Matrix3d m = Eigen::Matrix3d::Identity();
std::cout << topLeft2x2Corner(4 * m) << std::endl; // calls the const version
topLeft2x2Corner(m) *= 2; // calls the non-const version
std::cout << "Now the matrix m is:" << std::endl << m << std::endl;
return 0;
}
Eigen::Block< Derived, 2, 2 > topLeft2x2Corner(Eigen::MatrixBase< Derived > &m)
Definition: class_FixedBlock.cpp:5

Output:

See also
DenseBase::block(Index,Index,Index,Index), DenseBase::block(Index,Index), class VectorBlock

Member Typedef Documentation

◆ Base

template<typename XprType , int BlockRows, int BlockCols, bool InnerPanel>
typedef Impl Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >::Base

◆ BlockHelper

template<typename XprType , int BlockRows, int BlockCols, bool InnerPanel>
using Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >::BlockHelper = internal::block_xpr_helper<Block>
private

◆ ConstUnwindReturnType

template<typename XprType , int BlockRows, int BlockCols, bool InnerPanel>
using Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >::ConstUnwindReturnType = Block<const typename BlockHelper::BaseType, BlockRows, BlockCols, InnerPanel>

◆ Impl

template<typename XprType , int BlockRows, int BlockCols, bool InnerPanel>
typedef BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits<XprType>::StorageKind> Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >::Impl
private

◆ NestedExpression

template<typename XprType , int BlockRows, int BlockCols, bool InnerPanel>
typedef internal::remove_all_t<XprType> Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >::NestedExpression

◆ UnwindReturnType

template<typename XprType , int BlockRows, int BlockCols, bool InnerPanel>
using Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >::UnwindReturnType = Block<typename BlockHelper::BaseType, BlockRows, BlockCols, InnerPanel>

Constructor & Destructor Documentation

◆ Block() [1/3]

template<typename XprType , int BlockRows, int BlockCols, bool InnerPanel>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >::Block ( XprType xpr,
Index  i 
)
inline

Column or Row constructor

124  : Impl(xpr, i) {
125  eigen_assert((i >= 0) && (((BlockRows == 1) && (BlockCols == XprType::ColsAtCompileTime) && i < xpr.rows()) ||
126  ((BlockRows == XprType::RowsAtCompileTime) && (BlockCols == 1) && i < xpr.cols())));
127  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define eigen_assert(x)
Definition: Macros.h:910
BlockImpl< XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits< XprType >::StorageKind > Impl
Definition: Block.h:111
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: CwiseBinaryOp.h:116
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: CwiseBinaryOp.h:111

References eigen_assert, and i.

◆ Block() [2/3]

template<typename XprType , int BlockRows, int BlockCols, bool InnerPanel>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >::Block ( XprType xpr,
Index  startRow,
Index  startCol 
)
inline

Fixed-size constructor

132  : Impl(xpr, startRow, startCol) {
133  EIGEN_STATIC_ASSERT(RowsAtCompileTime != Dynamic && ColsAtCompileTime != Dynamic,
134  THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE)
135  eigen_assert(startRow >= 0 && BlockRows >= 0 && startRow + BlockRows <= xpr.rows() && startCol >= 0 &&
136  BlockCols >= 0 && startCol + BlockCols <= xpr.cols());
137  }
#define EIGEN_STATIC_ASSERT(X, MSG)
Definition: StaticAssert.h:26
const int Dynamic
Definition: Constants.h:25

References Eigen::Dynamic, eigen_assert, and EIGEN_STATIC_ASSERT.

◆ Block() [3/3]

template<typename XprType , int BlockRows, int BlockCols, bool InnerPanel>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >::Block ( XprType xpr,
Index  startRow,
Index  startCol,
Index  blockRows,
Index  blockCols 
)
inline

Dynamic-size constructor

143  : Impl(xpr, startRow, startCol, blockRows, blockCols) {
144  eigen_assert((RowsAtCompileTime == Dynamic || RowsAtCompileTime == blockRows) &&
145  (ColsAtCompileTime == Dynamic || ColsAtCompileTime == blockCols));
146  eigen_assert(startRow >= 0 && blockRows >= 0 && startRow <= xpr.rows() - blockRows && startCol >= 0 &&
147  blockCols >= 0 && startCol <= xpr.cols() - blockCols);
148  }

References Eigen::Dynamic, and eigen_assert.

Member Function Documentation

◆ unwind() [1/2]

template<typename XprType , int BlockRows, int BlockCols, bool InnerPanel>
template<typename T = Block, typename EnableIf = std::enable_if_t<!std::is_const<T>::value>>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE UnwindReturnType Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >::unwind ( )
inline
161  {
162  return UnwindReturnType(BlockHelper::base(*this), BlockHelper::row(*this, 0), BlockHelper::col(*this, 0),
163  this->rows(), this->cols());
164  }
Block< typename BlockHelper::BaseType, BlockRows, BlockCols, InnerPanel > UnwindReturnType
Definition: Block.h:153
static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE BaseType & base(XprType &xpr)
Definition: XprHelper.h:950
static constexpr EIGEN_ALWAYS_INLINE Index col(const XprType &, Index c)
Definition: XprHelper.h:955
static constexpr EIGEN_ALWAYS_INLINE Index row(const XprType &, Index r)
Definition: XprHelper.h:954

References col(), cols, row(), and rows.

◆ unwind() [2/2]

template<typename XprType , int BlockRows, int BlockCols, bool InnerPanel>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ConstUnwindReturnType Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >::unwind ( ) const
inline
155  {
156  return ConstUnwindReturnType(BlockHelper::base(*this), BlockHelper::row(*this, 0), BlockHelper::col(*this, 0),
157  this->rows(), this->cols());
158  }
Block< const typename BlockHelper::BaseType, BlockRows, BlockCols, InnerPanel > ConstUnwindReturnType
Definition: Block.h:152

References col(), cols, row(), and rows.

Referenced by unwind_test_impl< BaseXpr, Xpr, Depth >::run().


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