diff --git a/matrix/Matrix.hpp b/matrix/Matrix.hpp index 524ecee33a..a910d4fb04 100644 --- a/matrix/Matrix.hpp +++ b/matrix/Matrix.hpp @@ -238,13 +238,21 @@ public: void operator+=(const Matrix &other) { Matrix &self = *this; - self = self + other; + for (size_t i = 0; i < M; i++) { + for (size_t j = 0; j < N; j++) { + self(i, j) += other(i, j); + } + } } void operator-=(const Matrix &other) { Matrix &self = *this; - self = self - other; + for (size_t i = 0; i < M; i++) { + for (size_t j = 0; j < N; j++) { + self(i, j) -= other(i, j); + } + } } template @@ -302,7 +310,7 @@ public: for (size_t i = 0; i < M; i++) { for (size_t j = 0; j < N; j++) { - self(i, j) = self(i, j) * scalar; + self(i, j) *= scalar; } } } @@ -310,17 +318,23 @@ public: void operator/=(Type scalar) { Matrix &self = *this; - self = self * (Type(1) / scalar); + self *= (Type(1) / scalar); } inline void operator+=(Type scalar) { - *this = (*this) + scalar; + Matrix &self = *this; + for (size_t i = 0; i < M; i++) { + for (size_t j = 0; j < N; j++) { + self(i, j) += scalar; + } + } } inline void operator-=(Type scalar) { - *this = (*this) - scalar; + Matrix &self = *this; + self += (-scalar); } bool operator==(const Matrix &other) const