Skip to content

Conversation

@fredroy
Copy link
Contributor

@fredroy fredroy commented Jan 30, 2026

While adding some unit tests, I noticed that isDiagonal was wrong 😑
The problem occurs when i=0 (first row). The loop condition is while j<i-1 but when i=0 it will become j<std::max<sofa::Size> because i and j are unsigned.
The fix is also testing if the matrix is rectangular but not sure if we want that 🤔 (like for determinant?)

[with-all-tests]


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@fredroy fredroy added pr: fix Fix a bug pr: status to review To notify reviewers to review this pull-request pr: test PR adding test(s) in SOFA labels Jan 30, 2026
@alxbilger
Copy link
Contributor

Wikipedia says:

The term diagonal matrix may sometimes refer to a rectangular diagonal matrix, which is an m-by-n matrix with all the entries not of the form di,i being zero. For example:

$$ \begin{bmatrix} 1&0&0\\ 0&4&0\\ 0&0&-3\\ 0&0&0\\ \end{bmatrix} \quad \text{or}\quad \begin{bmatrix} 1&0&0&0&0\\ 0&4&0&0&0\\ 0&0&-3&0&0 \end{bmatrix} $$

for (Size j=i+1; j<C; j++)
for (Size j=0; j<C; ++j)
{
if (j == i && i < minDim) continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that && i < minDim is required because once one of the two indices is higher than the minDim, they can never be equal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: fix Fix a bug pr: status to review To notify reviewers to review this pull-request pr: test PR adding test(s) in SOFA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants