-
Notifications
You must be signed in to change notification settings - Fork 221
Add symmetric tridiagonal matrices module #1091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 11 commits
492c378
ce3f60f
624bdfa
af1df17
eecc723
bf53d95
ab6b3d1
f692605
97464f4
a17f62c
6e4291b
173283c
fc95858
70796c9
867cf4e
7054d66
3dff7c4
5081221
2121952
154f312
3dc8641
dd191d7
296c35a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
|
@@ -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 | ||
|
|
@@ -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`. | ||
| 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`: | ||
|
||
|
|
||
| `A = ` [[stdlib_specialmatrices(module):sym_tridiagonal(interface)]] `(du, dv, n)` | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please define (type, kind, intent, ...) the variables
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
|
@@ -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 | ||
|
|
||
|
|
@@ -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 | ||
|
|
||
|
|
@@ -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. | ||
|
|
||
| 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) |
| 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 | ||||||
|
||||||
| use stdlib_specialmatrices | |
| use stdlib_specialmatrices, only: sym_tridiagonal_dp_type, sym_tridiagonal |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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...