aboutsummaryrefslogtreecommitdiffstats
path: root/_test/meowpp_Matrix.cpp
diff options
context:
space:
mode:
Diffstat (limited to '_test/meowpp_Matrix.cpp')
-rw-r--r--_test/meowpp_Matrix.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/_test/meowpp_Matrix.cpp b/_test/meowpp_Matrix.cpp
new file mode 100644
index 0000000..dbcfcb1
--- /dev/null
+++ b/_test/meowpp_Matrix.cpp
@@ -0,0 +1,45 @@
+#include "meowpp/math/Matrix.h"
+
+#include "meowpp.h"
+
+#include <cmath>
+#include <cstdlib>
+
+using namespace meow;
+
+
+
+void print(Matrix<int> const& m){
+ for(size_t r = 0; r < m.rows(); r++){
+ printf("[");
+ for(size_t c = 0; c < m.cols(); c++){
+ printf("%8d", m(r, c));
+ }
+ printf("]\n");
+ }
+}
+
+TEST(Matrix){
+ Matrix<int> a(3, 4, 0);
+ Matrix<int> b(3, 4, 0);
+ Matrix<int> c(4, 5, 0);
+ for(int i = 0; i < 3; i++){
+ for(int j = 0; j < 4; j++){
+ a.entry(i, j, rand() % 100);
+ b.entry(i, j, rand() % 100);
+ }
+ }
+ for(int i = 0; i < 4; i++){
+ for(int j = 0; j < 5; j++){
+ c.entry(i, j, rand() % 100);
+ }
+ }
+ printf("A = \n"); print(a);
+ printf("B = \n"); print(b);
+ printf("C = \n"); print(b);
+ printf("A + B = \n"); print(a + b);
+ printf("A * C = \n"); print(a * c);
+ printf("A * B^T = \n"); print(a * b.transpose());
+
+ return true;
+};