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
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
#include <cxxstd/iostream.h>
#include <flens/flens.cxx>

using namespace flens;
using namespace std;

int
main()
{
    typedef GeMatrix<FullStorage<double> >  DGeMatrix;
    typedef DenseVector<Array<double> >     DDenseVector;

    Underscore<DDenseVector::IndexType>     _;

    ///
    ///  Allocate and initialize some vector ...
    ///
    DDenseVector x(5);
    x = 12345;

    ///
    ///  ... and matrix.
    ///
    DGeMatrix A(45);
    A = 1112131415,
        2122232425,
        3132333435,
        4142434445;

    ///
    ///  Print the vector and matrix
    ///
    cout << "x = " << x << endl;
    cout << "A = " << A << endl;
    cout << endl;

    ///
    ///  Create a vector view that references every second element of `x`.
    ///
    DDenseVector::View  y = x(_(1,2,5));

    cout << "y = x(1:2:5) = " << y << endl;
    cout << endl;


    ///
    ///  Create a vector view that references the second row of `A`
    ///
    DDenseVector::View row = A(2,_);

    cout << "row = A(2,:) = " << row << endl;
    cout << endl;

    ///
    ///  Create a vector view that references part of second row of `A`
    ///
    DDenseVector::View rowPart = A(2,_(2,4));

    cout << "rowPart = A(2,2:4) = " << rowPart << endl;
    cout << endl;


    ///
    ///  Create a vector view that references the third column of `A`
    ///
    DDenseVector::View col = A(_,3);

    cout << "col = A(:,3) = " << col << endl;
    cout << endl;

    ///
    ///  Create a vector view that references the diagonal of `A`
    ///
    DDenseVector::View d0 = A.diag(0);

    cout << "d0 = A.diag(0) = " << d0 << endl;
    cout << endl;

    ///
    ///  Create a vector view that references the first sub-diagonal of `A`
    ///
    DDenseVector::View d_1 = A.diag(-1);

    cout << "d_1 = A.diag(-1) = " << d_1 << endl;
    cout << endl;

    ///
    ///  Create a vector view that references the first super-diagonal of `A`
    ///
    DDenseVector::View d1 = A.diag(1);

    cout << "d1 = A.diag(1) = " << d1 << endl;
    cout << endl;


    return 0;
}