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
#include <complex>
#include <iostream>

#include <flens/flens.cxx>

using namespace flens;
using namespace std;

int
main()
{
///
/// Some typedefs for real and complex valued matrices.
///
   typedef GeMatrix<FullStorage<complex<double> > >    ComplexGeMatrix;
   typedef GeMatrix<FullStorage<double> >              RealGeMatrix;

    const int m = 5;
    const int n = 4;
    ComplexGeMatrix  Z(m,n);

///
/// See the next page for details on `IndexVariable` and `Complex`.
///
    ComplexGeMatrix::IndexVariable  i,j;
    Z(i,j) = Complex(i+j,j-i);

///
/// You can initialize a real valued matrix through the constructor.
///
    RealGeMatrix X = real(Z);

///
///  Or through an assignment.
///
    RealGeMatrix  Y;
    Y = imag(Z);

    cout << "Z = " << Z << endl;
    cout << "real(Z) = " << X << endl;
    cout << "imag(Z) = " << Y << endl;

///
/// You also can overwrite the real- or imaginary-part of a complex matrix with
/// a real valued matrix.  In this case we swap the real- and imaginary parts
/// of $Z$.  This is possible as $X$ and $Y$ contain copies.
///
    real(Z) = Y;
    imag(Z) = X;

    cout << "Z = " << Z << endl;
}