mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
* various fixes related to sub diagonals and band matrix
* allows 0 sized objects in Block/Map
This commit is contained in:
@@ -24,15 +24,20 @@
|
||||
|
||||
#include "main.h"
|
||||
|
||||
template<typename MatrixType> void bandmatrix(MatrixType& m)
|
||||
template<typename MatrixType> void bandmatrix(const MatrixType& _m)
|
||||
{
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrixType;
|
||||
|
||||
int size = m.rows();
|
||||
int rows = _m.rows();
|
||||
int cols = _m.cols();
|
||||
int supers = _m.supers();
|
||||
int subs = _m.subs();
|
||||
|
||||
DenseMatrixType dm1(size,size);
|
||||
MatrixType m(rows,cols,supers,subs);
|
||||
|
||||
DenseMatrixType dm1(rows,cols);
|
||||
dm1.setZero();
|
||||
|
||||
m.diagonal().setConstant(123);
|
||||
@@ -47,15 +52,33 @@ template<typename MatrixType> void bandmatrix(MatrixType& m)
|
||||
m.diagonal(-i).setConstant(-i);
|
||||
dm1.diagonal(-i).setConstant(-i);
|
||||
}
|
||||
std::cerr << m.toDense() << "\n\n" << dm1 << "\n\n";
|
||||
//std::cerr << m.m_data << "\n\n" << m.toDense() << "\n\n" << dm1 << "\n\n\n\n";
|
||||
VERIFY_IS_APPROX(dm1,m.toDense());
|
||||
|
||||
for (int i=0; i<cols; ++i)
|
||||
{
|
||||
m.col(i).setConstant(i+1);
|
||||
dm1.col(i).setConstant(i+1);
|
||||
}
|
||||
int d = std::min(rows,cols);
|
||||
int a = std::max(0,cols-d-supers);
|
||||
int b = std::max(0,rows-d-subs);
|
||||
if(a>0) dm1.block(0,d+supers,rows,a).setZero();
|
||||
dm1.block(0,supers+1,cols-supers-1-a,cols-supers-1-a).template triangularView<UpperTriangular>().setZero();
|
||||
dm1.block(subs+1,0,rows-subs-1-b,rows-subs-1-b).template triangularView<LowerTriangular>().setZero();
|
||||
if(b>0) dm1.block(d+subs,0,b,cols).setZero();
|
||||
//std::cerr << m.m_data << "\n\n" << m.toDense() << "\n\n" << dm1 << "\n\n";
|
||||
VERIFY_IS_APPROX(dm1,m.toDense());
|
||||
|
||||
}
|
||||
|
||||
void test_bandmatrix()
|
||||
{
|
||||
for(int i = 0; i < g_repeat ; i++) {
|
||||
BandMatrix<float,Dynamic,Dynamic,Dynamic> m(6,6,3,2);
|
||||
CALL_SUBTEST( bandmatrix(m) );
|
||||
for(int i = 0; i < 10*g_repeat ; i++) {
|
||||
int rows = ei_random<int>(1,10);
|
||||
int cols = ei_random<int>(1,10);
|
||||
int sups = ei_random<int>(0,cols-1);
|
||||
int subs = ei_random<int>(0,rows-1);
|
||||
CALL_SUBTEST( bandmatrix(BandMatrix<float>(rows,cols,sups,subs)) );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user