#include <flens/flens.cxx>
#include <iostream> #ifdef WITH_OPERATORS # include <flens/examples/lu/lu_blk_with_operators.h> #else # include <flens/examples/lu/lu_blk_with_flensblas.h> #endif #include <flens/examples/lu/apply_perm.h> using namespace flens; using namespace std; int main() { const int m = 4000; const int n = 4000; GeMatrix<FullStorage<double, RowMajor> > A(m,n), A_org; DenseVector<Array<int> > p(m); Underscore<int> _; fillRandom(A); // store original A for checking the factorization later A_org = A; /// Uncomment for playing with small dimensions: //cout << "A = " << A << endl; if (lu_blk(A, p) != 0) { cout << "Matrix is singular or close to singular" << endl; return 1; } # ifdef CHECK /// and //cout << "L = " << A.lowerUnit() << endl; //cout << "U = " << A.upper() << endl; //cout << "p = " << p << endl; GeMatrix<FullStorage<double> > LU(m,n); // blas::copy(NoTrans, A.upper(), LU.upper()); LU.upper() = A.upper(); // blas::mm(Left, NoTrans, 1.0, A(_(1,4),_(1,4)).lowerUnit(), LU); LU = A(_(1,m),_(1,m)).lowerUnit() * LU; // LU = P*LU apply_perm(p, LU); //cout << "P*L*U = " << LU << endl; // blas::axpy(NoTrans, -1.0, LU, A_org); A_org -= LU; //cout << "A - P*L*U = " << A_org << endl; cout << "|| A-P*L*U ||_1 = " << blas::asum(A_org) << endl; return 0; # endif } |