Matrix multiplication: Difference between revisions
Content added Content deleted
(Add C++ generic solution) |
mNo edit summary |
||
Line 485: | Line 485: | ||
#define MATRIX_ERR_MUL_ROW_AND_COL_NOT_EQUAL "3 The row number of second matrix must be equal with the column number of first matrix!" |
#define MATRIX_ERR_MUL_ROW_AND_COL_NOT_EQUAL "3 The row number of second matrix must be equal with the column number of first matrix!" |
||
#define MATRIX_ERR_MUL_ROW_AND_COL_BE_GREATER_THAN_ZERO "4 The number of rows and columns must be greater than zero!" |
#define MATRIX_ERR_MUL_ROW_AND_COL_BE_GREATER_THAN_ZERO "4 The number of rows and columns must be greater than zero!" |
||
#define |
#define MATRIX_ERR_TOO_FEW_DATA "5 Too few data in matrix." |
||
class MatrixException { |
class MatrixException { |
||
Line 615: | Line 615: | ||
throw MatrixException(MATRIX_ERR_WRONG_ROW_INDEX); |
throw MatrixException(MATRIX_ERR_WRONG_ROW_INDEX); |
||
} else if ((index + 1) * n > size()) { |
} else if ((index + 1) * n > size()) { |
||
throw MatrixException( |
throw MatrixException(MATRIX_ERR_TOO_FEW_DATA); |
||
} else { |
} else { |
||
unsigned int begin = index * n; |
unsigned int begin = index * n; |
||
Line 634: | Line 634: | ||
throw MatrixException(MATRIX_ERR_MUL_ROW_AND_COL_BE_GREATER_THAN_ZERO); |
throw MatrixException(MATRIX_ERR_MUL_ROW_AND_COL_BE_GREATER_THAN_ZERO); |
||
} else if (m * n > size() || other.m * other.n > other.size()) { |
} else if (m * n > size() || other.m * other.n > other.size()) { |
||
throw MatrixException( |
throw MatrixException(MATRIX_ERR_TOO_FEW_DATA); |
||
} else { |
} else { |
||
for (unsigned int i = 0; i < m; i++) { |
for (unsigned int i = 0; i < m; i++) { |