mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-02-17 18:09:55 +08:00
rename Block to DynBlock and rework API to make place for
upcoming fixed-size Block matrix. Also some cleanup.
This commit is contained in:
parent
346c00f4c8
commit
04502cccd9
@ -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;
|
||||
|
@ -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"
|
||||
|
@ -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
|
@ -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(); }
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
19
test/main.h
19
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
|
||||
|
Loading…
Reference in New Issue
Block a user