diff --git a/src/framework/util/matrix.h b/src/framework/util/matrix.h index 78532972..3e66e70c 100644 --- a/src/framework/util/matrix.h +++ b/src/framework/util/matrix.h @@ -33,6 +33,7 @@ class Matrix { public: Matrix() { setIdentity(); } + Matrix(int) {} // construct without initializing identity matrix Matrix(const Matrix& other) = default; template Matrix(const std::initializer_list& values) { *this = values; } @@ -65,7 +66,6 @@ public: bool operator!=(const Matrix& other) const; private: - Matrix(int) {} // construct without initializing identity matrix T m[N][M]; }; @@ -176,10 +176,10 @@ bool Matrix::operator!=(const Matrix& other) const template std::ostream& operator<<(std::ostream& out, const Matrix& mat) { - for(int i=0;i::operator==(const Matrix<3,3,float>& other) const m[2][2] == other.m[2][2]; } +template +Matrix operator*(const Matrix& a, const Matrix& b) +{ + static_assert(N==P, "N==P"); + Matrix c(1); + for(int i=1;i<=M;++i) { + for(int j=1;j<=Q;++j) { + T sum = 0; + for(int k=1;k<=N;++k) + sum += a(i,k) * b(k,j); + c(i,j) = sum; + } + } + return c; +} + +template +Matrix operator+(const Matrix& a, const Matrix& b) { Matrix c(a); c += b; return c; } + +template +Matrix operator-(const Matrix& a, const Matrix& b) { Matrix c(a); c -= b; return c; } + +template +Matrix operator*(const Matrix& a, float b) { Matrix c(a); c *= b; return c; } + +template +Matrix operator/(const Matrix& a, float b) { Matrix c = a; c /= b; return c; } + typedef Matrix<4,4> Matrix4x4; typedef Matrix<3,3> Matrix3x3; typedef Matrix<2,2> Matrix2x2;