mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Patch by Gael Guennebaud: unify fixed-size and dynamic-size Block
expressions, update documentation.
This commit is contained in:
@@ -27,19 +27,21 @@
|
||||
|
||||
/** \class Block
|
||||
*
|
||||
* \brief Expression of a dynamic-size block
|
||||
* \brief Expression of a fixed-size or dynamic-size block
|
||||
*
|
||||
* \param MatrixType the type of the object in which we are taking a block
|
||||
* \param BlockRows the number of rows of the block we are taking at compile time (optional)
|
||||
* \param BlockCols the number of columns of the block we are taking at compile time (optional)
|
||||
*
|
||||
* This class represents an expression of a dynamic-size block. It is the return
|
||||
* type of MatrixBase::block(int,int,int,int) and most of the time this is the only way it
|
||||
* is used.
|
||||
* This class represents an expression of either a fixed-size or dynamic-size block. It is the return
|
||||
* type of MatrixBase::block(int,int,int,int) and MatrixBase::block<int,int>(int,int) and
|
||||
* most of the time this is the only way it is used.
|
||||
*
|
||||
* However, if you want to directly maniputate dynamic-size block expressions,
|
||||
* However, if you want to directly maniputate 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 this:
|
||||
* Here is an example illustrating the dynamic case:
|
||||
* \include class_Block.cpp
|
||||
* Output: \verbinclude class_Block.out
|
||||
*
|
||||
@@ -47,10 +49,16 @@
|
||||
* has fixed size, this expression inherits a fixed maximal size which means that evaluating
|
||||
* it does not cause a dynamic memory allocation.
|
||||
*
|
||||
* \sa MatrixBase::block(int,int,int,int), class VectorBlock
|
||||
* Here is an example illustrating the fixed-size case:
|
||||
* \include class_FixedBlock.cpp
|
||||
* Output: \verbinclude class_FixedBlock.out
|
||||
*
|
||||
* \sa MatrixBase::block(int,int,int,int), MatrixBase::block(int,int), class VectorBlock
|
||||
*/
|
||||
template<typename MatrixType> class Block
|
||||
: public MatrixBase<typename MatrixType::Scalar, Block<MatrixType> >
|
||||
template<typename MatrixType,
|
||||
int BlockRows/*=Dynamic*/, int BlockCols/*=Dynamic*/> class Block
|
||||
: public MatrixBase<typename MatrixType::Scalar,
|
||||
Block<MatrixType, BlockRows, BlockCols> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
@@ -58,12 +66,26 @@ template<typename MatrixType> class Block
|
||||
friend class MatrixBase<Scalar, Block>;
|
||||
typedef MatrixBase<Scalar, Block> Base;
|
||||
|
||||
/** Fixed-size constructor
|
||||
*/
|
||||
Block(const MatRef& matrix, int startRow, int startCol)
|
||||
: m_matrix(matrix), m_startRow(startRow), m_startCol(startCol)
|
||||
{
|
||||
assert(RowsAtCompileTime!=Dynamic && RowsAtCompileTime!=Dynamic);
|
||||
assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= matrix.rows()
|
||||
&& startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= matrix.cols());
|
||||
}
|
||||
|
||||
/** Dynamic-size constructor
|
||||
*/
|
||||
Block(const MatRef& matrix,
|
||||
int startRow, int startCol,
|
||||
int blockRows, int blockCols)
|
||||
: m_matrix(matrix), m_startRow(startRow), m_startCol(startCol),
|
||||
m_blockRows(blockRows), m_blockCols(blockCols)
|
||||
{
|
||||
assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==1)
|
||||
&& (ColsAtCompileTime==Dynamic || ColsAtCompileTime==1));
|
||||
assert(startRow >= 0 && blockRows >= 1 && startRow + blockRows <= matrix.rows()
|
||||
&& startCol >= 0 && blockCols >= 1 && startCol + blockCols <= matrix.cols());
|
||||
}
|
||||
@@ -71,11 +93,13 @@ template<typename MatrixType> class Block
|
||||
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block)
|
||||
|
||||
private:
|
||||
enum {
|
||||
RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime == 1 ? 1 : Dynamic,
|
||||
ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime == 1 ? 1 : Dynamic,
|
||||
MaxRowsAtCompileTime = RowsAtCompileTime == 1 ? 1 : MatrixType::Traits::MaxRowsAtCompileTime,
|
||||
MaxColsAtCompileTime = ColsAtCompileTime == 1 ? 1 : MatrixType::Traits::MaxColsAtCompileTime
|
||||
enum{
|
||||
RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime == 1 ? 1 : BlockRows,
|
||||
ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime == 1 ? 1 : BlockCols,
|
||||
MaxRowsAtCompileTime = RowsAtCompileTime == 1 ? 1
|
||||
: (BlockRows==Dynamic ? MatrixType::Traits::MaxRowsAtCompileTime : BlockRows),
|
||||
MaxColsAtCompileTime = ColsAtCompileTime == 1 ? 1
|
||||
: (BlockCols==Dynamic ? MatrixType::Traits::MaxColsAtCompileTime : BlockCols)
|
||||
};
|
||||
|
||||
const Block& _ref() const { return *this; }
|
||||
@@ -93,11 +117,10 @@ template<typename MatrixType> class Block
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
MatRef m_matrix;
|
||||
IntAtRunTimeIfDynamic<MatrixType::Traits::RowsAtCompileTime == 1 ? 0 : Dynamic>
|
||||
m_startRow;
|
||||
IntAtRunTimeIfDynamic<MatrixType::Traits::ColsAtCompileTime == 1 ? 0 : Dynamic>
|
||||
m_startCol;
|
||||
IntAtRunTimeIfDynamic<MatrixType::Traits::RowsAtCompileTime == 1 ? 0 : Dynamic> m_startRow;
|
||||
IntAtRunTimeIfDynamic<MatrixType::Traits::ColsAtCompileTime == 1 ? 0 : Dynamic> m_startCol;
|
||||
IntAtRunTimeIfDynamic<RowsAtCompileTime> m_blockRows;
|
||||
IntAtRunTimeIfDynamic<ColsAtCompileTime> m_blockCols;
|
||||
};
|
||||
@@ -116,7 +139,7 @@ template<typename MatrixType> class Block
|
||||
* when it is applied to a fixed-size matrix, it inherits a fixed maximal size,
|
||||
* which means that evaluating it does not cause a dynamic memory allocation.
|
||||
*
|
||||
* \sa class Block, fixedBlock(int,int)
|
||||
* \sa class Block, block(int,int)
|
||||
*/
|
||||
template<typename Scalar, typename Derived>
|
||||
Block<Derived> MatrixBase<Scalar, Derived>
|
||||
@@ -147,7 +170,7 @@ const Block<Derived> MatrixBase<Scalar, Derived>
|
||||
* when it is applied to a fixed-size vector, it inherits a fixed maximal size,
|
||||
* which means that evaluating it does not cause a dynamic memory allocation.
|
||||
*
|
||||
* \sa class Block, fixedBlock(int)
|
||||
* \sa class Block, block(int)
|
||||
*/
|
||||
template<typename Scalar, typename Derived>
|
||||
Block<Derived> MatrixBase<Scalar, Derived>
|
||||
@@ -293,4 +316,34 @@ const Block<Derived> MatrixBase<Scalar, Derived>
|
||||
return Block<Derived>(ref(), rows() - cRows, cols() - cCols, cRows, cCols);
|
||||
}
|
||||
|
||||
/** \returns a fixed-size expression of a block in *this.
|
||||
*
|
||||
* The template parameters \a BlockRows and \a BlockCols are the number of
|
||||
* rows and columns in the block.
|
||||
*
|
||||
* \param startRow the first row in the block
|
||||
* \param startCol the first column in the block
|
||||
*
|
||||
* Example: \include MatrixBase_block_int_int.cpp
|
||||
* Output: \verbinclude MatrixBase_block_int_int.out
|
||||
*
|
||||
* \sa class Block, block(int,int,int,int)
|
||||
*/
|
||||
template<typename Scalar, typename Derived>
|
||||
template<int BlockRows, int BlockCols>
|
||||
Block<Derived, BlockRows, BlockCols> MatrixBase<Scalar, Derived>
|
||||
::block(int startRow, int startCol)
|
||||
{
|
||||
return Block<Derived, BlockRows, BlockCols>(ref(), startRow, startCol);
|
||||
}
|
||||
|
||||
/** This is the const version of block<>(int, int). */
|
||||
template<typename Scalar, typename Derived>
|
||||
template<int BlockRows, int BlockCols>
|
||||
const Block<Derived, BlockRows, BlockCols> MatrixBase<Scalar, Derived>
|
||||
::block(int startRow, int startCol) const
|
||||
{
|
||||
return Block<Derived, BlockRows, BlockCols>(ref(), startRow, startCol);
|
||||
}
|
||||
|
||||
#endif // EIGEN_BLOCK_H
|
||||
|
||||
@@ -31,8 +31,7 @@ template<typename NewScalar, typename MatrixType> class Cast;
|
||||
template<typename MatrixType> class Row;
|
||||
template<typename MatrixType> class Column;
|
||||
template<typename MatrixType> class Minor;
|
||||
template<typename MatrixType> class Block;
|
||||
template<typename MatrixType, int BlockRows, int BlockCols> class FixedBlock;
|
||||
template<typename MatrixType, int BlockRows=Dynamic, int BlockCols=Dynamic> class Block;
|
||||
template<typename MatrixType> class Transpose;
|
||||
template<typename MatrixType> class Conjugate;
|
||||
template<typename MatrixType> class Opposite;
|
||||
|
||||
@@ -200,9 +200,9 @@ template<typename Scalar, typename Derived> class MatrixBase
|
||||
const Block<Derived> corner(CornerType type, int cRows, int cCols) const;
|
||||
|
||||
template<int BlockRows, int BlockCols>
|
||||
FixedBlock<Derived, BlockRows, BlockCols> fixedBlock(int startRow, int startCol);
|
||||
Block<Derived, BlockRows, BlockCols> block(int startRow, int startCol);
|
||||
template<int BlockRows, int BlockCols>
|
||||
const FixedBlock<Derived, BlockRows, BlockCols> fixedBlock(int startRow, int startCol) const;
|
||||
const Block<Derived, BlockRows, BlockCols> block(int startRow, int startCol) const;
|
||||
|
||||
Transpose<Derived> transpose();
|
||||
const Transpose<Derived> transpose() const;
|
||||
|
||||
Reference in New Issue
Block a user