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

using namespace flens;
using namespace std;

///
/// 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 GeMatrix<FullStorage<double, ColMajor> >      DGeMatrix;
    typedef GeMatrix<FullStorageView<double, ColMajor> >  DGeMatrixView;

///
/// We define an underscore operator for selecting index ranges.  The template
/// class `Underscore` requires the index type of `DGeMatrix` as template
/// parameter.
///
    const Underscore<DGeMatrix::IndexType>  _;

///
/// Then we setup some matrix.
///
    DGeMatrix  A(3,4);
    A = 1,  2,  3,  4,
        5,  6,  7,  8,
        9101112;

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

///
/// Create a view `B` that references from `A` the second and third row.
///
    DGeMatrixView B = A(_(2,3),_);

    cout << "B = " << B << endl;

///
/// We change an element of `B`.  So we also change `A`.
///
    B(1,2) = 42;

    cout << "Changed B(1,2)." << std::endl;
    cout << "A = " << A << endl;


///
/// Create a copy `C` of `B`
///
    DGeMatrix C = B;

    cout << "C is a copy of B." << std::endl;
    cout << "C = " << C << endl;

///
/// We change an element of `C`.  So this neither will change `A` nor `B` as
/// `C` has its own memory.
///
    C(1,2) = 666;

    cout << "Changed C(1,2)." << std::endl;
    cout << "A = " << A << endl;
    cout << "B = " << B << endl;
    cout << "C = " << C << endl;
}