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

U is a triangular matrix referencing the upper triangular part.

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

SU is a symmetric matrix. The upper triangular part of SU is referencing U (which in turn references the upper part of A).

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

SL is a symmetric matrix. The lower triangular part of SL is referencing the lower part of A).

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

L is a unit triangular matrix referencing the lower part of A. The term “unit” denotes that elements on the diagonal are assumed to be one.

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

Compile and Run

$shell> cd flens/examples                                                         
$shell> g++ -Wall -std=c++11 -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             2             3             4 
            2             6             7             8 
            3             7             7             6 
            4             8             6            20 
SL = 
            1             5             9             5 
            5             6             8             4 
            9             8             7             3 
            5             4             3            20 
L = 
            1             0             0             0 
            5             1             0             0 
            9             8             1             0 
            5             4             3             1