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

using namespace flens;
using namespace std;

int
main()
{
    typedef complex<double>        Complex;
    DenseVector<Array<Complex> >   z(5);

    z = Complex(1,2), Complex(3,4), Complex(5,6), Complex(7,8), Complex(9,10);

    Underscore<int> _;

///
/// $x$ and $y$ are of type `DenseVector<ArrayView<double> >` but `auto` is
/// shorter.
///
    auto x = real(z);
    auto y = imag(z);

    cout << "z = " << z << endl;
    cout << "real(z) = " << x << endl;
    cout << "imag(z) = " << y << endl;

///
/// Let's modify the real and imaginary parts of $z$ through the vector views.
/// Note, $x$ and $y$ are of type `DenseVector`.  So you just can use them as
/// any other `DenseVector`.
///
    x = 2, 9, 4, 7, 6;
    y(_(1,2,5)) = 666, -666, 666;

///
/// Now we check that $z$ actually was modified:
///
    cout << "z = " << z << endl;

///
/// As $x$ and $y$ are dense vectors you can apply any BLAS function
///
    blas::swap(x,y);
    cout << "z = " << z << endl;
}