+3,079 −0
Merged
Changes from all commits
Show all changes
108 commitsSelect commit Hold shift + click to select a range
5d0ff52
sparse API 1st commit
jalveszb1dcbf6
Merge branch 'fortran-lang:master' into sparse
jalveszc63c0dd
cmake build
jalveszd940ebd
Merge branch 'sparse' of https://.com/jalvesz/stdlib into sparse
jalvesz72481be
add data accessors set and get
jalvesza7cb6be
fix typo
jalveszd48dde5
change ij accessor as subroutine
jalvesz93c5c3a
Merge branch 'fortran-lang:master' into sparse
jalvesz6241ca3
fix missing i,j integer declaration
jalvesz0f2ee3b
Merge branch 'fortran-lang:master' into sparse
jalveszc1a85c4
Merge branch 'fortran-lang:master' into sparse
jalvesz2606691
Merge branch 'fortran-lang:master' into sparse
jalveszc34ac70
Merge branch 'fortran-lang:master' into sparse
jalvesz3126d16
Merge branch 'fortran-lang:master' into sparse
jalveszc0bbabb
Merge branch 'fortran-lang:master' into sparse
jalvesz2c2431d
add comments and change _t for _type
jalveszd64a045
revert matvec convention to (matrix,x,y)
jalvesz6786859
Merge branch 'fortran-lang:master' into sparse
jalveszd926581
Merge branch 'fortran-lang:master' into sparse
jalvesz22b477c
Merge branch 'sparse' of https://.com/jalvesz/stdlib into sparse
jalveszd165b8b
upgrade sparse support with SELLC format and more tests add suffix fo…
jalvesz8f72559
include alpha and beta parameters in sparse matvec
jalvesz87c867a
wrong ellpack size
jalvesz59fe24e
start sparse specs
jalvesz43ab25f
fix module name
jalvesz838b159
include reference
jalveszc74ad09
add matvec specs
jalvesz14bfef9
start adding conversions specs
jalvesz23be647
breaking change: rename matvec to spmv for consistency with stdlib bl…
jalvesz1d9dabc
Merge branch 'fortran-lang:master' into sparse
jalvesz8278f38
Merge branch 'fortran-lang:master' into sparse
jalvesz87bfd10
Merge branch 'fortran-lang:master' into sparse
jalvesz3fa318b
Merge branch 'fortran-lang:master' into sparse
jalvesz4aae5b4
Merge branch 'fortran-lang:master' into sparse
jalvesz14e9be0
Merge branch 'fortran-lang:master' into sparse
jalvesz6e679f5
change storage identifier names
jalvesz91e619a
add example with conversion and spmv
jalvesz7117d16
fix example path
jalvesz5b0aadf
make example runnable with cmake
jalveszc0438f0
update spec
jalvesze18b3fc
add coo2ordered procedure
jalvesz79534b3
Update doc/specs/stdlib_sparse.md
jalvesz5f35174
Update doc/specs/stdlib_sparse.md
jalveszb3de016
Update doc/specs/stdlib_sparse.md
jalvesz181760b
Update doc/specs/stdlib_sparse.md
jalvesz147a5c9
Update doc/specs/stdlib_sparse.md
jalveszc832eeb
Update doc/specs/stdlib_sparse.md
jalvesz22a70b1
Update doc/specs/stdlib_sparse.md
jalvesz9223345
Update doc/specs/stdlib_sparse.md
jalvesz827a1ef
Update doc/specs/stdlib_sparse.md
jalvesz21a8547
change get_value to function and add NaN if out of bounds
jalveszda9f171
change is ordered by is_sorted
jalvesz1cbb982
remove unused base attribute
jalvesza3c155a
forgotten base attribute
jalvesz2fb4e83
make set/get non_overridable
jalvesze78c026
replace quicksort 1D by stdlib sort
jalveszf25e07d
Setter procedure name change to 'add' covering scalar and array data
jalveszc7035c9
add sparse test for add or getting values
jalvesz82950e0
change name of value retrival function to at
jalvesz93c1e55
sellc add/at
jalveszc1f30f6
refactoring to enable a from_ijv initialization interface
jalvesz4c16f4a
fix module procedure attribute
jalvesz944212d
enable creating CSR, ELL and SELLC using the from_ijv interface
jalveszdd4dbd8
add example from_ijv
jalvesz2d7701e
unused matrix
jalvesz98a564b
add example and spec for add/at
jalveszb65d933
example print index
jalvesza94272e
add csr2dense direct conversion
jalvesze4c1f58
Merge branch 'fortran-lang:master' into sparse
jalvesz14e2c17
Merge branch 'fortran-lang:master' into sparse
jalveszb53eca2
Update doc/specs/stdlib_sparse.md
jalvesz65e3fcb
Update doc/specs/stdlib_sparse.md
jalvesz2f56cd4
Update doc/specs/stdlib_sparse.md
jalvesz941de3a
Update doc/specs/stdlib_sparse.md
jalvesz575c426
Update doc/specs/stdlib_sparse.md
jalveszdb73fdc
Update src/stdlib_sparse_kinds.fypp
jalvesz697afa2
Update src/stdlib_sparse_kinds.fypp
jalveszc97e665
Update src/stdlib_sparse_kinds.fypp
jalveszac100a1
Merge branch 'fortran-lang:master' into sparse
jalvesz9879a9c
Merge branch 'fortran-lang:master' into sparse
jalveszdde88a7
refactor spmv as submodule to keep parameters private, rework specs
jalvesz6ae038b
add an ilp parameter to change in the future for int64 if needed for …
jalvesz3596f3f
add the _type suffix to all sparse types
jalvesza21d1e8
Merge branch 'fortran-lang:master' into sparse
jalveszc8d94a3
rollback on submodules
jalvesz82dbe02
forgotten file in cmake
jalvesza8aa247
Merge branch 'fortran-lang:master' into sparse
jalvesz66b0ce2
Merge branch 'fortran-lang:master' into sparse
jalvesz4b41aa1
Merge branch 'fortran-lang:master' into sparse
jalveszab112e6
Merge branch 'fortran-lang:master' into sparse
jalveszbc0021b
add csc/coo conversions and diagonal extraction
jalvesz7279461
Merge branch 'fortran-lang:master' into sparse
jalvesza4d9306
Add in place operator for coo and csr spmv
jalveszcd30636
add support for op with ellpack
jalveszb68b4c8
add support for op with csc format
jalvesz62c702b
unit test in-place transpose
jalvesz581d215
Merge branch 'fortran-lang:master' into sparse
jalvesz59d33f0
complete spmv for the ellpack format including symmetric representations
jalveszbeafb3c
simplify csr spmv, remove unused var beta_
jalvesz7a26174
typo
jalvesz3746331
change file name
jalvesz3dfcecd
addtest
jalvesz89a993e
add in place transpose spmv for SELLC
jalveszae02481
simplify sellc spmv kernel
jalvesz680d35d
fix out-of-bounds
jalvesz5ceef37
Merge branch 'fortran-lang:master' into sparse
jalvesz7e45901
sellc hermitian transpose
jalvesz22cd23e
sellc: rollback on local associates, use embedded chunk kernels
jalveszFile filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Failed to load files.
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,364 @@ | ||
--- | ||
title: sparse | ||
--- | ||
# The `stdlib_sparse` module | ||
[TOC] | ||
## Introduction | ||
The `stdlib_sparse` module provides derived types for standard sparse matrix data structures. It also provides math kernels such as sparse matrix-vector product and conversion between matrix types. | ||
## Sparse matrix derived types | ||
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> | ||
### The `sparse_type` abstract derived type | ||
#### Status | ||
Experimental | ||
#### Description | ||
The parent `sparse_type` is as an abstract derived type holding the basic common meta data needed to define a sparse matrix, as well as shared APIs. All sparse matrix flavors are extended from the `sparse_type`. | ||
```Fortran | ||
type, public, abstract :: sparse_type | ||
integer :: nrows !! number of rows | ||
integer :: ncols !! number of columns | ||
integer :: nnz !! number of non-zero values | ||
integer :: storage !! assumed storage symmetry | ||
end type | ||
``` | ||
The storage integer label should be assigned from the module's internal enumerator containing the following three enums: | ||
```Fortran | ||
enum, bind(C) | ||
enumerator :: sparse_full !! Full Sparse matrix (no symmetry considerations) | ||
enumerator :: sparse_lower !! Symmetric Sparse matrix with triangular inferior storage | ||
enumerator :: sparse_upper !! Symmetric Sparse matrix with triangular supperior storage | ||
end enum | ||
``` | ||
In the following, all sparse kinds will be presented in two main flavors: a data-less type `<matrix>_type` useful for topological graph operations. And real/complex valued types `<matrix>_<kind>_type` containing the `data` buffer for the matrix values. The following rectangular matrix will be used to showcase how each sparse matrix holds the data internally: | ||
$$ M = \begin{bmatrix} | ||
9 & 0 & 0 & 0 & -3 \\ | ||
4 & 7 & 0 & 0 & 0 \\ | ||
0 & 8 & -1 & 8 & 0 \\ | ||
4 & 0 & 5 & 6 & 0 \\ | ||
\end{bmatrix} $$ | ||
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> | ||
### `COO`: The COOrdinates compressed sparse format | ||
#### Status | ||
Experimental | ||
#### Description | ||
The `COO`, triplet or `ijv` format defines all non-zero elements of the matrix by explicitly allocating the `i,j` index and the value of the matrix. While some implementations use separate `row` and `col` arrays for the index, here we use a 2D array in order to promote fast memory acces to `ij`. | ||
```Fortran | ||
type(COO_sp_type) :: COO | ||
call COO%malloc(4,5,10) | ||
perazz marked this conversation as resolved. Show resolved Hide resolvedUh oh!There was an error while loading. Please reload this page. | ||
COO%data(:) = real([9,-3,4,7,8,-1,8,4,5,6]) | ||
COO%index(1:2,1) = [1,1] | ||
COO%index(1:2,2) = [1,5] | ||
COO%index(1:2,3) = [2,1] | ||
COO%index(1:2,4) = [2,2] | ||
COO%index(1:2,5) = [3,2] | ||
COO%index(1:2,6) = [3,3] | ||
COO%index(1:2,7) = [3,4] | ||
COO%index(1:2,8) = [4,1] | ||
COO%index(1:2,9) = [4,3] | ||
COO%index(1:2,10) = [4,4] | ||
``` | ||
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> | ||
### `CSR`: The Compressed Sparse Row or Yale format | ||
#### Status | ||
Experimental | ||
#### Description | ||
The Compressed Sparse Row or Yale format `CSR` stores the matrix structure by compressing the row indices with a counter pointer `rowptr` enabling to know the first and last non-zero column index `col` of the given row. | ||
```Fortran | ||
type(CSR_sp_type) :: CSR | ||
call CSR%malloc(4,5,10) | ||
CSR%data(:) = real([9,-3,4,7,8,-1,8,4,5,6]) | ||
CSR%col(:) = [1,5,1,2,2,3,4,1,3,4] | ||
CSR%rowptr(:) = [1,3,5,8,11] | ||
``` | ||
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> | ||
### `CSC`: The Compressed Sparse Column format | ||
#### Status | ||
Experimental | ||
#### Description | ||
The Compressed Sparse Colum `CSC` is similar to the `CSR` format but values are accesed first by column, thus an index counter is given by `colptr` which enables to know the first and last non-zero row index of a given colum. | ||
```Fortran | ||
type(CSC_sp_type) :: CSC | ||
call CSC%malloc(4,5,10) | ||
CSC%data(:) = real([9,4,4,7,8,-1,5,8,6,-3]) | ||
CSC%row(:) = [1,2,4,2,3,3,4,3,4,1] | ||
CSC%colptr(:) = [1,4,6,8,10,11] | ||
``` | ||
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> | ||
### `ELLPACK`: ELL-pack storage format | ||
#### Status | ||
Experimental | ||
#### Description | ||
The `ELL` format stores data in a dense matrix of $nrows \times K$ in column major order. By imposing a constant number of elements per row $K$, this format will incur in additional zeros being stored, but it enables efficient vectorization as memory acces is carried out by constant sized strides. | ||
```Fortran | ||
type(ELL_sp_type) :: ELL | ||
call ELL%malloc(num_rows=4,num_cols=5,num_nz_row=3) | ||
ELL%data(1,1:3) = real([9,-3,0]) | ||
ELL%data(2,1:3) = real([4,7,0]) | ||
ELL%data(3,1:3) = real([8,-1,8]) | ||
ELL%data(4,1:3) = real([4,5,6]) | ||
ELL%index(1,1:3) = [1,5,0] | ||
ELL%index(2,1:3) = [1,2,0] | ||
ELL%index(3,1:3) = [2,3,4] | ||
ELL%index(4,1:3) = [1,3,4] | ||
``` | ||
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> | ||
### `SELL-C`: The Sliced ELLPACK with Constant blocks format | ||
#### Status | ||
Experimental | ||
#### Description | ||
The Sliced ELLPACK format `SELLC` is a variation of the `ELLPACK` format. This modification reduces the storage size compared to the `ELLPACK` format but maintaining its efficient data access scheme. It can be seen as an intermediate format between `CSR` and `ELLPACK`. For more details read [the reference](https://arxiv.org/pdf/1307.6209v1) | ||
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> | ||
## `add`- sparse matrix data accessors | ||
### Status | ||
Experimental | ||
### Description | ||
Type-bound procedures to enable adding data in a sparse matrix. | ||
### Syntax | ||
`call matrix%add(i,j,v)` or | ||
`call matrix%add(i(:),j(:),v(:,:))` | ||
### Arguments | ||
`i`: Shall be an integer value or rank-1 array. It is an `intent(in)` argument. | ||
`j`: Shall be an integer value or rank-1 array. It is an `intent(in)` argument. | ||
`v`: Shall be a `real` or `complex` value or rank-2 array. The type shall be in accordance to the declared sparse matrix object. It is an `intent(in)` argument. | ||
## `at`- sparse matrix data accessors | ||
### Status | ||
Experimental | ||
### Description | ||
Type-bound procedures to enable requesting data from a sparse matrix. | ||
### Syntax | ||
jalvesz marked this conversation as resolved. Show resolved Hide resolvedUh oh!There was an error while loading. Please reload this page. | ||
jvdp1 marked this conversation as resolved. Show resolved Hide resolvedUh oh!There was an error while loading. Please reload this page. | ||
`v = matrix%at(i,j)` | ||
### Arguments | ||
`i` : Shall be an integer value. It is an `intent(in)` argument. | ||
`j` : Shall be an integer value. It is an `intent(in)` argument. | ||
`v` : Shall be a `real` or `complex` value in accordance to the declared sparse matrix object. If the `ij` tuple is within the sparse pattern, `v` contains the value in the data buffer. If the `ij` tuple is outside the sparse pattern, `v` is equal `0`. If the `ij` tuple is outside the matrix pattern `(nrows,ncols)`, `v` is `NaN`. | ||
## Example | ||
```fortran | ||
{!example/linalg/example_sparse_data_accessors.f90!} | ||
``` | ||
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> | ||
## `spmv` - Sparse Matrix-Vector product | ||
### Status | ||
Experimental | ||
### Description | ||
Provide sparse matrix-vector product kernels for the current supported sparse matrix types. | ||
$$y=\alpha*op(M)*x+\beta*y$$ | ||
### Syntax | ||
`call ` [[stdlib_sparse_spmv(module):spmv(interface)]] `(matrix,vec_x,vec_y [,alpha,beta,op])` | ||
### Arguments | ||
`matrix`: Shall be a `real` or `complex` sparse type matrix. It is an `intent(in)` argument. | ||
`vec_x`: Shall be a rank-1 or rank-2 array of `real` or `complex` type array. It is an `intent(in)` argument. | ||
`vec_y`: Shall be a rank-1 or rank-2 array of `real` or `complex` type array. . It is an `intent(inout)` argument. | ||
`alpha`, `optional` : Shall be a scalar value of the same type as `vec_x`. Default value `alpha=1`. It is an `intent(in)` argument. | ||
`beta`, `optional` : Shall be a scalar value of the same type as `vec_x`. Default value `beta=0`. It is an `intent(in)` argument. | ||
`op`, `optional`: In-place operator identifier. Shall be a `character(1)` argument. It can have any of the following values: `N`: no transpose, `T`: transpose, `H`: hermitian or complex transpose. These values are provided as constants by the `stdlib_sparse` module: `sparse_op_none`, `sparse_op_transpose`, `sparse_op_hermitian` | ||
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> | ||
## Sparse matrix to matrix conversions | ||
### Status | ||
Experimental | ||
### Description | ||
This module provides facility functions for converting between storage formats. | ||
jvdp1 marked this conversation as resolved. Show resolved Hide resolvedUh oh!There was an error while loading. Please reload this page. | ||
### Syntax | ||
`call ` [[stdlib_sparse_conversion(module):coo2ordered(interface)]] `(coo[,sort_data])` | ||
### Arguments | ||
`COO` : Shall be any `COO` type. The same object will be returned with the arrays reallocated to the correct size after removing duplicates. It is an `intent(inout)` argument. | ||
`sort_data`, `optional` : Shall be a `logical` argument to determine whether data in the COO graph should be sorted while sorting the index array, default `.false.`. It is an `intent(in)` argument. | ||
### Syntax | ||
`call ` [[stdlib_sparse_conversion(module):from_ijv(interface)]] `(sparse,row,col[,data,nrows,ncols,num_nz_rows,chunk])` | ||
### Arguments | ||
`sparse` : Shall be a `COO`, `CSR`, `ELL` or `SELLC` type. The graph object will be returned with a canonical shape after sorting and removing duplicates from the `(row,col,data)` triplet. If the graph is `COO_type` no data buffer is allowed. It is an `intent(inout)` argument. | ||
`row` : rows index array. It is an `intent(in)` argument. | ||
`col` : columns index array. It is an `intent(in)` argument. | ||
`data`, `optional`: `real` or `complex` data array. It is an `intent(in)` argument. | ||
`nrows`, `optional`: number of rows, if not given it will be computed from the `row` array. It is an `intent(in)` argument. | ||
`ncols`, `optional`: number of columns, if not given it will be computed from the `col` array. It is an `intent(in)` argument. | ||
`num_nz_rows`, `optional`: number of non zeros per row, only valid in the case of an `ELL` matrix, by default it will computed from the largest row. It is an `intent(in)` argument. | ||
`chunk`, `optional`: chunk size, only valid in the case of a `SELLC` matrix, by default it will be taken from the `SELLC` default attribute chunk size. It is an `intent(in)` argument. | ||
## Example | ||
```fortran | ||
{!example/linalg/example_sparse_from_ijv.f90!} | ||
``` | ||
### Syntax | ||
`call ` [[stdlib_sparse_conversion(module):diag(interface)]] `(matrix,diagonal)` | ||
### Arguments | ||
`matrix` : Shall be a `dense`, `COO`, `CSR` or `ELL` type. It is an `intent(in)` argument. | ||
`diagonal` : A rank-1 array of the same type as the `matrix`. It is an `intent(inout)` and `allocatable` argument. | ||
#### Note | ||
If the `diagonal` array has not been previously allocated, the `diag` subroutine will allocate it using the `nrows` of the `matrix`. | ||
### Syntax | ||
`call ` [[stdlib_sparse_conversion(module):dense2coo(interface)]] `(dense,coo)` | ||
### Arguments | ||
`dense` : Shall be a rank-2 array of `real` or `complex` type. It is an `intent(in)` argument. | ||
`coo` : Shall be a `COO` type of `real` or `complex` type. It is an `intent(out)` argument. | ||
### Syntax | ||
`call ` [[stdlib_sparse_conversion(module):coo2dense(interface)]] `(coo,dense)` | ||
### Arguments | ||
`coo` : Shall be a `COO` type of `real` or `complex` type. It is an `intent(in)` argument. | ||
`dense` : Shall be a rank-2 array of `real` or `complex` type. It is an `intent(out)` argument. | ||
### Syntax | ||
`call ` [[stdlib_sparse_conversion(module):coo2csr(interface)]] `(coo,csr)` | ||
### Arguments | ||
`coo` : Shall be a `COO` type of `real` or `complex` type. It is an `intent(in)` argument. | ||
`csr` : Shall be a `CSR` type of `real` or `complex` type. It is an `intent(out)` argument. | ||
### Syntax | ||
`call ` [[stdlib_sparse_conversion(module):coo2csc(interface)]] `(coo,csc)` | ||
### Arguments | ||
`coo` : Shall be a `COO` type of `real` or `complex` type. It is an `intent(in)` argument. | ||
`csc` : Shall be a `CSC` type of `real` or `complex` type. It is an `intent(out)` argument. | ||
### Syntax | ||
`call ` [[stdlib_sparse_conversion(module):csr2coo(interface)]] `(csr,coo)` | ||
### Arguments | ||
`csr` : Shall be a `CSR` type of `real` or `complex` type. It is an `intent(in)` argument. | ||
`coo` : Shall be a `COO` type of `real` or `complex` type. It is an `intent(out)` argument. | ||
### Syntax | ||
`call ` [[stdlib_sparse_conversion(module):csr2sellc(interface)]] `(csr,sellc[,chunk])` | ||
### Arguments | ||
`csr` : Shall be a `CSR` type of `real` or `complex` type. It is an `intent(in)` argument. | ||
`sellc` : Shall be a `SELLC` type of `real` or `complex` type. It is an `intent(out)` argument. | ||
`chunk`, `optional`: chunk size for the Sliced ELLPACK format. It is an `intent(in)` argument. | ||
### Syntax | ||
`call ` [[stdlib_sparse_conversion(module):csr2sellc(interface)]] `(csr,ell[,num_nz_rows])` | ||
### Arguments | ||
`csr` : Shall be a `CSR` type of `real` or `complex` type. It is an `intent(in)` argument. | ||
`ell` : Shall be a `ELL` type of `real` or `complex` type. It is an `intent(out)` argument. | ||
`num_nz_rows`, `optional`: number of non zeros per row. If not give, it will correspond to the size of the longest row in the `CSR` matrix. It is an `intent(in)` argument. | ||
### Syntax | ||
`call ` [[stdlib_sparse_conversion(module):csc2coo(interface)]] `(csc,coo)` | ||
### Arguments | ||
`csc` : Shall be a `CSC` type of `real` or `complex` type. It is an `intent(in)` argument. | ||
`coo` : Shall be a `COO` type of `real` or `complex` type. It is an `intent(out)` argument. | ||
## Example | ||
```fortran | ||
{!example/linalg/example_sparse_spmv.f90!} | ||
``` |
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.