diff --git a/matrices.h b/matrices.h index 47f01fd..ffbce67 100644 --- a/matrices.h +++ b/matrices.h @@ -16,6 +16,8 @@ class Matrix{ void Multiply(float); Matrix Multiply(Matrix*); + void Hadamard(Matrix*); + void Add(float); void Add(Matrix*); @@ -46,8 +48,23 @@ Matrix::Matrix(Matrix* other){ this->values = other->values; } +void Matrix::Hadamard(Matrix* other){ + // Matrices need to be the same size + assertm(this->values.size() == other->values.size() && + this->values[0].size() == other->values[0].size(), + "Matrices need to be the same size"); + for(int m = 0; m < this->values.size(); m++){ + for(int n = 0; n < this->values[m].size(); n++){ + this->values[m][n] *= other->values[m][n]; + } + } +} + // Multiply 2 matrices (AxB = this x other) Matrix Matrix::Multiply(Matrix* other){ + // Matrices need to be of right size + assertm(this->values[0].size() == other->values.size(),"Wrong matrix size"); + // Resulting size is this->M x other->N Matrix result(this->values.size(), other->values[0].size()); for(int m = 0; m < result.values.size(); m++){ @@ -68,7 +85,7 @@ void Matrix::Add(Matrix* other){ // Matrices need to be the same size assertm(this->values.size() == other->values.size() && this->values[0].size() == other->values[0].size(), - "Matrices need to be the same size"); + "Wrong matrix size"); for(int m = 0; m < this->values.size(); m++){ for(int n = 0; n < this->values[m].size(); n++){ this->values[m][n] += other->values[m][n]; @@ -81,7 +98,7 @@ void Matrix::Substract(Matrix* other){ // Matrices need to be the same size assertm(this->values.size() == other->values.size() && this->values[0].size() == other->values[0].size(), - "Matrices need to be the same size"); + "Wrong matrix size"); for(int m = 0; m < this->values.size(); m++){ for(int n = 0; n < this->values[m].size(); n++){ this->values[m][n] -= other->values[m][n];