diff --git a/doc/tutorial.cpp b/doc/tutorial.cpp index 4400bd2d1..5daf2f027 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(0,1,0,1) = m; + m2.block(0,0,2,2) = m; cout << "In the bottom-left block, we put the matrix m*m, which is:" << endl << m*m << endl; - m2.block(2,3,0,1) = m * m; + m2.block(2,0,2,2) = m * m; cout << "In the top-right block, we put the matrix m+m, which is:" << endl << m+m << endl; - m2.block(0,1,2,3) = m + m; + m2.block(0,2,2,2) = m + m; cout << "In the bottom-right block, we put the matrix m-m, which is:" << endl << m-m << endl; - m2.block(2,3,2,3) = m - m; + m2.block(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/src/Core.h b/src/Core.h index 820ab6573..c1fde09be 100644 --- a/src/Core.h +++ b/src/Core.h @@ -20,7 +20,7 @@ namespace Eigen { #include "Core/Opposite.h" #include "Core/Row.h" #include "Core/Column.h" -#include "Core/Block.h" +#include "Core/DynBlock.h" #include "Core/Minor.h" #include "Core/Transpose.h" #include "Core/Conjugate.h" diff --git a/src/Core/Block.h b/src/Core/DynBlock.h similarity index 59% rename from src/Core/Block.h rename to src/Core/DynBlock.h index 5432ff28d..05f67aefd 100644 --- a/src/Core/Block.h +++ b/src/Core/DynBlock.h @@ -26,37 +26,38 @@ #ifndef EIGEN_BLOCK_H #define EIGEN_BLOCK_H -template class Block - : public MatrixBase > +template class DynBlock + : public MatrixBase > { public: typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::Ref MatRef; - friend class MatrixBase >; + friend class MatrixBase >; static const int RowsAtCompileTime = Dynamic, ColsAtCompileTime = Dynamic; - Block(const MatRef& matrix, - int startRow, int endRow, - int startCol = 0, int endCol = 0) - : m_matrix(matrix), m_startRow(startRow), m_endRow(endRow), - m_startCol(startCol), m_endCol(endCol) + 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) { - assert(startRow >= 0 && startRow <= endRow && endRow < matrix.rows() - && startCol >= 0 && startCol <= endCol && endCol < matrix.cols()); + assert(startRow >= 0 && blockRows >= 1 && startRow + blockRows <= matrix.rows() + && startCol >= 0 && blockCols >= 1 && startCol + blockCols <= matrix.rows()); } - Block(const Block& other) - : m_matrix(other.m_matrix), m_startRow(other.m_startRow), m_endRow(other.m_endRow), - m_startCol(other.m_startCol), m_endCol(other.m_endCol) {} + DynBlock(const DynBlock& other) + : m_matrix(other.m_matrix), + m_startRow(other.m_startRow), m_startCol(other.m_startCol), + m_blockRows(other.m_blockRows), m_blockCols(other.m_blockCols) {} - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(DynBlock) private: - const Block& _ref() const { return *this; } - int _rows() const { return m_endRow - m_startRow + 1; } - int _cols() const { return m_endCol - m_startCol + 1; } + const DynBlock& _ref() const { return *this; } + int _rows() const { return m_blockRows; } + int _cols() const { return m_blockCols; } Scalar& _write(int row, int col=0) { @@ -70,15 +71,15 @@ template class Block protected: MatRef m_matrix; - const int m_startRow, m_endRow, m_startCol, m_endCol; + const int m_startRow, m_startCol, m_blockRows, m_blockCols; }; template -Block -MatrixBase::block(int startRow, int endRow, int startCol, int endCol) const +DynBlock MatrixBase + ::dynBlock(int startRow, int startCol, int blockRows, int blockCols) const { - return Block(static_cast(const_cast(this))->ref(), - startRow, endRow, startCol, endCol); + return DynBlock(static_cast(const_cast(this))->ref(), + startRow, startCol, blockRows, blockCols); } #endif // EIGEN_BLOCK_H diff --git a/src/Core/MatrixBase.h b/src/Core/MatrixBase.h index c4588dd88..c37967cbf 100644 --- a/src/Core/MatrixBase.h +++ b/src/Core/MatrixBase.h @@ -82,7 +82,12 @@ template class MatrixBase Row row(int i) const; Column col(int i) const; Minor minor(int row, int col) const; - Block block(int startRow, int endRow, int startCol, int endCol) const; + + DynBlock dynBlock(int startRow, int startCol, + int blockRows, int blockCols) const; + //template Block + //block(int startRow, int startCol) const; + Transpose transpose() const; Conjugate conjugate() const; Transpose > adjoint() const { return conjugate().transpose(); } diff --git a/src/Core/Util.h b/src/Core/Util.h index f9cab96da..615fd610e 100644 --- a/src/Core/Util.h +++ b/src/Core/Util.h @@ -47,7 +47,7 @@ template class Cast; template class Row; template class Column; template class Minor; -template class Block; +template class DynBlock; template class Transpose; template class Conjugate; template class Opposite; diff --git a/test/adjoint.cpp b/test/adjoint.cpp index a86225408..4b4b42f20 100644 --- a/test/adjoint.cpp +++ b/test/adjoint.cpp @@ -93,10 +93,10 @@ void EigenTest::testAdjoint() { REPEAT { adjoint(Matrix()); - adjoint(Matrix4cd()); + adjoint(Matrix4d()); adjoint(MatrixXcf(3, 3)); adjoint(MatrixXi(8, 12)); - adjoint(MatrixXd(20, 20)); + adjoint(MatrixXcd(20, 20)); } } diff --git a/test/basicstuff.cpp b/test/basicstuff.cpp index 03f555749..4fb4b991a 100644 --- a/test/basicstuff.cpp +++ b/test/basicstuff.cpp @@ -140,10 +140,10 @@ void EigenTest::testBasicStuff() { REPEAT { basicStuff(Matrix()); - basicStuff(Matrix4cd()); + basicStuff(Matrix4d()); basicStuff(MatrixXcf(3, 3)); basicStuff(MatrixXi(8, 12)); - basicStuff(MatrixXd(20, 20)); + basicStuff(MatrixXcd(20, 20)); } } diff --git a/test/main.h b/test/main.h index 00048d237..067b966f9 100644 --- a/test/main.h +++ b/test/main.h @@ -35,11 +35,19 @@ #define DEFAULT_REPEAT 50 #define REPEAT for(int repeat_iteration = 0; repeat_iteration < m_repeat; repeat_iteration++) +#define VERIFY(a) QVERIFY(a) +#define VERIFY_IS_APPROX(a, b) QVERIFY(test_isApprox(a, b)) +#define VERIFY_IS_NOT_APPROX(a, b) QVERIFY(!test_isApprox(a, b)) +#define VERIFY_IS_MUCH_SMALLER_THAN(a, b) QVERIFY(test_isMuchSmallerThan(a, b)) +#define VERIFY_IS_NOT_MUCH_SMALLER_THAN(a, b) QVERIFY(!test_isMuchSmallerThan(a, b)) +#define VERIFY_IS_APPROX_OR_LESS_THAN(a, b) QVERIFY(test_isApproxOrLessThan(a, b)) +#define VERIFY_IS_NOT_APPROX_OR_LESS_THAN(a, b) QVERIFY(!test_isApproxOrLessThan(a, b)) + namespace Eigen { template inline typename NumTraits::Real test_precision(); template<> inline int test_precision() { return 0; } -template<> inline float test_precision() { return 1e-2; } +template<> inline float test_precision() { return 1e-2f; } template<> inline double test_precision() { return 1e-5; } template<> inline float test_precision >() { return test_precision(); } template<> inline double test_precision >() { return test_precision(); } @@ -96,15 +104,6 @@ inline bool test_isMuchSmallerThan(const MatrixBase& m, return m.isMuchSmallerThan(s, test_precision()); } - -#define VERIFY(a) QVERIFY(a) -#define VERIFY_IS_APPROX(a, b) QVERIFY(test_isApprox(a, b)) -#define VERIFY_IS_NOT_APPROX(a, b) QVERIFY(!test_isApprox(a, b)) -#define VERIFY_IS_MUCH_SMALLER_THAN(a, b) QVERIFY(test_isMuchSmallerThan(a, b)) -#define VERIFY_IS_NOT_MUCH_SMALLER_THAN(a, b) QVERIFY(!test_isMuchSmallerThan(a, b)) -#define VERIFY_IS_APPROX_OR_LESS_THAN(a, b) QVERIFY(test_isApproxOrLessThan(a, b)) -#define VERIFY_IS_NOT_APPROX_OR_LESS_THAN(a, b) QVERIFY(!test_isApproxOrLessThan(a, b)) - class EigenTest : public QObject { Q_OBJECT