use from Ernesto Palacios
Dependents: RoboticArm DXL_SDK_Porting_Test
Fork of Matrix by
Diff: Operators.cpp
- Revision:
- 7:7a564cf28ab6
- Parent:
- 5:a4014ab0a8cf
- Child:
- 8:1774aa06ab99
diff -r 3f01dc2d77f1 -r 7a564cf28ab6 Operators.cpp --- a/Operators.cpp Thu Feb 02 04:28:35 2017 +0000 +++ b/Operators.cpp Thu Feb 02 04:29:41 2017 +0000 @@ -1,15 +1,16 @@ -/** - * @brief Source Code for the Operator of Matrix Class. - * @file Operators.cpp - * @author Ernesto Palacios - * - * Created on September 2011. - * - * Develop Under GPL v3.0 License - * http://www.gnu.org/licenses/gpl-3.0.html - * - */ + + //* @brief Source Code for the Operator of Matrix Class. + //* @file Operators.cpp + //* @author Ernesto Palacios + //* + //* Created on September 2011. + //* + //* Develop Under GPL v3.0 License + //* http://www.gnu.org/licenses/gpl-3.0.html + //* + //*/ #include "mbed.h" + #include "Matrix.h" /// Subindex in Matrix left side @@ -20,7 +21,11 @@ if( row >= _nRows || col >= _nCols) { printf("\n\nError:\nOut of limits @ Matrix::operator()\n"); - }else{ + + return _matrix[0][0];//暫時這樣stanley + } + else + { return _matrix[row][col]; } } @@ -33,6 +38,7 @@ if( row >= _nRows || col >= _nCols) { printf("\n\nError:\nOut of limits @ Matrix::operator()\n"); + return _matrix[0][0];//暫時這樣stanley }else{ return _matrix[row][col]; } @@ -110,7 +116,12 @@ return leftM; - }else{ printf( "\n\nERROR:\nDiferent Dimensions @ += operator\n" ); } + }else{ + printf( "\n\nERROR:\nDiferent Dimensions @ += operator\n" ); + return leftM;//暫時這樣stanley + + + } } @@ -128,10 +139,31 @@ }else{ printf( "\n\nERROR:\nDiferent Dimensions @ -= operator\n" ); + + return leftM;//暫時這樣stanley + } } +//Original +//Matrix& operator *=( Matrix& leftM, const Matrix& rightM ) +//{ +// if( leftM._nCols == rightM._nRows ) +// { +// Matrix resultM ( leftM._nRows, rightM._nCols ); +// +// for( int i = 0; i < resultM._nRows; i++ ) +// for( int j = 0; j < resultM._nCols; j++ ) +// for( int m = 0; m < rightM._nRows; m++ ) +// resultM._matrix[i][j] += leftM._matrix[i][m] * rightM._matrix[m][j]; +// +// return resultM; +// }else{ +// printf( "\n\nERROR:\nDiferent Dimensions @ *= operator\n" ); +// } +//} +//stanley Matrix& operator *=( Matrix& leftM, const Matrix& rightM ) { if( leftM._nCols == rightM._nRows ) @@ -143,13 +175,18 @@ for( int m = 0; m < rightM._nRows; m++ ) resultM._matrix[i][j] += leftM._matrix[i][m] * rightM._matrix[m][j]; - return resultM; + leftM=resultM;//stanley + + // return resultM;//org + return leftM;//stanley }else{ printf( "\n\nERROR:\nDiferent Dimensions @ *= operator\n" ); + + return leftM;//暫時這樣stanley + } } - Matrix& operator *=( Matrix& leftM, float number ) { for( int i = 0; i < leftM._nRows; i++ ) @@ -197,6 +234,9 @@ }else{ printf( "\n\nERROR\nDiferent Dimensions @ + operator \n" ); + + Matrix NULL_M( 1, 1 );//暫時這樣stanley + return NULL_M; //Matrix error(4); //error.Clear(); //return error; @@ -236,7 +276,9 @@ }else{ printf( "\n\nERROR:\nDiferent Dimensions @ + operator \n" ); - + + Matrix NULL_M( 1, 1 );//暫時這樣stanley + return NULL_M; } } @@ -276,6 +318,9 @@ } else { printf("\n\nERROR:\nDiferent Dimension matrices @ * operator"); + + Matrix NULL_M( 1, 1 );//暫時這樣stanley + return NULL_M; } } @@ -317,4 +362,4 @@ return leftM; } -} +} \ No newline at end of file