Adding a float now returns a Matrix

This commit is contained in:
Leto 2024-12-27 23:34:27 +01:00
parent a3db9391d3
commit a4dabb247d
2 changed files with 11 additions and 8 deletions

View File

@ -2,11 +2,12 @@
int main() { int main() {
Matrix a(3, 3); 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; return 0;
} }

View File

@ -16,7 +16,7 @@ class Matrix{
inline Matrix Swap(const 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 Matrix Multiply(const Matrix*);
inline void Hadamard(const Matrix*); inline void Hadamard(const Matrix*);
@ -180,12 +180,14 @@ Matrix Matrix::Substract(float value){
} }
// Multiply every matrix case by a given factor // Multiply every matrix case by a given factor
void Matrix::Multiply(float value){ Matrix Matrix::Multiply(float value){
for(int m = 0; m < this->values.size(); m++){ Matrix result = this;
for(int n = 0; n < this->values[m].size(); n++){ for(int m = 0; m < result.values.size(); m++){
this->values[m][n] *= value; for(int n = 0; n < result.values[m].size(); n++){
result.values[m][n] *= value;
} }
} }
return result;
} }
// Set a matrix to a given value // Set a matrix to a given value