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
#include <flens/flens.cxx>
#include <iostream>

using namespace flens;
using namespace std;

///
/// This function receives a general matrix and `MA` can be of type
/// `FullStorage`, `FullStorageView` or `ConstFullStorageView`. Note that the
/// function receives the matrix as a const reference.
template <typename MA>
void
dummy(const GeMatrix<MA> &A)
{

///
/// We setup a range operator for this matrix type ...
///
    typedef typename GeMatrix<MA>::IndexType  IndexType;
    const Underscore<IndexType>  _;

///
/// ... and get some numbers we will use to split the matrix vertically.
///
    const IndexType n = A.numCols();
    const IndexType k = n/2;

///
/// As `A` is in this function in const context the created matrix views will
/// always be of type `GeMatrix<ConstFullStorageView<..> >`. And this is also
/// the type represented by `auto`. So `A1` and `A2` will be of type
/// `const GeMatrix<ConstFullStorageView<..> >`.
///
    const auto A1 = A(_,_(1,k));
    const auto A2 = A(_,_(k+1,n));

    cout << "A1 = " << A1 << endl;
    cout << "A2 = " << A2 << endl;
}

///
/// In the `main` function we again start with a typedef for a `GeMatrix` with
/// elements of type `double` that are stored column-wise in memory. Also, we
/// define a suitable range operator.
///
int
main()
{
    typedef FullStorage<double, ColMajor>  FS;
    typedef GeMatrix<FS>                   GeMatrix;
    const Underscore<GeMatrix::IndexType>  _;

///
/// Then we setup some matrix.
///
    GeMatrix  A(3,4);
    A = 1,  2,  3,  4,
        5,  6,  7,  8,
        9, 10, 11, 12;

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

///
/// Now we call dummy with different view types.
///
/// Call it with matrix of type `GeMatrix<FullStorage<..> >`
///
    dummy(A);

///
/// Call it with matrix of type `GeMatrix<FullStorageView<..> >`
///
    dummy(A(_(1,3),_));

///
/// Call it again with matrix of type `GeMatrix<FullStorageView<..> >`
///
    auto B = A(_(1,3),_);
    dummy(B);

///
/// Call it with matrix of type `GeMatrix<ConstFullStorageView<..> >`. Here
/// `C` is of type `const GeMatrix<FullStorageView>`, i.e. a (non-const) matrix
/// view in const context.
///
    const auto C = A(_(1,3),_);
    dummy(C(_,_(1,4)));
}