diff options
-rw-r--r-- | doc/tutorial.cpp | 8 | ||||
-rw-r--r-- | src/Core.h | 2 | ||||
-rw-r--r-- | src/Core/DynBlock.h (renamed from src/Core/Block.h) | 45 | ||||
-rw-r--r-- | src/Core/MatrixBase.h | 7 | ||||
-rw-r--r-- | src/Core/Util.h | 2 | ||||
-rw-r--r-- | test/adjoint.cpp | 4 | ||||
-rw-r--r-- | test/basicstuff.cpp | 4 | ||||
-rw-r--r-- | test/main.h | 19 |
8 files changed, 48 insertions, 43 deletions
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 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<typename MatrixType> class Block - : public MatrixBase<typename MatrixType::Scalar, Block<MatrixType> > +template<typename MatrixType> class DynBlock + : public MatrixBase<typename MatrixType::Scalar, DynBlock<MatrixType> > { public: typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::Ref MatRef; - friend class MatrixBase<Scalar, Block<MatrixType> >; + friend class MatrixBase<Scalar, DynBlock<MatrixType> >; 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<typename MatrixType> 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<typename Scalar, typename Derived> -Block<Derived> -MatrixBase<Scalar, Derived>::block(int startRow, int endRow, int startCol, int endCol) const +DynBlock<Derived> MatrixBase<Scalar, Derived> + ::dynBlock(int startRow, int startCol, int blockRows, int blockCols) const { - return Block<Derived>(static_cast<Derived*>(const_cast<MatrixBase*>(this))->ref(), - startRow, endRow, startCol, endCol); + return DynBlock<Derived>(static_cast<Derived*>(const_cast<MatrixBase*>(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<typename Scalar, typename Derived> class MatrixBase Row<Derived> row(int i) const; Column<Derived> col(int i) const; Minor<Derived> minor(int row, int col) const; - Block<Derived> block(int startRow, int endRow, int startCol, int endCol) const; + + DynBlock<Derived> dynBlock(int startRow, int startCol, + int blockRows, int blockCols) const; + //template<int BlockRows, int BlockCols> Block<Derived, BlockRows, BlockCols> + //block(int startRow, int startCol) const; + Transpose<Derived> transpose() const; Conjugate<Derived> conjugate() const; Transpose<Conjugate<Derived> > 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<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> class DynBlock; template<typename MatrixType> class Transpose; template<typename MatrixType> class Conjugate; template<typename MatrixType> 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<float, 1, 1>()); - 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<float, 1, 1>()); - 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<typename T> inline typename NumTraits<T>::Real test_precision(); template<> inline int test_precision<int>() { return 0; } -template<> inline float test_precision<float>() { return 1e-2; } +template<> inline float test_precision<float>() { return 1e-2f; } template<> inline double test_precision<double>() { return 1e-5; } template<> inline float test_precision<std::complex<float> >() { return test_precision<float>(); } template<> inline double test_precision<std::complex<double> >() { return test_precision<double>(); } @@ -96,15 +104,6 @@ inline bool test_isMuchSmallerThan(const MatrixBase<Scalar, Derived>& m, return m.isMuchSmallerThan(s, test_precision<Scalar>()); } - -#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 |