Skip to content

Add symmetric tridiagonal matrices module#1091

Merged
jvdp1 merged 25 commits intofortran-lang:masterfrom
Mahmood-Sinan:symtridiag
Apr 3, 2026
Merged

Add symmetric tridiagonal matrices module#1091
jvdp1 merged 25 commits intofortran-lang:masterfrom
Mahmood-Sinan:symtridiag

Conversation

@Mahmood-Sinan
Copy link
Copy Markdown
Contributor

@Mahmood-Sinan Mahmood-Sinan commented Jan 21, 2026

This draft PR adds support for symmetric tridiagonal matrices inside specialmatrices in stdlib.
It includes implementation, tests, documentation and examples.
The PR implements the same arithmetic and matrix operations as the existing tridiagonal module.

Remaining tasks:

Feedback is welcome.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 21, 2026

Codecov Report

❌ Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.00%. Comparing base (dae9d4b) to head (d6b8572).
⚠️ Report is 49 commits behind head on master.

Files with missing lines Patch % Lines
...pecialmatrices/example_sym_tridiagonal_dp_type.f90 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1091      +/-   ##
==========================================
- Coverage   68.04%   68.00%   -0.04%     
==========================================
  Files         404      405       +1     
  Lines       12948    12955       +7     
  Branches     1395     1395              
==========================================
  Hits         8810     8810              
- Misses       4138     4145       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@loiseaujc
Copy link
Copy Markdown
Contributor

It looks pretty nice. One little thing though (even if I overlooked it when implementing the tridiagonal_type ) : you could define a single pure subroutine to construct the symtridiagonal matrices (make it two if you include the constant diagonal cases) and then have it called by the pure and impure constructors. It's a little thing but that would reduce a bit code duplication I guess.

I'll go through the code a bit more thoroughly tomorrow but it looks pretty good to me already.

@Mahmood-Sinan
Copy link
Copy Markdown
Contributor Author

One little thing though (even if I overlooked it when implementing the tridiagonal_type ) : you could define a single pure subroutine to construct the symtridiagonal matrices (make it two if you include the constant diagonal cases) and then have it called by the pure and impure constructors. It's a little thing but that would reduce a bit code duplication I guess.

Thanks for the suggestion! You’re right, I implemented so. Now the tridiagonal and symtridiagonal construction is now handled by two pure helper routines(one from arrays and one from constants), which is called by both the pure and impure constructors.

Copy link
Copy Markdown
Contributor

@loiseaujc loiseaujc left a comment

Choose a reason for hiding this comment

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

I'll take a deeper look at it by the end of the week, but it looks quite good to me so far.

Comment thread src/specialmatrices/stdlib_specialmatrices.fypp
Comment thread src/specialmatrices/stdlib_specialmatrices_sym_tridiagonal.fypp Outdated
Comment thread src/specialmatrices/stdlib_specialmatrices_sym_tridiagonal.fypp Outdated
@loiseaujc loiseaujc marked this pull request as ready for review February 5, 2026 09:52
Copy link
Copy Markdown
Contributor

@loiseaujc loiseaujc left a comment

Choose a reason for hiding this comment

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

LGTM.

@loiseaujc
Copy link
Copy Markdown
Contributor

@perazz, @jalvesz and @jvdp1 : This PR is ready for merging. The only question I have left is a triviality though. What convention should we use for naming types : sym_tridiagonal_dp_type or symtridiagonal_dp_type ? My preference goes to the first one personally.

@Mahmood-Sinan
Copy link
Copy Markdown
Contributor Author

@perazz, @jalvesz and @jvdp1 : This PR is ready for merging. The only question I have left is a triviality though. What convention should we use for naming types : sym_tridiagonal_dp_type or symtridiagonal_dp_type ? My preference goes to the first one personally.

@perazz @jalvesz @jvdp1 Please look into this.

Copy link
Copy Markdown
Member

@jvdp1 jvdp1 left a comment

Choose a reason for hiding this comment

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

Thank you @Mahmood-Sinan for this PR. Please find below some comments and suggestions.

Comment thread doc/specs/stdlib_specialmatrices.md
Comment thread doc/specs/stdlib_specialmatrices.md Outdated

`A = ` [[stdlib_specialmatrices(module):sym_tridiagonal(interface)]] `(du, dv)`

- To construct a symmetric tridiagonal matrix of size `n x n` with constant diagonal elements `du` and `dv`:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

by "constant" do you mean "scalar"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I changed it so scalar now.

Comment thread doc/specs/stdlib_specialmatrices.md
Comment thread example/specialmatrices/example_sym_tridiagonal_dp_type.f90 Outdated
Comment thread src/specialmatrices/stdlib_specialmatrices.fypp
Comment thread src/specialmatrices/stdlib_specialmatrices_sym_tridiagonal.fypp Outdated
Comment thread test/linalg/test_linalg_specialmatrices.fypp Outdated
Comment thread test/linalg/test_linalg_specialmatrices.fypp Outdated
allocate(y1(n), source = 0.0_wp) ; allocate(y2(n), source=0.0_wp)

! Test y = A @ x
y1 = matmul(Amat, x) ; call spmv(A, x, y2)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
y1 = matmul(Amat, x) ; call spmv(A, x, y2)
y1 = matmul(Amat, x)
call spmv(A, x, y2)

Comment thread test/linalg/test_linalg_specialmatrices.fypp Outdated
@Mahmood-Sinan
Copy link
Copy Markdown
Contributor Author

Thank you @Mahmood-Sinan for this PR. Please find below some comments and suggestions.

Thank you so much for reviewing. I have made those changes. Please take a look at them.

@Mahmood-Sinan
Copy link
Copy Markdown
Contributor Author

@jvdp1 I have made the changes you asked for, please check

Copy link
Copy Markdown
Member

@jvdp1 jvdp1 left a comment

Choose a reason for hiding this comment

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

Thank you @Mahmood-Sinan for this PR (sorry for my delayed review). LGTM, and this PR is ready to be merged IMO.

@loiseaujc
Copy link
Copy Markdown
Contributor

I'll bother you for one last set of changes and then we can merge. Following #1162, can you make sure thesym_tridiagonal implementation handles the case of 1 x 1 matrices gracefully ?

@loiseaujc
Copy link
Copy Markdown
Contributor

@Mahmood-Sinan : LGTM. Thanks for reacting rapidly to the 1x1 edge case.

@jvdp1 : Do you mind if I merge this today so that @Mahmood-Sinan can include it in their GSoC application ?

@Mahmood-Sinan
Copy link
Copy Markdown
Contributor Author

@jvdp1 : Do you mind if I merge this today so that @Mahmood-Sinan can include it in their GSoC application ?

@jvdp1 please check.

@jvdp1
Copy link
Copy Markdown
Member

jvdp1 commented Apr 3, 2026

Sorry @Mahmood-Sinan and @loiseaujc for this late answer. I will merge it.

@jvdp1 jvdp1 merged commit 3b447b9 into fortran-lang:master Apr 3, 2026
75 of 77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants