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
     64
     65
     66
     67
///
///  We simply include everything of FLENS
///
#include <flens/flens.cxx>
#include <iostream>

using namespace flens;
using namespace std;

int
main()
{
    ///
    ///  Typedef for a general matrix with elements of type `double`.
    ///  Internally elements are stored in *column major* order.
    ///
    typedef GeMatrix<FullStorage<double, ColMajor> >  GEMatrix;

    ///
    ///  Matrix A gets dynamically allocated and then initialized.
    ///
    GEMatrix A(4,4);
    A = 1, 2, 3,  4,
        5, 6, 7,  8,
        9, 8, 7,  6,
        5, 4, 3, 20;

    ///
    ///  Print the matrix content using output streams:
    ///
    cout << "A = " << A << endl;

    ///
    ///  We print some information about matrix dimensions and index ranges.
    ///  You will see that by default in FLENS indices start at 1 (like in
    ///  Fortran):
    ///
    cout << "Dim. of A: " << A.numRows() << " x " << A.numCols() << endl;
    cout << endl;
    cout << "Row indices: " << A.firstRow() << ".." << A.lastRow() << endl;
    cout << endl;
    cout << "Col indices: " << A.firstCol() << ".." << A.lastCol() << endl;
    cout << endl;

    ///
    /// Also for element access (write) we provide a Fortran-Style interface:
    ///
    A(3,2) = 42;

    ///
    /// The same for read access:
    ///
    cout << "changed element: A(3,2) = " << A(3,2) << endl;

    cout << endl;

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

    ///
    /// You also can fill the whole matrix with a new value:
    ///
    A = 42;

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

    return 0;
}