Skip to content

[Type] Mat: add unit tests and fix isDiagonal()#5909

Open
fredroy wants to merge 4 commits intosofa-framework:masterfrom
fredroy:mat_test_and_fix_isdiag
Open

[Type] Mat: add unit tests and fix isDiagonal()#5909
fredroy wants to merge 4 commits intosofa-framework:masterfrom
fredroy:mat_test_and_fix_isdiag

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} $$

@fredroy fredroy force-pushed the mat_test_and_fix_isdiag branch from fde6c00 to 8d1aab3 Compare February 4, 2026 23:32
@fredroy
Copy link
Contributor Author

fredroy commented Feb 4, 2026

[ci-build][with-all-tests]

@hugtalbot hugtalbot added pr: status ready Approved a pull-request, ready to be squashed and removed pr: status to review To notify reviewers to review this pull-request labels Feb 5, 2026
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 ready Approved a pull-request, ready to be squashed pr: test PR adding test(s) in SOFA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants