-
-
Notifications
You must be signed in to change notification settings - Fork 881
docs: add band matrix storage format documentation in the README of lapack/base
#8083
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: develop
Are you sure you want to change the base?
Changes from 6 commits
d04bbf9
5e9bfc5
a165f27
c418f0c
1d53da9
3983026
461abb7
4a61392
939a824
b284d11
d41266a
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 |
---|---|---|
|
@@ -22,6 +22,161 @@ limitations under the License. | |
|
||
> Base (i.e., lower-level) linear algebra package (LAPACK) routines. | ||
|
||
<section class="intro"> | ||
|
||
## Band Storage | ||
|
||
Many LAPACK routines work with banded matrices, which are stored compactly in two-dimensional arrays arranged in linear memory in order to save memory and improve computational efficiency. The following are the different band storage formats used throughout LAPACK. | ||
|
||
### General Band Matrix Storage | ||
|
||
A general band matrix of size `M`-by-`N` with `KL` subdiagonals and `KU` superdiagonals is stored in a two-dimensional array `AB` with `KL+KU+1` rows and `N` columns. | ||
|
||
**Storage Mapping:** | ||
|
||
- Columns of the original matrix are stored in corresponding columns of the array `AB`. | ||
- Diagonals of the matrix are stored in rows of the array `AB`. | ||
- Element `A[i, j]` from the original matrix is stored in `AB[KU+1+i-j, j]`. | ||
- Valid range for `i`: `max(1, j-KU) <= i <= min(M, j+KL)`. | ||
|
||
#### Example | ||
|
||
Let `M = N = 5`, `KL = 2`, and `KU = 1`. Given an original band matrix `A` | ||
|
||
<!-- <equation class="equation" label="eq:band_matrix_a" align="center" raw="A = \left[\begin{array}{rrrrr}a_{11} & a_{12} & 0 & 0 & 0 \\a_{21} & a_{22} & a_{23} & 0 & 0 \\a_{31} & a_{32} & a_{33} & a_{34} & 0 \\0 & a_{42} & a_{43} & a_{44} & a_{45} \\0 & 0 & a_{53} & a_{54} & a_{55}\end{array}\right]" alt="Representation of band matrix A."> --> | ||
|
||
|
||
```math | ||
A = \left[ | ||
\begin{array}{rrrrr} | ||
a_{11} & a_{12} & 0 & 0 & 0 \\ | ||
a_{21} & a_{22} & a_{23} & 0 & 0 \\ | ||
a_{31} & a_{32} & a_{33} & a_{34} & 0 \\ | ||
0 & a_{42} & a_{43} & a_{44} & a_{45} \\ | ||
0 & 0 & a_{53} & a_{54} & a_{55} | ||
\end{array} | ||
\right] | ||
``` | ||
|
||
<!-- </equation> --> | ||
|
||
the band storage matrix `AB` is then | ||
|
||
<!-- <equation class="equation" label="eq:band_storage_ab" align="center" raw="AB = \left[\begin{array}{rrrrr}* & a_{12} & a_{23} & a_{34} & a_{45} \\a_{11} & a_{22} & a_{33} & a_{44} & a_{55} \\a_{21} & a_{32} & a_{43} & a_{54} & * \\a_{31} & a_{42} & a_{53} & * & *\end{array}\right]" alt="Band storage representation of matrix A."> --> | ||
|
||
```math | ||
AB = \left[ | ||
\begin{array}{rrrrr} | ||
* & a_{12} & a_{23} & a_{34} & a_{45} \\ | ||
a_{11} & a_{22} & a_{33} & a_{44} & a_{55} \\ | ||
a_{21} & a_{32} & a_{43} & a_{54} & * \\ | ||
a_{31} & a_{42} & a_{53} & * & * | ||
\end{array} | ||
\right] | ||
``` | ||
|
||
<!-- </equation> --> | ||
|
||
`AB` is a 4×5 matrix as `KL+KU+1 = 2+1+1 = 4`. Elements marked `*` need not be set and are not referenced by LAPACK routines. | ||
|
||
**Note:** When a band matrix is supplied for LU factorization, space must be allowed to store an additional `KL` superdiagonals, which are generated by fill-in as a result of row interchanges. This means that the matrix is stored according to the above scheme, but with `KL + KU` superdiagonals. | ||
|
||
### Triangular Band Matrices | ||
|
||
Triangular band matrices are stored in the same format as general band matrices: | ||
|
||
- If `KL = 0`, the matrix is upper triangular. | ||
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. It would be good to actually show matrices which are upper and lower triangular here. |
||
- If `KU = 0`, the matrix is lower triangular. | ||
|
||
### Symmetric or Hermitian Band Matrices | ||
|
||
For symmetric or Hermitian band matrices with `KD` subdiagonals or superdiagonals, only the upper or lower triangle (as specified by an `UPLO` parameter) needs to be stored. | ||
|
||
**Upper Triangle Storage (UPLO = 'U'):** | ||
|
||
- Element `A[i, j]` is stored in `AB[KD+1+i-j, j]`. | ||
- Valid range for `i`: `max(1, j-KD) <= i <= j`. | ||
|
||
**Lower Triangle Storage (UPLO = 'L'):** | ||
|
||
- Element `A[i, j]` is stored in `AB[1+i-j, j]`. | ||
- Valid range for `i`: `j <= i <= min(N, j+KD)`. | ||
|
||
#### Example | ||
|
||
Let `N = 5` and `KD = 2`. Given the following matrix `A`, | ||
|
||
<!-- <equation class="equation" label="eq:symmetric_upper_a" align="center" raw="A = \left[\begin{array}{rrrrr}a_{11} & a_{12} & a_{13} & 0 & 0 \\{a_{12}} & a_{22} & a_{23} & a_{24} & 0 \\{a_{13}} & {a_{23}} & a_{33} & a_{34} & a_{35} \\0 & {a_{24}} & {a_{34}} & a_{44} & a_{45} \\0 & 0 & {a_{35}} & {a_{45}} & a_{55}\end{array}\right]" alt="Representation of symmetric band matrix A (upper triangle)."> --> | ||
|
||
```math | ||
A = \left[ | ||
\begin{array}{rrrrr} | ||
a_{11} & a_{12} & a_{13} & 0 & 0 \\ | ||
{a_{12}} & a_{22} & a_{23} & a_{24} & 0 \\ | ||
{a_{13}} & {a_{23}} & a_{33} & a_{34} & a_{35} \\ | ||
0 & {a_{24}} & {a_{34}} & a_{44} & a_{45} \\ | ||
0 & 0 & {a_{35}} & {a_{45}} & a_{55} | ||
\end{array} | ||
\right] | ||
``` | ||
|
||
<!-- </equation> --> | ||
|
||
the band storage matrix `AB` when `UPLO = 'U'` (i.e., upper triangle) is | ||
|
||
<!-- <equation class="equation" label="eq:symmetric_upper_ab" align="center" raw="AB = \left[\begin{array}{rrrrr}* & * & a_{13} & a_{24} & a_{35} \\* & a_{12} & a_{23} & a_{34} & a_{45} \\a_{11} & a_{22} & a_{33} & a_{44} & a_{55}\end{array}\right]" alt="Band storage representation of symmetric matrix A (upper triangle)."> --> | ||
|
||
```math | ||
AB = \left[ | ||
\begin{array}{rrrrr} | ||
* & * & a_{13} & a_{24} & a_{35} \\ | ||
* & a_{12} & a_{23} & a_{34} & a_{45} \\ | ||
a_{11} & a_{22} & a_{33} & a_{44} & a_{55} | ||
\end{array} | ||
\right] | ||
``` | ||
|
||
<!-- </equation> --> | ||
|
||
`AB` is a 3×5 matrix is 3×5 as `KD+1 = 2+1 = 3`. Similarly, given the following matrix `A`, | ||
kgryte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
<!-- <equation class="equation" label="eq:symmetric_lower_a" align="center" raw="A = \left[\begin{array}{rrrrr}a_{11} & {a_{21}} & {a_{31}} & 0 & 0 \\a_{21} & a_{22} & {a_{32}} & {a_{42}} & 0 \\a_{31} & a_{32} & a_{33} & {a_{43}} & {a_{53}} \\0 & a_{42} & a_{43} & a_{44} & {a_{54}} \\0 & 0 & a_{53} & a_{54} & a_{55}\end{array}\right]" alt="Representation of symmetric band matrix A (lower triangle)."> --> | ||
|
||
```math | ||
A = \left[ | ||
\begin{array}{rrrrr} | ||
a_{11} & {a_{21}} & {a_{31}} & 0 & 0 \\ | ||
a_{21} & a_{22} & {a_{32}} & {a_{42}} & 0 \\ | ||
a_{31} & a_{32} & a_{33} & {a_{43}} & {a_{53}} \\ | ||
0 & a_{42} & a_{43} & a_{44} & {a_{54}} \\ | ||
0 & 0 & a_{53} & a_{54} & a_{55} | ||
\end{array} | ||
\right] | ||
``` | ||
|
||
<!-- </equation> --> | ||
|
||
the band storage matrix `AB` when `UPLO = 'L'` (i.e., lower triangle) is | ||
|
||
<!-- <equation class="equation" label="eq:symmetric_lower_ab" align="center" raw="AB = \left[\begin{array}{rrrrr}a_{11} & a_{22} & a_{33} & a_{44} & a_{55} \\a_{21} & a_{32} & a_{43} & a_{54} & * \\a_{31} & a_{42} & a_{53} & * & *\end{array}\right]" alt="Band storage representation of symmetric matrix A (lower triangle)."> --> | ||
|
||
```math | ||
AB = \left[ | ||
\begin{array}{rrrrr} | ||
a_{11} & a_{22} & a_{33} & a_{44} & a_{55} \\ | ||
a_{21} & a_{32} & a_{43} & a_{54} & * \\ | ||
a_{31} & a_{42} & a_{53} & * & * | ||
\end{array} | ||
\right] | ||
``` | ||
|
||
`AB` is a 3×5 matrix as `KD+1 = 2+1 = 3`. | ||
kgryte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
<!-- </equation> --> | ||
|
||
</section> | ||
|
||
<!-- /.intro --> | ||
|
||
<section class="usage"> | ||
|
||
## Usage | ||
|
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.
Overall, this is looking good. It's a more readable version of https://netlib.org/lapack/lug/node124.html. That stated, one thing which needs to be changed is that currently everything is written using one-based indexing. We need to update everything to zero-based indexing.