aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/plugins/BlockMethods.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2017-01-17 11:34:28 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2017-01-17 11:34:28 +0100
commit4f36dcfda88be7737fbbe5145c52fca6d164ca91 (patch)
tree6370e8473ccab68607f5406a7b8996d4e9f590f2 /Eigen/src/plugins/BlockMethods.h
parent71e5b713563ba9a61ab58901f3034d7248a879d7 (diff)
Add a generic block() method compatible with Eigen::fix
Diffstat (limited to 'Eigen/src/plugins/BlockMethods.h')
-rw-r--r--Eigen/src/plugins/BlockMethods.h60
1 files changed, 58 insertions, 2 deletions
diff --git a/Eigen/src/plugins/BlockMethods.h b/Eigen/src/plugins/BlockMethods.h
index ac35a0086..38020730c 100644
--- a/Eigen/src/plugins/BlockMethods.h
+++ b/Eigen/src/plugins/BlockMethods.h
@@ -773,7 +773,7 @@ inline typename ConstNColsBlockXpr<N>::Type middleCols(Index startCol, Index n =
///
EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
///
-/// \sa class Block, block(Index,Index,Index,Index)
+/// \sa block(Index,Index,NRowsType,NColsType), class Block, block(Index,Index,Index,Index)
///
template<int NRows, int NCols>
EIGEN_DEVICE_FUNC
@@ -809,7 +809,7 @@ inline const typename ConstFixedBlockXpr<NRows,NCols>::Type block(Index startRow
///
EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
///
-/// \sa class Block, block(Index,Index,Index,Index)
+/// \sa block(Index,Index,NRowsType,NColsType), block(Index,Index,Index,Index), class Block
///
template<int NRows, int NCols>
inline typename FixedBlockXpr<NRows,NCols>::Type block(Index startRow, Index startCol,
@@ -826,6 +826,62 @@ inline const typename ConstFixedBlockXpr<NRows,NCols>::Type block(Index startRow
return typename ConstFixedBlockXpr<NRows,NCols>::Type(derived(), startRow, startCol, blockRows, blockCols);
}
+/// \returns an expression of a block in \c *this.
+///
+/// \tparam NRowsType the type of the object handling the number of rows in the block, can be any integral type (e.g., int, Index) or any returned by Eigen::fix<N> or Eigen::fix<N>(n).
+/// \tparam NColsType analogue of NRowsType but for the number of columns.
+/// \param startRow the first row in the block
+/// \param startCol the first column in the block
+/// \param blockRows number of rows in the block as specified at either run-time or compile-time
+/// \param blockCols number of columns in the block as specified at either run-time or compile-time
+///
+/// \newin{3.4}
+///
+/// This function covers the same versatility as block<NRows,NCols>(Index, Index), and block<NRows,NCols>(Index, Index, Index, Index)
+/// but with less redundancy and more consistency as it does not modify the argument order
+/// and seamlessly enable hybrid fixed/dynamic sizes.
+/// The one-to-one full equivalences are as follows:
+///
+/// \code
+/// mat.template block<NRows,NCols>(i,j) <--> mat.block(i,j,fix<NRows>,fix<NCols>)
+/// mat.template block<NRows,NCols>(i,j,rows,cols) <--> mat.block(i,j,fix<NRows>(rows),fix<NCols>(cols))
+/// \endcode
+///
+/// but of course, with this version one of the compile-time parameter can be completely
+/// omitted if it turns out to be a pure runtime one:
+/// \code
+/// mat.template block<NRows,Dynamic>(i,j,rows,cols) <--> mat.block(i,j,fix<NRows>,cols)
+/// \endcode
+///
+EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
+///
+/// \sa class Block, block(Index,Index,Index,Index), fix
+///
+template<typename NRowsType, typename NColsType>
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+inline typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+#else
+inline typename FixedBlockXpr<...,...>::Type
+#endif
+block(Index startRow, Index startCol, NRowsType blockRows, NColsType blockCols)
+{
+ return typename FixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type(
+ derived(), startRow, startCol, internal::get_runtime_value(blockRows), internal::get_runtime_value(blockCols));
+}
+
+/// This is the const version of block(Index,Index,NRowsType,NColsType)
+template<typename NRowsType, typename NColsType>
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+inline typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type
+#else
+inline typename ConstFixedBlockXpr<...,...>::Type
+#endif
+block(Index startRow, Index startCol, NRowsType blockRows, NColsType blockCols) const
+{
+ return typename ConstFixedBlockXpr<internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>::Type(
+ derived(), startRow, startCol, internal::get_runtime_value(blockRows), internal::get_runtime_value(blockCols));
+}
+
/// \returns an expression of the \a i-th column of *this. Note that the numbering starts at 0.
///
/// Example: \include MatrixBase_col.cpp