summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2019-10-10 01:18:49 +0200
committerNao Pross <naopross@thearcway.org>2019-10-10 01:19:17 +0200
commit241149ba6e85ad225d9c355e2033f0595e29a10d (patch)
tree6884a1c042e1434e403fd5efc3dad3e82048ba42 /test
parentNew matrix data model (breaks everything) (diff)
downloadlibmm-241149ba6e85ad225d9c355e2033f0595e29a10d.tar.gz
libmm-241149ba6e85ad225d9c355e2033f0595e29a10d.zip
Update access model for operator|
The operator | can access the matrix either by directly changing the values (by reference, mm::mutate(M)) or by creating first a a copy of the matrix (mm::clone(M)). ToDo: The order of destruction of the mutate object is not yet well defined, and therefore it is not yet deterministic enough to work with expressions like (pseudocode) matrix m = a * b * (a | mm::alg::invert) because operator| (defaults to mutate), should not but could, change the value of a before the product a * b gets evaluated.
Diffstat (limited to 'test')
-rw-r--r--test/matrix_example.cpp72
1 files changed, 50 insertions, 22 deletions
diff --git a/test/matrix_example.cpp b/test/matrix_example.cpp
index 96ba67d..af95a00 100644
--- a/test/matrix_example.cpp
+++ b/test/matrix_example.cpp
@@ -1,36 +1,64 @@
#include "mm/mmmatrix.hpp"
+#include "mm/view.hpp"
#include <iostream>
#include <complex>
-int main(int argc, char *argv[]) {
- std::cout << "MxN dimensional (int) matrices" << std::endl;
- mm::matrix<int, 3, 2> a {{1, 2}, {3, 4}, {5, 6}};
- mm::matrix<int, 3, 2> b {{4, 3}, {9, 1}, {2, 5}};
- mm::matrix<int, 2, 4> c {{1, 2, 3, 4}, {5, 6, 7, 8}};
- auto ct = c.t();
+// int main(int argc, char *argv[]) {
+int main() {
+ // std::cout << "MxN dimensional (int) matrices" << std::endl;
- std::cout << "a = \n" << a;
- std::cout << "b = \n" << b;
- std::cout << "c = \n" << c;
- std::cout << "c^t = \n" << ct;
- std::cout << std::endl;
+ mm::matrix<int, 2, 2> a { 1, 2, 3, 4 };
+
+ // mm::matrix<int, 3, 2> a {{1, 2}, {3, 4}, {5, 6}};
+ // mm::matrix<int, 3, 2> a {1, 2, 3, 4, 5, 6};
+
+ // mm::matrix<int, 3, 2> b {4, 3, 9, 1, 2, 5};
+ // mm::matrix<int, 2, 4> c {1, 2, 3, 4, 5, 6, 7, 8};
+
+ // std::cout << "a = \n" << a;
+ // std::cout << "b = \n" << b;
+ // std::cout << "c = \n" << c;
+ // std::cout << std::endl;
// access elements
- std::cout << "Access elements" << std::endl;
- std::cout << "a.at(2,0) = " << a.at(2, 0) << std::endl;
- std::cout << "a[2][0] = " << a[2][0] << std::endl;;
- std::cout << std::endl;
+ // std::cout << "Access elements" << std::endl;
+ // std::cout << "a.at(2,0) = " << a.at(2, 0) << std::endl;
+ // std::cout << "a[2][0] = " << a[2][0] << std::endl;;
+ // std::cout << std::endl;
// basic operations
- std::cout << "Basic operations" << std::endl;
- std::cout << "a + b = \n" << a + b;
- std::cout << "a - b = \n" << a - b;
- std::cout << "a * c = \n" << a * c;
- std::cout << "a * 2 = \n" << a * 2;
- std::cout << "2 * a = \n" << 2 * a;
- std::cout << "a.td() = \n" << a.t(); // or a.trasposed();
+ // std::cout << "Basic operations" << std::endl;
+ // std::cout << "a + b = \n" << a + b;
+ // std::cout << "a - b = \n" << a - b;
+ // std::cout << "a * c = \n" << a * c;
+ // std::cout << "a * 2 = \n" << a * 2;
+ // std::cout << "2 * a = \n" << 2 * a;
+ // std::cout << "a.td() = \n" << a.t(); // or a.trasposed();
+ // std::cout << std::endl;
+
+ std::cout << "a = \n" << a;
+
+ std::cout << "Cloning a" << std::endl;
+ decltype(a) e = mm::clone(a) | mm::alg::transpose();
+ std::cout << "e = \n" << e;
std::cout << std::endl;
+ std::cout << "Mutating a" << std::endl;
+ mm::mutate(a) | mm::alg::transpose();
+ std::cout << "a = \n" << a;
+ std::cout << std::endl;
+
+ a | mm::alg::tr();
+ std::cout << "a = \n" << a;
+
+ // std::cout << "Converting clone object" << std::endl;
+ // mm::matrix<int, 2, 2> g = e;
+ // std::cout << std::endl;
+
+ // std::cout << "Converting mutate object" << std::endl;
+ // mm::matrix<int, 2, 2> h = f;
+ // std::cout << std::endl;
+
return 0;
}