1 #include <flens/flens.cxx>
2 #include <iostream>
3
4 using namespace flens;
5 using namespace std;
6
7 ///
8 /// This function receives a general matrix and `MA` can be of type
9 /// `FullStorage`, `FullStorageView` or `ConstFullStorageView`. Note that the
10 /// function receives the matrix as a const reference.
11 template <typename MA>
12 void
13 dummy(const GeMatrix<MA> &A)
14 {
15
16 ///
17 /// We setup a range operator for this matrix type ...
18 ///
19 typedef typename GeMatrix<MA>::IndexType IndexType;
20 const Underscore<IndexType> _;
21
22 ///
23 /// ... and get some numbers we will use to split the matrix vertically.
24 ///
25 const IndexType n = A.numCols();
26 const IndexType k = n/2;
27
28 ///
29 /// As `A` is in this function in const context the created matrix views will
30 /// always be of type `GeMatrix<ConstFullStorageView<..> >`. And this is also
31 /// the type represented by `auto`. So `A1` and `A2` will be of type
32 /// `const GeMatrix<ConstFullStorageView<..> >`.
33 ///
34 const auto A1 = A(_,_(1,k));
35 const auto A2 = A(_,_(k+1,n));
36
37 cout << "A1 = " << A1 << endl;
38 cout << "A2 = " << A2 << endl;
39 }
40
41 ///
42 /// In the `main` function we again start with a typedef for a `GeMatrix` with
43 /// elements of type `double` that are stored column-wise in memory. Also, we
44 /// define a suitable range operator.
45 ///
46 int
47 main()
48 {
49 typedef FullStorage<double, ColMajor> FS;
50 typedef GeMatrix<FS> GeMatrix;
51 const Underscore<GeMatrix::IndexType> _;
52
53 ///
54 /// Then we setup some matrix.
55 ///
56 GeMatrix A(3,4);
57 A = 1, 2, 3, 4,
58 5, 6, 7, 8,
59 9, 10, 11, 12;
60
61 cout << "A = " << A << endl;
62
63 ///
64 /// Now we call dummy with different view types.
65 ///
66 /// Call it with matrix of type `GeMatrix<FullStorage<..> >`
67 ///
68 dummy(A);
69
70 ///
71 /// Call it with matrix of type `GeMatrix<FullStorageView<..> >`
72 ///
73 dummy(A(_(1,3),_));
74
75 ///
76 /// Call it again with matrix of type `GeMatrix<FullStorageView<..> >`
77 ///
78 auto B = A(_(1,3),_);
79 dummy(B);
80
81 ///
82 /// Call it with matrix of type `GeMatrix<ConstFullStorageView<..> >`. Here
83 /// `C` is of type `const GeMatrix<FullStorageView>`, i.e. a (non-const) matrix
84 /// view in const context.
85 ///
86 const auto C = A(_(1,3),_);
87 dummy(C(_,_(1,4)));
88 }
2 #include <iostream>
3
4 using namespace flens;
5 using namespace std;
6
7 ///
8 /// This function receives a general matrix and `MA` can be of type
9 /// `FullStorage`, `FullStorageView` or `ConstFullStorageView`. Note that the
10 /// function receives the matrix as a const reference.
11 template <typename MA>
12 void
13 dummy(const GeMatrix<MA> &A)
14 {
15
16 ///
17 /// We setup a range operator for this matrix type ...
18 ///
19 typedef typename GeMatrix<MA>::IndexType IndexType;
20 const Underscore<IndexType> _;
21
22 ///
23 /// ... and get some numbers we will use to split the matrix vertically.
24 ///
25 const IndexType n = A.numCols();
26 const IndexType k = n/2;
27
28 ///
29 /// As `A` is in this function in const context the created matrix views will
30 /// always be of type `GeMatrix<ConstFullStorageView<..> >`. And this is also
31 /// the type represented by `auto`. So `A1` and `A2` will be of type
32 /// `const GeMatrix<ConstFullStorageView<..> >`.
33 ///
34 const auto A1 = A(_,_(1,k));
35 const auto A2 = A(_,_(k+1,n));
36
37 cout << "A1 = " << A1 << endl;
38 cout << "A2 = " << A2 << endl;
39 }
40
41 ///
42 /// In the `main` function we again start with a typedef for a `GeMatrix` with
43 /// elements of type `double` that are stored column-wise in memory. Also, we
44 /// define a suitable range operator.
45 ///
46 int
47 main()
48 {
49 typedef FullStorage<double, ColMajor> FS;
50 typedef GeMatrix<FS> GeMatrix;
51 const Underscore<GeMatrix::IndexType> _;
52
53 ///
54 /// Then we setup some matrix.
55 ///
56 GeMatrix A(3,4);
57 A = 1, 2, 3, 4,
58 5, 6, 7, 8,
59 9, 10, 11, 12;
60
61 cout << "A = " << A << endl;
62
63 ///
64 /// Now we call dummy with different view types.
65 ///
66 /// Call it with matrix of type `GeMatrix<FullStorage<..> >`
67 ///
68 dummy(A);
69
70 ///
71 /// Call it with matrix of type `GeMatrix<FullStorageView<..> >`
72 ///
73 dummy(A(_(1,3),_));
74
75 ///
76 /// Call it again with matrix of type `GeMatrix<FullStorageView<..> >`
77 ///
78 auto B = A(_(1,3),_);
79 dummy(B);
80
81 ///
82 /// Call it with matrix of type `GeMatrix<ConstFullStorageView<..> >`. Here
83 /// `C` is of type `const GeMatrix<FullStorageView>`, i.e. a (non-const) matrix
84 /// view in const context.
85 ///
86 const auto C = A(_(1,3),_);
87 dummy(C(_,_(1,4)));
88 }