]> git.tdb.fi Git - libs/math.git/blobdiff - source/linal/matrix.h
Add formatted output operators for vector and matrix classes
[libs/math.git] / source / linal / matrix.h
index daf9cb898e04393f2fc2d0f4d75b52d69bca4b94..2711d40a637489c1bfa3cc9676c2fb8043f978d4 100644 (file)
@@ -2,6 +2,7 @@
 #define MSP_LINAL_MATRIX_H_
 
 #include <algorithm>
+#include <ostream>
 #include "vector.h"
 
 namespace Msp {
@@ -260,6 +261,27 @@ inline Matrix<T, N, M> transpose(const Matrix<T, M, N> &m)
        return r;
 }
 
+template<typename T, unsigned M, unsigned N>
+inline std::ostream &operator<<(std::ostream &s, const Matrix<T, M, N> &m)
+{
+       s << "Matrix" << M << 'x' << N << '(';
+       for(unsigned i=0; i<N; ++i)
+       {
+               if(i)
+                       s << ", ";
+               s << '[';
+               for(unsigned j=0; j<M; ++j)
+               {
+                       if(j)
+                               s << ", ";
+                       s << m(j, i);
+               }
+               s << ']';
+       }
+       s << ')';
+       return s;
+}
+
 } // namespace LinAl
 } // namespace Msp