From df36096f72d3275d17a8ccabec166da0bf6b8ade Mon Sep 17 00:00:00 2001 From: Krad Date: Fri, 21 Apr 2023 15:32:09 +0800 Subject: [PATCH] Fix matrix operator bug on - and /.2 --- src/Matrix.cpp | 8 ++++---- src/Matrix.h | 8 ++++---- test/FunctionTester.cpp | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Matrix.cpp b/src/Matrix.cpp index a2fe4d4..ecf0133 100644 --- a/src/Matrix.cpp +++ b/src/Matrix.cpp @@ -350,7 +350,7 @@ namespace Aurora { Matrix Matrix::operator+(Matrix &&aMatrix) const { return operatorMxM_RR(&vdAddI,&vzAddI,*this,std::forward(aMatrix)); } - Matrix operator+(Matrix &&aMatrix, const Matrix &aOther) { + Matrix operator+(Matrix &&aMatrix, Matrix &aOther) { return operatorMxM_RR(&vdAddI,&vzAddI,aOther,std::forward(aMatrix),true); } @@ -367,7 +367,7 @@ namespace Aurora { Matrix Matrix::operator-(Matrix &&aMatrix) const { return operatorMxM_RR(&vdSubI,&vzSubI,*this,std::forward(aMatrix)); } - Matrix operator-(Matrix &&aMatrix, const Matrix &aOther) { + Matrix operator-(Matrix &&aMatrix, Matrix &aOther) { return operatorMxM_RR(&vdSubI,&vzSubI,aOther,std::forward(aMatrix),true); } @@ -384,7 +384,7 @@ namespace Aurora { Matrix Matrix::operator*(Matrix &&aMatrix) const { return operatorMxM_RR(&vdMulI,&vzMulI,*this,std::forward(aMatrix)); } - Matrix operator*(Matrix &&aMatrix, const Matrix &aOther) { + Matrix operator*(Matrix &&aMatrix, Matrix &aOther) { return operatorMxM_RR(&vdMulI,&vzMulI,aOther,std::forward(aMatrix),true); } @@ -401,7 +401,7 @@ namespace Aurora { Matrix Matrix::operator/(Matrix &&aMatrix) const { return operatorMxM_RR(&vdDivI,&vzDivI,*this,std::forward(aMatrix)); } - Matrix operator/(Matrix &&aMatrix, const Matrix &aOther) { + Matrix operator/(Matrix &&aMatrix, Matrix &aOther) { return operatorMxM_RR(&vdDivI,&vzDivI,aOther,std::forward(aMatrix),true); } diff --git a/src/Matrix.h b/src/Matrix.h index d62e31e..f620d82 100644 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -111,7 +111,7 @@ namespace Aurora { friend Matrix& operator+(Matrix &&matrix,double aScalar); Matrix operator+(const Matrix &matrix) const; Matrix operator+(Matrix &&matrix) const; - friend Matrix operator+(Matrix &&aMatrix,const Matrix &aOther); + friend Matrix operator+(Matrix &&aMatrix,Matrix &aOther); // sub Matrix operator-(double aScalar) const; @@ -120,7 +120,7 @@ namespace Aurora { friend Matrix& operator-(Matrix &&matrix,double aScalar); Matrix operator-(const Matrix &matrix) const; Matrix operator-(Matrix &&matrix) const; - friend Matrix operator-(Matrix &&aMatrix,const Matrix &aOther); + friend Matrix operator-(Matrix &&aMatrix,Matrix &aOther); // mul Matrix operator*(double aScalar) const; @@ -129,7 +129,7 @@ namespace Aurora { friend Matrix& operator*(Matrix &&matrix,double aScalar); Matrix operator*(const Matrix &matrix) const; Matrix operator*(Matrix &&matrix) const; - friend Matrix operator*(Matrix &&aMatrix,const Matrix &aOther); + friend Matrix operator*(Matrix &&aMatrix,Matrix &aOther); // div Matrix operator/(double aScalar) const; @@ -138,7 +138,7 @@ namespace Aurora { friend Matrix& operator/(Matrix &&matrix,double aScalar); Matrix operator/(const Matrix &matrix) const; Matrix operator/(Matrix &&matrix) const; - friend Matrix operator/(Matrix &&aMatrix,const Matrix &aOther); + friend Matrix operator/(Matrix &&aMatrix, Matrix &aOther); // pow Matrix operator^(int times) const; diff --git a/test/FunctionTester.cpp b/test/FunctionTester.cpp index faf10f9..aa65dca 100644 --- a/test/FunctionTester.cpp +++ b/test/FunctionTester.cpp @@ -188,8 +188,8 @@ TEST_F(FunctionTester, matrixOpertaor) { EXPECT_EQ(C.getData()[2],2); C = A*B/2.0; EXPECT_EQ(C.getData()[2],2); - C = A*B*B/2.0; - EXPECT_EQ(C.getData()[2],4); + C = (A*8.0/B) * (B+1.0)-2.0+8; + EXPECT_EQ(C.getData()[2],30); } }