DiscussionsIssue archiveOther usage issues

Archived discussion

math_Matrix::Multiply() seems to be wrong

Other usage issuesTue, 04/22/2025 - 15:193 replies

Browse this forum
QuestionAuthor

Hi all,

it seems that method math_Matrix::Multiply(const math_Matrix& Right) is wrong. In the following code, when I = 0, J2 = 0, the code "Array(I, J2) = Som;" sets Array(0, 0) to Som, but then Array(0,0) is reused to compute the final elements in position Array(0,1), Array(0,2), ... Array(0,Right.UpperColIndex), that is it is reused to compute the other elements of the first row of Array. A similar issue appears to me to be in the computation of the remaining rows of Array(). Am I wrong?

void math_Matrix::Multiply(const math_Matrix& Right)
{
Standard_DimensionError_Raise_if(
ColNumber() != Right.RowNumber(),
"math_Matrix::Multiply() - input matrix has incompatible dimensions");

Standard_Real Som;
for (Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++)
{
for (Standard_Integer J2 = Right.LowerColIndex; J2 <= Right.UpperColIndex; J2++)
{
Som = 0.0;
Standard_Integer I2 = Right.LowerRowIndex;
for (Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++)
{
Som = Som + Array(I, J) * Right.Array(I2, J2);
I2++;
}
Array(I, J2) = Som;
}
}
}

Discussion

3 archived replies

Posts are displayed in their archived order.

01Commenter-1

Hello. The conditions indeed look not valid. The result of calculation is not accepted to use inside single iteration. I will create a PR and fix the issue.

Additionally, sometimes I'm thinking about Eigen, but it is not simple way according minimizing external 3rd-party in the kernel. But still can be in place for the next major releases.

Best regards, Commenter-1,

02Author

Hi Dmitrii,

thanks for your quick reply.

Best regards.
Author

03Commenter-1