1 #include <flens/flens.cxx>
 2 #include <iostream>
 3 
 4 using namespace flens;
 5 using namespace std;
 6 
 7 int
 8 main()
 9 {
10 
11 ///
12 /// The storage scheme for `DenseVector` is `Array`, `ArrayView` or
13 /// `ConstArrayView`.  We setup a typedef for a "regular" dense vector that
14 /// allocates its own memory.
15 ///
16     typedef DenseVector<Array<double> >   DenseVector;
17     typedef DenseVector::IndexType        IndexType;
18 
19 ///
20 /// We define a dense vector of length `4` and initialize it.
21 ///
22     DenseVector x(4);
23     x = 1234;
24 
25 ///
26 /// We retrieve some information like index range and vector length.  You
27 /// will see that the default index base is One.
28 ///
29     cout << "x.range() = " << x.range() << endl;
30     cout << "x.length() = " << x.length() << endl;
31 
32 ///
33 /// We print the vector.
34 ///
35     cout << "x = " << x << endl;
36 
37 ///
38 /// We iterate through the vector and reset its elements (such that $x_i =
39 /// i^2$).
40 ///
41     for (IndexType i=x.firstIndex(); i<=x.lastIndex(); ++i) {
42         x(i) = i*i;
43     }
44 
45 ///
46 /// For selecting vector parts we define a range operator
47 ///
48     const Underscore<IndexType> _;
49 
50 ///
51 /// We create a vector view `y` that references a part of `x`.
52 ///
53     DenseVector::View y = x(_(2,4));
54     y = 666;
55 
56 ///
57 /// Here we create a new vector `z` that allocates its own memory and
58 /// initializes it with a copy of a part of `x`.  So `z` is no vector view.
59 ///
60     DenseVector::NoView z = x(_(1,2));
61     z = 42;
62 
63     cout << "x = " << x << endl;
64     cout << "y = " << y << endl;
65     cout << "z = " << z << endl;
66 }