diff --git a/main.cpp b/main.cpp index 3846d27..8a8e128 100644 --- a/main.cpp +++ b/main.cpp @@ -2,11 +2,12 @@ int main() { Matrix a(3, 3); - Matrix b(3, 1); // Let's multiply by a vector - Matrix result = a * &b; + a.Print("A"); - result.Print("A x B"); // Result is a 3 by 1 vector + a = a.Add(0.5F); + + a.Print("A + 0.5F"); return 0; } \ No newline at end of file diff --git a/matrices.h b/matrices.h index 9c57e72..4311640 100644 --- a/matrices.h +++ b/matrices.h @@ -16,7 +16,7 @@ class Matrix{ inline Matrix Swap(const Matrix*); - inline void Multiply(float); // TODO : Make this return a Matrix + inline Matrix Multiply(float); inline Matrix Multiply(const Matrix*); inline void Hadamard(const Matrix*); @@ -180,12 +180,14 @@ Matrix Matrix::Substract(float value){ } // Multiply every matrix case by a given factor -void Matrix::Multiply(float value){ - for(int m = 0; m < this->values.size(); m++){ - for(int n = 0; n < this->values[m].size(); n++){ - this->values[m][n] *= value; +Matrix Matrix::Multiply(float value){ + Matrix result = this; + for(int m = 0; m < result.values.size(); m++){ + for(int n = 0; n < result.values[m].size(); n++){ + result.values[m][n] *= value; } } + return result; } // Set a matrix to a given value