diff --git a/Eigen/Core b/Eigen/Core index b1aaa8774..12b55b0da 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -22,7 +22,7 @@ namespace Eigen { #include "src/Core/Product.h" #include "src/Core/Row.h" #include "src/Core/Column.h" -#include "src/Core/DynBlock.h" +#include "src/Core/FixedBlock.h" #include "src/Core/Block.h" #include "src/Core/Minor.h" #include "src/Core/Transpose.h" diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index 22410b9be..28c39f3d0 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -28,17 +28,15 @@ /** \class Block * - * \brief Expression of a fixed-size block + * \brief Expression of a 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 - * \param BlockCols the number of columns of the block we are taking * - * This class represents an expression of a fixed-size block. It is the return + * This class represents an expression of a dynamic-size block. It is the return * type of MatrixBase::block() and most of the time this is the only way it * is used. * - * However, if you want to directly maniputate fixed-size block expressions, + * However, if you want to directly maniputate dynamic-size block expressions, * for instance if you want to write a function returning such an expression, you * will need to use this class. * @@ -46,37 +44,39 @@ * \include class_Block.cpp * Output: \verbinclude class_Block.out * - * \sa MatrixBase::block(), class DynBlock + * \sa MatrixBase::block() */ -template class Block - : public MatrixBase > +template class Block + : public MatrixBase > { public: typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::Ref MatRef; - friend class MatrixBase >; + friend class MatrixBase >; - Block(const MatRef& matrix, int startRow, int startCol) - : m_matrix(matrix), m_startRow(startRow), m_startCol(startCol) + 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(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= matrix.rows() - && startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= matrix.cols()); + assert(startRow >= 0 && blockRows >= 1 && startRow + blockRows <= matrix.rows() + && startCol >= 0 && blockCols >= 1 && startCol + blockCols <= matrix.cols()); } EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block) private: - enum{ - RowsAtCompileTime = BlockRows, - ColsAtCompileTime = BlockCols, - MaxRowsAtCompileTime = BlockRows, - MaxColsAtCompileTime = BlockCols + 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 }; const Block& _ref() const { return *this; } - int _rows() const { return BlockRows; } - int _cols() const { return BlockCols; } + int _rows() const { return m_blockRows; } + int _cols() const { return m_blockCols; } Scalar& _coeffRef(int row, int col) { @@ -90,37 +90,35 @@ template class Block protected: MatRef m_matrix; - const int m_startRow, m_startCol; + const int m_startRow, m_startCol, m_blockRows, m_blockCols; }; -/** \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 +/** \returns a dynamic-size expression of a block in *this. * * \param startRow the first row in the block * \param startCol the first column in the block + * \param blockRows the number of rows in the block + * \param blockCols the number of columns in the block * * Example: \include MatrixBase_block.cpp * Output: \verbinclude MatrixBase_block.out * - * \sa class Block, dynBlock() + * \sa class Block, fixedBlock() */ template -template -Block MatrixBase - ::block(int startRow, int startCol) +Block MatrixBase + ::block(int startRow, int startCol, int blockRows, int blockCols) { - return Block(ref(), startRow, startCol); + return Block(ref(), startRow, startCol, blockRows, blockCols); } /** This is the const version of block(). */ template -template -const Block MatrixBase - ::block(int startRow, int startCol) const +const Block MatrixBase + ::block(int startRow, int startCol, int blockRows, int blockCols) const { - return Block(ref(), startRow, startCol); + return Block(ref(), startRow, startCol, blockRows, blockCols); } + #endif // EIGEN_BLOCK_H diff --git a/Eigen/src/Core/DynBlock.h b/Eigen/src/Core/FixedBlock.h similarity index 50% rename from Eigen/src/Core/DynBlock.h rename to Eigen/src/Core/FixedBlock.h index 3c863bb80..00d7e558a 100644 --- a/Eigen/src/Core/DynBlock.h +++ b/Eigen/src/Core/FixedBlock.h @@ -23,60 +23,60 @@ // License. This exception does not invalidate any other reasons why a work // based on this file might be covered by the GNU General Public License. -#ifndef EIGEN_DYNBLOCK_H -#define EIGEN_DYNBLOCK_H +#ifndef EIGEN_FIXEDBLOCK_H +#define EIGEN_FIXEDBLOCK_H -/** \class DynBlock +/** \class FixedBlock * - * \brief Expression of a dynamic-size block + * \brief Expression of a fixed-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 + * \param BlockCols the number of columns of the block we are taking * - * This class represents an expression of a dynamic-size block. It is the return - * type of MatrixBase::dynBlock() and most of the time this is the only way it + * This class represents an expression of a fixed-size block. It is the return + * type of MatrixBase::fixedBlock() 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 fixed-size 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: - * \include class_DynBlock.cpp - * Output: \verbinclude class_DynBlock.out + * \include class_FixedBlock.cpp + * Output: \verbinclude class_FixedBlock.out * - * \sa MatrixBase::dynBlock() + * \sa MatrixBase::fixedBlock(), class Block */ -template class DynBlock - : public MatrixBase > +template class FixedBlock + : public MatrixBase > { public: typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::Ref MatRef; - friend class MatrixBase >; + friend class MatrixBase >; - DynBlock(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) + FixedBlock(const MatRef& matrix, int startRow, int startCol) + : m_matrix(matrix), m_startRow(startRow), m_startCol(startCol) { - assert(startRow >= 0 && blockRows >= 1 && startRow + blockRows <= matrix.rows() - && startCol >= 0 && blockCols >= 1 && startCol + blockCols <= matrix.cols()); + assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= matrix.rows() + && startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= matrix.cols()); } - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(DynBlock) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(FixedBlock) 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 = BlockRows, + ColsAtCompileTime = BlockCols, + MaxRowsAtCompileTime = BlockRows, + MaxColsAtCompileTime = BlockCols }; - const DynBlock& _ref() const { return *this; } - int _rows() const { return m_blockRows; } - int _cols() const { return m_blockCols; } + const FixedBlock& _ref() const { return *this; } + int _rows() const { return BlockRows; } + int _cols() const { return BlockCols; } Scalar& _coeffRef(int row, int col) { @@ -90,35 +90,37 @@ template class DynBlock protected: MatRef m_matrix; - const int m_startRow, m_startCol, m_blockRows, m_blockCols; + const int m_startRow, m_startCol; }; -/** \returns a dynamic-size expression of a block in *this. +/** \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 - * \param blockRows the number of rows in the block - * \param blockCols the number of columns in the block * - * Example: \include MatrixBase_dynBlock.cpp - * Output: \verbinclude MatrixBase_dynBlock.out + * Example: \include MatrixBase_block.cpp + * Output: \verbinclude MatrixBase_block.out * - * \sa class DynBlock, block() + * \sa class FixedBlock, block() */ template -DynBlock MatrixBase - ::dynBlock(int startRow, int startCol, int blockRows, int blockCols) +template +FixedBlock MatrixBase + ::fixedBlock(int startRow, int startCol) { - return DynBlock(ref(), startRow, startCol, blockRows, blockCols); + return FixedBlock(ref(), startRow, startCol); } -/** This is the const version of dynBlock(). */ +/** This is the const version of fixedBlock(). */ template -const DynBlock MatrixBase - ::dynBlock(int startRow, int startCol, int blockRows, int blockCols) const +template +const FixedBlock MatrixBase + ::fixedBlock(int startRow, int startCol) const { - return DynBlock(ref(), startRow, startCol, blockRows, blockCols); + return FixedBlock(ref(), startRow, startCol); } - -#endif // EIGEN_DYNBLOCK_H +#endif // EIGEN_FIXEDBLOCK_H diff --git a/Eigen/src/Core/ForwardDeclarations.h b/Eigen/src/Core/ForwardDeclarations.h index 07c6e3f69..5f969667c 100644 --- a/Eigen/src/Core/ForwardDeclarations.h +++ b/Eigen/src/Core/ForwardDeclarations.h @@ -32,8 +32,8 @@ template class Cast; template class Row; template class Column; template class Minor; -template class DynBlock; -template class Block; +template class Block; +template class FixedBlock; template class Transpose; template class Conjugate; template class Opposite; diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 6dd9d00b0..dc0292f97 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -184,14 +184,14 @@ template class MatrixBase Minor minor(int row, int col); const Minor minor(int row, int col) const; - DynBlock dynBlock(int startRow, int startCol, int blockRows, int blockCols); - const DynBlock - dynBlock(int startRow, int startCol, int blockRows, int blockCols) const; + Block block(int startRow, int startCol, int blockRows, int blockCols); + const Block + block(int startRow, int startCol, int blockRows, int blockCols) const; template - Block block(int startRow, int startCol); + FixedBlock fixedBlock(int startRow, int startCol); template - const Block block(int startRow, int startCol) const; + const FixedBlock fixedBlock(int startRow, int startCol) const; Transpose transpose(); const Transpose transpose() const; diff --git a/Eigen/src/Core/Util.h b/Eigen/src/Core/Util.h index d8db03caf..935a3dea6 100644 --- a/Eigen/src/Core/Util.h +++ b/Eigen/src/Core/Util.h @@ -113,12 +113,11 @@ template class IntAtRunTimeIfDynamic template<> class IntAtRunTimeIfDynamic { int m_value; + IntAtRunTimeIfDynamic() {} public: explicit IntAtRunTimeIfDynamic(int value) : m_value(value) {} int value() const { return m_value; } void setValue(int value) { m_value = value; } - private: - IntAtRunTimeIfDynamic() {} }; #endif // EIGEN_UTIL_H diff --git a/doc/examples/class_Block.cpp b/doc/examples/class_Block.cpp index a6025231e..b34cf13ad 100644 --- a/doc/examples/class_Block.cpp +++ b/doc/examples/class_Block.cpp @@ -3,17 +3,17 @@ USING_PART_OF_NAMESPACE_EIGEN using namespace std; template -Eigen::Block +Eigen::FixedBlock topLeft2x2Corner(MatrixBase& m) { - return Eigen::Block(m.ref(), 0, 0); + return Eigen::FixedBlock(m.ref(), 0, 0); } template -const Eigen::Block +const Eigen::FixedBlock topLeft2x2Corner(const MatrixBase& m) { - return Eigen::Block(m.ref(), 0, 0); + return Eigen::FixedBlock(m.ref(), 0, 0); } int main(int, char**) diff --git a/doc/examples/class_DynBlock.cpp b/doc/examples/class_DynBlock.cpp index 589d1204e..6d48d235d 100644 --- a/doc/examples/class_DynBlock.cpp +++ b/doc/examples/class_DynBlock.cpp @@ -3,17 +3,17 @@ USING_PART_OF_NAMESPACE_EIGEN using namespace std; template -Eigen::DynBlock +Eigen::Block topLeftCorner(MatrixBase& m, int rows, int cols) { - return Eigen::DynBlock(m.ref(), 0, 0, rows, cols); + return Eigen::Block(m.ref(), 0, 0, rows, cols); } template -const Eigen::DynBlock +const Eigen::Block topLeftCorner(const MatrixBase& m, int rows, int cols) { - return Eigen::DynBlock(m.ref(), 0, 0, rows, cols); + return Eigen::Block(m.ref(), 0, 0, rows, cols); } int main(int, char**) diff --git a/doc/snippets/MatrixBase_block.cpp b/doc/snippets/MatrixBase_block.cpp index 6bdc1ab03..984fd7094 100644 --- a/doc/snippets/MatrixBase_block.cpp +++ b/doc/snippets/MatrixBase_block.cpp @@ -1,5 +1,5 @@ Matrix4d m = Vector4d(1,2,3,4).asDiagonal(); cout << "Here is the matrix m:" << endl << m << endl; -cout << "Here is m.block<2, 2>(2, 2):" << endl << m.block<2, 2>(2, 2) << endl; -m.block<2, 2>(2, 0) = m.block<2, 2>(2, 2); +cout << "Here is m.fixedBlock<2, 2>(2, 2):" << endl << m.fixedBlock<2, 2>(2, 2) << endl; +m.fixedBlock<2, 2>(2, 0) = m.fixedBlock<2, 2>(2, 2); cout << "Now the matrix m is:" << endl << m << endl; diff --git a/doc/snippets/MatrixBase_dynBlock.cpp b/doc/snippets/MatrixBase_dynBlock.cpp index c04db2140..12363d028 100644 --- a/doc/snippets/MatrixBase_dynBlock.cpp +++ b/doc/snippets/MatrixBase_dynBlock.cpp @@ -1,5 +1,5 @@ Matrix3d m = Vector3d(1,2,3).asDiagonal(); cout << "Here is the matrix m:" << endl << m << endl; -cout << "Here is m.dynBlock(1, 1, 2, 1):" << endl << m.dynBlock(1, 1, 2, 1) << endl; -m.dynBlock(1, 0, 2, 1) = m.dynBlock(1, 1, 2, 1); +cout << "Here is m.block(1, 1, 2, 1):" << endl << m.block(1, 1, 2, 1) << endl; +m.block(1, 0, 2, 1) = m.block(1, 1, 2, 1); cout << "Now the matrix m is:" << endl << m << endl; diff --git a/doc/snippets/MatrixBase_setIdentity.cpp b/doc/snippets/MatrixBase_setIdentity.cpp index 17a706ca2..b14fcdd27 100644 --- a/doc/snippets/MatrixBase_setIdentity.cpp +++ b/doc/snippets/MatrixBase_setIdentity.cpp @@ -1,3 +1,3 @@ Matrix4i m = Matrix4i::zero(); -m.block<3,3>(1,0).setIdentity(); +m.fixedBlock<3,3>(1,0).setIdentity(); cout << m << endl; diff --git a/doc/tutorial.cpp b/doc/tutorial.cpp index b0627083d..10406819f 100644 --- a/doc/tutorial.cpp +++ b/doc/tutorial.cpp @@ -18,13 +18,13 @@ int main(int, char **) // notice how we are mixing fixed-size and dynamic-size types. cout << "In the top-left block, we put the matrix m shown above." << endl; - m2.block<2,2>(0,0) = m; + m2.fixedBlock<2,2>(0,0) = m; cout << "In the bottom-left block, we put the matrix m*m, which is:" << endl << m*m << endl; - m2.block<2,2>(2,0) = m * m; + m2.fixedBlock<2,2>(2,0) = m * m; cout << "In the top-right block, we put the matrix m+m, which is:" << endl << m+m << endl; - m2.block<2,2>(0,2) = m + m; + m2.fixedBlock<2,2>(0,2) = m + m; cout << "In the bottom-right block, we put the matrix m-m, which is:" << endl << m-m << endl; - m2.block<2,2>(2,2) = m - m; + m2.fixedBlock<2,2>(2,2) = m - m; cout << "Now the 4x4 matrix m2 is:" << endl << m2 << endl; cout << "Row 0 of m2 is:" << endl << m2.row(0) << endl; diff --git a/test/submatrices.cpp b/test/submatrices.cpp index ee0e49642..aa189476e 100644 --- a/test/submatrices.cpp +++ b/test/submatrices.cpp @@ -30,7 +30,7 @@ namespace Eigen { template void submatrices(const MatrixType& m) { /* this test covers the following files: - Row.h Column.h Block.h DynBlock.h Minor.h DiagonalCoeffs.h + Row.h Column.h FixedBlock.h Block.h Minor.h DiagonalCoeffs.h */ typedef typename MatrixType::Scalar Scalar; @@ -66,22 +66,22 @@ template void submatrices(const MatrixType& m) m1.row(r1) += s1 * m1.row(r2); m1.col(c1) += s1 * m1.col(c2); - //check dynBlock() + //check block() Matrix b1(1,1); b1(0,0) = m1(r1,c1); - RowVectorType br1(m1.dynBlock(r1,0,1,cols)); - VectorType bc1(m1.dynBlock(0,c1,rows,1)); - VERIFY_IS_APPROX(b1, m1.dynBlock(r1,c1,1,1)); + RowVectorType br1(m1.block(r1,0,1,cols)); + VectorType bc1(m1.block(0,c1,rows,1)); + VERIFY_IS_APPROX(b1, m1.block(r1,c1,1,1)); VERIFY_IS_APPROX(m1.row(r1), br1); VERIFY_IS_APPROX(m1.col(c1), bc1); - //check operator(), both constant and non-constant, on dynBlock() - m1.dynBlock(r1,c1,r2-r1+1,c2-c1+1) = s1 * m2.dynBlock(0, 0, r2-r1+1,c2-c1+1); - m1.dynBlock(r1,c1,r2-r1+1,c2-c1+1)(r2-r1,c2-c1) = m2.dynBlock(0, 0, r2-r1+1,c2-c1+1)(0,0); + //check operator(), both constant and non-constant, on block() + m1.block(r1,c1,r2-r1+1,c2-c1+1) = s1 * m2.block(0, 0, r2-r1+1,c2-c1+1); + m1.block(r1,c1,r2-r1+1,c2-c1+1)(r2-r1,c2-c1) = m2.block(0, 0, r2-r1+1,c2-c1+1)(0,0); //check minor() if(rows > 1 && cols > 1) { Matrix mi = m1.minor(0,0).eval(); - VERIFY_IS_APPROX(mi, m1.dynBlock(1,1,rows-1,cols-1)); + VERIFY_IS_APPROX(mi, m1.block(1,1,rows-1,cols-1)); mi = m1.minor(r1,c1); VERIFY_IS_APPROX(mi.transpose(), m1.transpose().minor(c1,r1)); //check operator(), both constant and non-constant, on minor() @@ -104,18 +104,18 @@ void EigenTest::testSubmatrices() submatrices(MatrixXi(8, 12)); submatrices(MatrixXcd(20, 20)); - // test block() separately as it is a template method so doesn't support + // test fixedBlock() separately as it is a template method so doesn't support // being called as a member of a class that is itself a template parameter // (at least as of g++ 4.2) Matrix m = Matrix::random(); float s = random(); - // test block() as lvalue - m.block<2,5>(1,1) *= s; - // test operator() on block() both as constant and non-constant - m.block<2,5>(1,1)(0, 3) = m.block<2,5>(1,1)(1,2); - // check that block() and dynBlock() agree - MatrixXf b = m.block<3,2>(3,3); - VERIFY_IS_APPROX(b, m.dynBlock(3,3,3,2)); + // test fixedBlock() as lvalue + m.fixedBlock<2,5>(1,1) *= s; + // test operator() on fixedBlock() both as constant and non-constant + m.fixedBlock<2,5>(1,1)(0, 3) = m.fixedBlock<2,5>(1,1)(1,2); + // check that fixedBlock() and block() agree + MatrixXf b = m.fixedBlock<3,2>(3,3); + VERIFY_IS_APPROX(b, m.block(3,3,3,2)); } }