Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
492c378
added function definitions
Mahmood-Sinan Dec 22, 2025
ce3f60f
added function implementations and examples
Mahmood-Sinan Dec 22, 2025
624bdfa
added tests for sym_tridiag and renamed the test suite name
Mahmood-Sinan Dec 22, 2025
af1df17
docs: add symmetric tridiagonal matrices and cdp example
Mahmood-Sinan Dec 22, 2025
eecc723
add build functions for construction of matrices from arrays and cons…
Mahmood-Sinan Jan 25, 2026
bf53d95
merge
Mahmood-Sinan Jan 25, 2026
ab6b3d1
merged the latest stdlib and moved sym_tridiagonal into specialmatric…
Mahmood-Sinan Jan 25, 2026
f692605
move build constructors under interfaces
Mahmood-Sinan Jan 25, 2026
97464f4
remove if condition for linalg_error_handling inside constructors
Mahmood-Sinan Jan 28, 2026
a17f62c
modify the fypp logic inside spmv for rank based preprocessing
Mahmood-Sinan Jan 31, 2026
6e4291b
Merge remote-tracking branch 'upstream/master' into symtridiag
Mahmood-Sinan Feb 1, 2026
173283c
Merge remote-tracking branch 'upstream/master' into symtridiag
Mahmood-Sinan Feb 6, 2026
fc95858
add: spmv error check for operator for sym tridiag, modify: example p…
Mahmood-Sinan Feb 6, 2026
70796c9
Merge remote-tracking branch 'upstream/master' into symtridiag
Mahmood-Sinan Feb 20, 2026
867cf4e
update: docs to add arguments and missing sentence
Mahmood-Sinan Feb 20, 2026
7054d66
modify: example and src
Mahmood-Sinan Feb 20, 2026
3dff7c4
modify: add new lines between inline assignments
Mahmood-Sinan Feb 20, 2026
5081221
add: new lines in test
Mahmood-Sinan Feb 20, 2026
2121952
add debug statements in test
Mahmood-Sinan Feb 21, 2026
154f312
change constant to scalar inside comments
Mahmood-Sinan Feb 21, 2026
3dc8641
modify: if(present()) to optval inside spmv
Mahmood-Sinan Feb 21, 2026
dd191d7
change: constant to scalar inside docs
Mahmood-Sinan Feb 21, 2026
296c35a
modify: docs to add err argument
Mahmood-Sinan Feb 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 59 additions & 4 deletions doc/specs/stdlib_specialmatrices.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The `stdlib_specialmatrices` module provides derived types and specialized drive
These include:

- Tridiagonal matrices
- Symmetric Tridiagonal matrices (not yet supported)
- Symmetric tridiagonal matrices
- Circulant matrices (not yet supported)
- Toeplitz matrices (not yet supported)
- Hankel matrices (not yet supported)
Expand All @@ -32,7 +32,7 @@ Experimental

#### Description

Tridiagonal matrices are ubiquituous in scientific computing and often appear when discretizing 1D differential operators.
Tridiagonal matrices are ubiquitous in scientific computing and often appear when discretizing 1D differential operators.
A generic tridiagonal matrix has the following structure:
$$
A
Expand Down Expand Up @@ -76,6 +76,58 @@ Tridiagonal matrices are available with all supported data types as `tridiagonal
{!example/specialmatrices/example_tridiagonal_dp_type.f90!}
```

### Symmetric tridiagonal matrices {#Sym_tridiagonal}

#### Status

Experimental

#### Description

Symmetric tridiagonal matrices are a special case of tridiagonal matrices in which the subdiagonal and superdiagonal are identical.
A generic symmetric tridiagonal matrix has the following structure:
$$
A
=
\begin{bmatrix}
a_1 & b_1 \\
b_1 & a_2 & b_2 \\
& \ddots & \ddots & \ddots \\
& & b_{n-2} & a_{n-1} & b_{n-1} \\
& & & b_{n-1} & a_n
\end{bmatrix}.
$$
Hence, only one vector of size `n` and one vector of size `n-1` need to be stored to fully represent the matrix.
Interfaces to the most common ones will soon be provided by `stdlib_specialmatrices`.
Copy link
Member

Choose a reason for hiding this comment

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

What do you mean be "soon"? Is it not what is proposed in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for noticing. I have missed out a sentence before this which was common for both tridiagonal and symmetric tridiagonal. I added that sentence now. The interfances that this sentence talks about were solve, inverse, etc...

Symmetric tridiagonal matrices are available with all supported data types as `sym_tridiagonal_<kind>_type`, for example:

