From 61e7d329c6bafaf269a619ffb2bb80a24b1fb210 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Tue, 13 Jun 2017 17:43:39 +0100 Subject: Working on matrix functions --- include/YAGE/Math/matrix.hpp | 97 +++++++++++++++++++++++++++++--------------- test/matrix_test.cpp | 7 +++- 2 files changed, 70 insertions(+), 34 deletions(-) diff --git a/include/YAGE/Math/matrix.hpp b/include/YAGE/Math/matrix.hpp index 3b18be0b..5a9e80f2 100644 --- a/include/YAGE/Math/matrix.hpp +++ b/include/YAGE/Math/matrix.hpp @@ -4,12 +4,15 @@ #include #include #include +#include +#include #include namespace yage { template class Matrix; +template class Vector; namespace detail { @@ -47,21 +50,69 @@ protected: public: Matrix() : data_(Rows*Cols) {} - int rowSize() + int rowSize() const { return Rows; } - int colSize() + int colSize() const { return Cols; } + Matrix<1, Cols, Type> getRow(int row) const + { + Matrix<1, Cols, Type> rowMatrix; + for(int i=0; i getCol(int col) const + { + Matrix colMatrix; + for(int i=0; i operator[](int row) { return detail::Row(this, row); } + detail::Row operator[](int row) const + { + // TODO got to fix this + return detail::Row((Matrix*)this, row); + } + Matrix& operator=(const Matrix &other) { if(this!=&other) @@ -111,25 +162,7 @@ public: friend std::ostream& operator<<(std::ostream &os, const Matrix &mat) { - os<<'['; - for(std::size_t i=0; i class Vector : public Matrix() : Matrix() {} - explicit Vector(const Matrix &other) - { - this->data_=other.data_; - } + explicit Vector(const Matrix &other) : Matrix(other) {} Type& operator[](int col) { @@ -188,12 +218,15 @@ namespace matrix template Matrix transpose(const Matrix &m) { - static_assert(M!=1, "Called wrong transpose"); -} - -template Vector transpose(const Matrix<1, N, T> &m) -{ - + Matrix trans; + for(int i=0; i T dot(const Vector &v1, const Vector &v2) @@ -223,7 +256,7 @@ Matrix multiply(const Matrix &m1, const Matrix &m2) return res; } -} // vector +} // matrix } // yage diff --git a/test/matrix_test.cpp b/test/matrix_test.cpp index a6974c7f..bf85ab35 100644 --- a/test/matrix_test.cpp +++ b/test/matrix_test.cpp @@ -9,7 +9,7 @@ int main() yage::Vector<2, int> v1, v2; yage::Vector2d v3; - + m1[0][1]=1; m2[1][1]=2; @@ -23,10 +23,13 @@ int main() v3.x() = 2; v3.y() = 1; - yage::matrix::multiply(m1, m2); + auto m3=yage::matrix::transpose(v3); + auto vec4=yage::Vector<2, double>(yage::matrix::transpose(m3)); std::cout<