1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
#include <cxxstd/iostream.h>
#include <flens/flens.cxx>

using namespace std;
using namespace flens;

int
main()
{
    GeMatrix<FullStorage<double> >   A(44);
    DenseVector<Array<double> >      b(4);
    DenseVector<Array<int> >         piv(4);

    A =  2,   3,  -1,   0,
        -6,  -5,   0,   2,
         2,  -5,   6,  -6,
         4,   6,   2,  -3;

    cout << "A = " << A << endl;

///
/// *A pripori* compute the triangular factorization $PLU = A$ using the
/// __FLENS-LAPACK__ function `lapack::trf`.
///
    lapack::trf(A, piv);

///
/// The right hand sides are only known a posteriori.  Furthermore we have
/// three different right hand sides for the same coefficient matrix $A$.
///
/// *A posteriori* call the triangular solvers to solve $Ax=b$ for different
/// right hand sides $b$.
///
    for (int i=0; i<3; ++i) {
        cout << "Right hand side b in problem set " << i << endl;
        fillRandom(b);
        cout << "b = " << b << endl;
///
///     Apply the permutation: $b \leftarrow Pb$ using the __FLENS-LAPACK__
///     function `lapack::laswp`.
///
        lapack::laswp(b, piv);

///
///     Solve $L y = b$ using __FLENS-BLAS__ function `blas::sv`.  Vector $b$
///     will be overwritten with $y$.
///
        blas::sv(NoTrans, A.lowerUnit(), b);

///
///     Solve $U x = b$ using __FLENS-BLAS__ function `blas::sv`.  Vector $b$
///     will be overwritten with $x$.
///
        blas::sv(NoTrans, A.upper(), b);

        cout << "x = " << b << endl;
    }
}

///
///     :links: FLENS-LAPACK -> doc:flens/lapack/lapack
///             FLENS-BLAS   -> doc:flens/blas/blas
///