1
0
forked from leto/LeMA

= operator uses new Swap function and added + operator

This commit is contained in:
Leto 2024-12-24 14:14:04 +01:00
parent e0d6d480da
commit 7e35b218d9
2 changed files with 17 additions and 3 deletions

View File

@ -7,9 +7,13 @@ int main()
Matrix a(3,2); Matrix a(3,2);
a.Randomize(); a.Randomize();
Matrix b = a;
a.Print("A"); a.Print("A");
a.Transpose().Print("Transposed"); b.Print("B");
Matrix result = a + &b;
result.Print("A + B");
return 0; return 0;
} }

View File

@ -14,6 +14,8 @@ class Matrix{
inline void Set(float); inline void Set(float);
inline Matrix Swap(const Matrix*);
inline void Multiply(float); inline void Multiply(float);
inline Matrix Multiply(const Matrix*); inline Matrix Multiply(const Matrix*);
@ -40,8 +42,11 @@ class Matrix{
}; };
Matrix Matrix::operator=(const Matrix* other){ Matrix Matrix::operator=(const Matrix* other){
this->values = other->values; return this->Swap(other);
return *this; }
Matrix Matrix::operator+(const Matrix* other){
return this->Add(other);
} }
// Constructs a zero matrix // Constructs a zero matrix
@ -59,6 +64,11 @@ Matrix::Matrix(const Matrix* other){
this->values = other->values; this->values = other->values;
} }
Matrix Matrix::Swap(const Matrix* other){
this->values = other->values;
return *this;
}
void Matrix::Hadamard(const Matrix* other){ void Matrix::Hadamard(const Matrix* other){
// Matrices need to be the same size // Matrices need to be the same size
assertm(this->values.size() == other->values.size() && assertm(this->values.size() == other->values.size() &&