Content

First Steps

The term general matrix refers to a matrix that is not necessarily square or symmetric. Further, full storage denotes that all \(mn\) elements of a \(m \times n\) matrix get stored.

For dense vectors FLENS defines the

In a first example we allocate and initialize a general matrix and play around with it.

Example Code

#include <flens/flens.cxx>
#include <iostream>

using namespace flens;
using namespace std;

int
main()
{
    typedef GeMatrix<FullStorage<double, ColMajor> >  GEMatrix;

    GEMatrix A(4,4);
    A = 123,  4,
        567,  8,
        987,  6,
        54320;

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

    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;

    A(3,2) = 42;

    cout << "changed element: A(3,2) = " << A(3,2) << endl;

    cout << endl;

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

    A = 42;

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

    return 0;
}

Comments on Example Code

We simply include everything of FLENS

#include <flens/flens.cxx>
#include <iostream>

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 = 123,  4,
        567,  8,
        987,  6,
        54320;

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;

You also can fill the whole matrix with a new value:

    A = 42;

Compile and Run

$shell> cd flens/examples                                                       
$shell> g++ -Wall -std=c++11 -I../.. tut01-page01-example.cc                    
$shell> ./a.out                                                                 
A = 
            1             2             3             4 
            5             6             7             8 
            9             8             7             6 
            5             4             3            20 
Dim. of A: 4 x 4
Row indices: 1..4
Col indices: 1..4
changed element: A(3,2) = 42
A = 
            1             2             3             4 
            5             6             7             8 
            9            42             7             6 
            5             4             3            20 
A = 
           42            42            42            42 
           42            42            42            42 
           42            42            42            42 
           42            42            42            42