- `sym_tridiagonal_sp_type` : Symmetric tridiagonal matrix of size `n` with `real`/`single precision` data.
- `sym_tridiagonal_dp_type` : Symmetric tridiagonal matrix of size `n` with `real`/`double precision` data.
- `sym_tridiagonal_xdp_type` : Symmetric tridiagonal matrix of size `n` with `real`/`extended precision` data.
- `sym_tridiagonal_qp_type` : Symmetric tridiagonal matrix of size `n` with `real`/`quadruple precision` data.
- `sym_tridiagonal_csp_type` : Symmetric tridiagonal matrix of size `n` with `complex`/`single precision` data.
- `sym_tridiagonal_cdp_type` : Symmetric tridiagonal matrix of size `n` with `complex`/`double precision` data.
- `sym_tridiagonal_cxdp_type` : Symmetric tridiagonal matrix of size `n` with `complex`/`extended precision` data.
- `sym_tridiagonal_cqp_type` : Symmetric tridiagonal matrix of size `n` with `complex`/`quadruple precision` data.


#### Syntax

- To construct a symmetric tridiagonal matrix from already allocated arrays `du` (off-diagonal, size `n-1`) and `dv` (main diagonal, size `n`):

`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
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
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.


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

Copy link
Member

Choose a reason for hiding this comment

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

Please define (type, kind, intent, ...) the variables du, dv, n.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added them now under a new heading named arguments.

#### Example

```fortran
{!example/specialmatrices/example_sym_tridiagonal_dp_type.f90!}
```


## Specialized drivers for linear algebra tasks

Below is a list of all the specialized drivers for linear algebra tasks currently provided by the `stdlib_specialmatrices` module.
Expand All @@ -90,7 +142,7 @@ Experimental

With the exception of `extended precision` and `quadruple precision`, all the types provided by `stdlib_specialmatrices` benefit from specialized kernels for matrix-vector products accessible via the common `spmv` interface.

- For `tridiagonal` matrices, the backend is either LAPACK `lagtm` or the generalized routine `glagtm`, depending on the values and types of `alpha` and `beta`.
- For `tridiagonal` and `symmetric tridiagonal` matrices, the backend is either LAPACK `lagtm` or the generalized routine `glagtm`, depending on the values and types of `alpha` and `beta`.

#### Syntax

Expand All @@ -115,6 +167,9 @@ With the exception of `extended precision` and `quadruple precision`, all the ty
```fortran
{!example/specialmatrices/example_specialmatrices_dp_spmv.f90!}
```
```fortran
{!example/specialmatrices/example_specialmatrices_cdp_spmv.f90!}
```

## Utility functions

Expand Down Expand Up @@ -186,7 +241,7 @@ Experimental

#### Description

The definition of all standard artihmetic operators have been overloaded to be applicable for the matrix types defined by `stdlib_specialmatrices`:
The definition of all standard arithmetic operators have been overloaded to be applicable for the matrix types defined by `stdlib_specialmatrices`:

- Overloading the `+` operator for adding two matrices of the same type and kind.
- Overloading the `-` operator for subtracting two matrices of the same type and kind.
Expand Down
1 change: 1 addition & 0 deletions example/specialmatrices/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ADD_EXAMPLE(specialmatrices_dp_spmv)
ADD_EXAMPLE(specialmatrices_cdp_spmv)
ADD_EXAMPLE(tridiagonal_dp_type)
ADD_EXAMPLE(sym_tridiagonal_dp_type)
17 changes: 17 additions & 0 deletions example/specialmatrices/example_sym_tridiagonal_dp_type.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
program example_tridiagonal_matrix
use stdlib_linalg_constants, only: dp
use stdlib_specialmatrices
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
use stdlib_specialmatrices
use stdlib_specialmatrices, only: sym_tridiagonal_dp_type, sym_tridiagonal

implicit none

integer, parameter :: n = 5
type(sym_tridiagonal_dp_type) :: A
real(dp) :: du(n - 1), dv(n)

! Generate random symmteric tridiagonal elements.
call random_number(du)
call random_number(dv)

! Create the corresponding Tridiagonal matrix.
A = sym_tridiagonal(du, dv)

end program example_tridiagonal_matrix
1 change: 1 addition & 0 deletions src/specialmatrices/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set(specialmatrices_fppFiles
stdlib_specialmatrices.fypp
stdlib_specialmatrices_tridiagonal.fypp
stdlib_specialmatrices_sym_tridiagonal.fypp
)

set(specialmatrices_cppFiles
Expand Down
Loading
Loading