It All Starts With a General Matrix

In this session we introduce matrix types

Like the GeMatrix type these matrix types use a full storage scheme for storing their elements. Often you start we a GeMatrix and then create triangular views or symmetric views. Such an task often arises in the implementation of numerical algorithms. For example, in FLENS-LAPACK this is a often used feature of FLENS.

Example Code

We setup some general matrix and then create triangular and symmetric matric views that reference the upper or lower part.

#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;

    auto U = A.upper();
    cout << "U = " << U << endl;

    auto SU = U.symmetric();
    cout << "SU = " << SU << endl;

    auto SL = A.lower().symmetric();
    cout << "SL = " << SL << endl;

    auto L = A.lowerUnit();
    cout << "L = " << L << endl;

    return 0;
}

Comments on Example Code

...

    auto U = A.upper();
    cout << "U = " << U << endl;

...

    auto SU = U.symmetric();
    cout << "SU = " << SU << endl;

...

    auto SL = A.lower().symmetric();
    cout << "SL = " << SL << endl;

...

    auto L = A.lowerUnit();
    cout << "L = " << L << endl;

Compile and Run

$shell> cd flens/examples                                                     
$shell> clang++ -Wall -std=c++0x -I../.. tut03-page01-example.cc              
$shell> ./a.out                                                               
A = 
                   1                    2                    3                    4 
                   5                    6                    7                    8 
                   9                    8                    7                    6 
                   5                    4                    3                   20 
U = 
                   1                    2                    3                    4 
                   0                    6                    7                    8 
                   0                    0                    7                    6 
                   0                    0                    0                   20 
SU = 
   1.000000    2.000000    3.000000    4.000000 
   2.000000    6.000000    7.000000    8.000000 
   3.000000    7.000000    7.000000    6.000000 
   4.000000    8.000000    6.000000   20.000000 
SL = 
   1.000000    5.000000    9.000000    5.000000 
   5.000000    6.000000    8.000000    4.000000 
   9.000000    8.000000    7.000000    3.000000 
   5.000000    4.000000    3.000000   20.000000 
L = 
            1.000000             0.000000             0.000000             0.000000 
            5.000000             1.000000             0.000000             0.000000 
            9.000000             8.000000             1.000000             0.000000 
            5.000000             4.000000             3.000000             1.000000