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
#include <flens/flens.cxx>
#include <iostream>

using namespace flens;
using namespace std;

int
main()
{
    GeMatrix<FullStorage<double> >   A(3,3);
    DenseVector<Array<int> >         piv(3);

///
/// Setup the toy example.
///
    A = 1, 2, 3,
        4, 5, 6,
        7, 8, 1;

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

///
/// Compute the $LU$ factoriation of $A$.
///
    int info = lapack::trf(A, piv);

///
/// If `info` is not zero then the matrix was singular.  More precise, the
/// upper triangular matrix $U$ computed by `trf` is exactly singular.
///
    if (info!=0) {
        cerr << "A is singular" << endl;
        return info;
    }

///
///  Compute $A^{-1}$ from the $LU$ factorization of $A$.
///
    lapack::tri(A, piv);
    cout << "inv(A) = " << A << endl;

    return 0;
}