renaming:

Block -> FixedBlock
DynBlock -> Block
indeed, previous commit solves the main issue with DynBlock so
is should now be the more commonly used one.
This commit is contained in:
Benoit Jacob 2008-01-13 20:19:14 +00:00
parent 89a134ba0b
commit 95dc68dc86
13 changed files with 123 additions and 124 deletions

View File

@ -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"

View File

@ -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<typename MatrixType, int BlockRows, int BlockCols> class Block
: public MatrixBase<typename MatrixType::Scalar,
Block<MatrixType, BlockRows, BlockCols> >
template<typename MatrixType> class Block
: public MatrixBase<typename MatrixType::Scalar, Block<MatrixType> >
{
public:
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, Block<MatrixType, BlockRows, BlockCols> >;
friend class MatrixBase<Scalar, Block<MatrixType> >;
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<typename MatrixType, int BlockRows, int BlockCols> 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<typename Scalar, typename Derived>
template<int BlockRows, int BlockCols>
Block<Derived, BlockRows, BlockCols> MatrixBase<Scalar, Derived>
::block(int startRow, int startCol)
Block<Derived> MatrixBase<Scalar, Derived>
::block(int startRow, int startCol, int blockRows, int blockCols)
{
return Block<Derived, BlockRows, BlockCols>(ref(), startRow, startCol);
return Block<Derived>(ref(), startRow, startCol, blockRows, blockCols);
}
/** This is the const version of block(). */
template<typename Scalar, typename Derived>
template<int BlockRows, int BlockCols>
const Block<Derived, BlockRows, BlockCols> MatrixBase<Scalar, Derived>
::block(int startRow, int startCol) const
const Block<Derived> MatrixBase<Scalar, Derived>
::block(int startRow, int startCol, int blockRows, int blockCols) const
{
return Block<Derived, BlockRows, BlockCols>(ref(), startRow, startCol);
return Block<Derived>(ref(), startRow, startCol, blockRows, blockCols);
}
#endif // EIGEN_BLOCK_H

View File

@ -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<typename MatrixType> class DynBlock
: public MatrixBase<typename MatrixType::Scalar, DynBlock<MatrixType> >
template<typename MatrixType, int BlockRows, int BlockCols> class FixedBlock
: public MatrixBase<typename MatrixType::Scalar,
FixedBlock<MatrixType, BlockRows, BlockCols> >
{
public:
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, DynBlock<MatrixType> >;
friend class MatrixBase<Scalar, FixedBlock<MatrixType, BlockRows, BlockCols> >;
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<typename MatrixType> 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<typename Scalar, typename Derived>
DynBlock<Derived> MatrixBase<Scalar, Derived>
::dynBlock(int startRow, int startCol, int blockRows, int blockCols)
template<int BlockRows, int BlockCols>
FixedBlock<Derived, BlockRows, BlockCols> MatrixBase<Scalar, Derived>
::fixedBlock(int startRow, int startCol)
{
return DynBlock<Derived>(ref(), startRow, startCol, blockRows, blockCols);
return FixedBlock<Derived, BlockRows, BlockCols>(ref(), startRow, startCol);
}
/** This is the const version of dynBlock(). */
/** This is the const version of fixedBlock(). */
template<typename Scalar, typename Derived>
const DynBlock<Derived> MatrixBase<Scalar, Derived>
::dynBlock(int startRow, int startCol, int blockRows, int blockCols) const
template<int BlockRows, int BlockCols>
const FixedBlock<Derived, BlockRows, BlockCols> MatrixBase<Scalar, Derived>
::fixedBlock(int startRow, int startCol) const
{
return DynBlock<Derived>(ref(), startRow, startCol, blockRows, blockCols);
return FixedBlock<Derived, BlockRows, BlockCols>(ref(), startRow, startCol);
}
#endif // EIGEN_DYNBLOCK_H
#endif // EIGEN_FIXEDBLOCK_H

View File

@ -32,8 +32,8 @@ 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 DynBlock;
template<typename MatrixType, int BlockRows, int BlockCols> class Block;
template<typename MatrixType> class Block;
template<typename MatrixType, int BlockRows, int BlockCols> class FixedBlock;
template<typename MatrixType> class Transpose;
template<typename MatrixType> class Conjugate;
template<typename MatrixType> class Opposite;

View File

@ -184,14 +184,14 @@ template<typename Scalar, typename Derived> class MatrixBase
Minor<Derived> minor(int row, int col);
const Minor<Derived> minor(int row, int col) const;
DynBlock<Derived> dynBlock(int startRow, int startCol, int blockRows, int blockCols);
const DynBlock<Derived>
dynBlock(int startRow, int startCol, int blockRows, int blockCols) const;
Block<Derived> block(int startRow, int startCol, int blockRows, int blockCols);
const Block<Derived>
block(int startRow, int startCol, int blockRows, int blockCols) const;
template<int BlockRows, int BlockCols>
Block<Derived, BlockRows, BlockCols> block(int startRow, int startCol);
FixedBlock<Derived, BlockRows, BlockCols> fixedBlock(int startRow, int startCol);
template<int BlockRows, int BlockCols>
const Block<Derived, BlockRows, BlockCols> block(int startRow, int startCol) const;
const FixedBlock<Derived, BlockRows, BlockCols> fixedBlock(int startRow, int startCol) const;
Transpose<Derived> transpose();
const Transpose<Derived> transpose() const;

View File

@ -113,12 +113,11 @@ template<int Value> class IntAtRunTimeIfDynamic
template<> class IntAtRunTimeIfDynamic<Dynamic>
{
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

View File

@ -3,17 +3,17 @@ USING_PART_OF_NAMESPACE_EIGEN
using namespace std;
template<typename Scalar, typename Derived>
Eigen::Block<Derived, 2, 2>
Eigen::FixedBlock<Derived, 2, 2>
topLeft2x2Corner(MatrixBase<Scalar, Derived>& m)
{
return Eigen::Block<Derived, 2, 2>(m.ref(), 0, 0);
return Eigen::FixedBlock<Derived, 2, 2>(m.ref(), 0, 0);
}
template<typename Scalar, typename Derived>
const Eigen::Block<Derived, 2, 2>
const Eigen::FixedBlock<Derived, 2, 2>
topLeft2x2Corner(const MatrixBase<Scalar, Derived>& m)
{
return Eigen::Block<Derived, 2, 2>(m.ref(), 0, 0);
return Eigen::FixedBlock<Derived, 2, 2>(m.ref(), 0, 0);
}
int main(int, char**)

View File

@ -3,17 +3,17 @@ USING_PART_OF_NAMESPACE_EIGEN
using namespace std;
template<typename Scalar, typename Derived>
Eigen::DynBlock<Derived>
Eigen::Block<Derived>
topLeftCorner(MatrixBase<Scalar, Derived>& m, int rows, int cols)
{
return Eigen::DynBlock<Derived>(m.ref(), 0, 0, rows, cols);
return Eigen::Block<Derived>(m.ref(), 0, 0, rows, cols);
}
template<typename Scalar, typename Derived>
const Eigen::DynBlock<Derived>
const Eigen::Block<Derived>
topLeftCorner(const MatrixBase<Scalar, Derived>& m, int rows, int cols)
{
return Eigen::DynBlock<Derived>(m.ref(), 0, 0, rows, cols);
return Eigen::Block<Derived>(m.ref(), 0, 0, rows, cols);
}
int main(int, char**)

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -30,7 +30,7 @@ namespace Eigen {
template<typename MatrixType> 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<typename MatrixType> void submatrices(const MatrixType& m)
m1.row(r1) += s1 * m1.row(r2);
m1.col(c1) += s1 * m1.col(c2);
//check dynBlock()
//check block()
Matrix<Scalar,Dynamic,Dynamic> 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<Scalar, Dynamic, Dynamic> 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<float, 6, 8> m = Matrix<float, 6, 8>::random();
float s = random<float>();
// 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));
}
}