Skip to content

Commit 009faa6

Browse files
committed
document interaction with LinearSolve
1 parent 1d037e0 commit 009faa6

File tree

6 files changed

+82
-19
lines changed

6 files changed

+82
-19
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ The later is modeled after the linked list sparse matrix format described in the
1414

1515
Any linear algebra method on `ExtendableSparseMatrix` starts with a `flush!` method which adds the LNK entries and the existing CSC entries into a new CSC struct and resets the LNK struct.
1616

17-
`ExtendableSparseMatrix` is aimed to work as a drop-in replacement to `SparseMatrixCSC` in finite element and finite volume codes especally in those cases where the sparsity structure is hard to detect a priori and where working with an intermediadte COO representation appears to be not convenient.
17+
`ExtendableSparseMatrix` is aimed to work as a drop-in replacement to `SparseMatrixCSC` in finite element and finite volume codes especially in those cases where the sparsity structure is hard to detect a priori and where working with an intermediadte COO representation appears to be not convenient.
1818

1919

2020

2121
## Caveat
2222

2323
This package assumes that a $m \times n$ matrix is sparse if *each* row and *each* column have less than $C$ entries with
24-
$C << n$ and $C <<m$ . Adding a full matrix row will be a performance hit.
24+
$C << n$ and $C << m$ . Adding a full matrix row will be a performance hit.
2525

2626

2727
## Working with ForwardDiff
@@ -59,6 +59,9 @@ For details, see the [corresponding documentation](https://j-fu.github.io/Extend
5959

6060

6161
### Interfaces to other packages
62+
With version 0.7, the package becomes compatible with [LinearSolve.jl](https://github.com/SciML/LinearSolve.jl).
63+
Matrices of type `ExtendableSparseMatrix` can be passed to the `LinearProblem` constructor of [LinearSolve.jl](https://github.com/SciML/LinearSolve.jl).
64+
6265
The package provides interfaces to other sparse matrix solvers and preconditioners. Dependencies on these
6366
packages are handeled via [Requires.jl](https://github.com/JuliaPackaging/Requires.jl).
6467
Currently, support includes:

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ DocumenterTools = "35a29f4d-8980-5a13-9543-d66fff28ecb8"
77
ExtendableSparse = "95c220a8-a1cf-11e9-0c77-dbfce5f500b3"
88
IncompleteLU = "40713840-3770-5561-ab4c-a76e7d0d7895"
99
IterativeSolvers = "42fd0dbc-a981-5370-80f2-aaf504508153"
10+
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
1011
Pardiso = "46dd5b70-b6fb-5a00-ae2d-e8fea33afaf2"

docs/make.jl

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
push!(LOAD_PATH,"../src/")
2-
using Documenter, ExtendableSparse,Pardiso,AlgebraicMultigrid,IncompleteLU
2+
using Documenter, ExtendableSparse,Pardiso,AlgebraicMultigrid,IncompleteLU,LinearSolve
33

4-
makedocs(sitename="ExtendableSparse.jl",
5-
modules = [ExtendableSparse],
6-
doctest = true,
7-
clean = false,
8-
authors = "J. Fuhrmann",
9-
repo="https://github.com/j-fu/ExtendableSparse.jl",
10-
pages=[
11-
"Home"=>"index.md",
12-
"example.md",
13-
"extsparse.md",
14-
"iter.md",
15-
"internal.md",
16-
"changes.md",
17-
])
4+
function mkdocs()
5+
makedocs(sitename="ExtendableSparse.jl",
6+
modules = [ExtendableSparse],
7+
doctest = true,
8+
clean = false,
9+
authors = "J. Fuhrmann",
10+
repo="https://github.com/j-fu/ExtendableSparse.jl",
11+
pages=[
12+
"Home"=>"index.md",
13+
"example.md",
14+
"extsparse.md",
15+
"iter.md",
16+
"linearsolve.md",
17+
"internal.md",
18+
"changes.md",
19+
])
20+
end
21+
22+
mkdocs()
1823

1924
deploydocs(repo = "github.com/j-fu/ExtendableSparse.jl.git")

docs/src/changes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# Changes
2+
## v0.7, August 19, 2022
3+
- Require Julia 1.6
4+
- first steps to compatibility with LinearSolve.jl
5+
## v0.6, April 20, 2021
6+
- use type parameters to describe factorizations
27
## v0.5, April 10, 2021
38
- Introduce lu/lu! , factorize/factorize!, unifying LU factorizations and preconditioners
49
- Interface packages: Pardiso, AlgebraicMultigrid, IncompleteLU via Requires.jl

docs/src/linearsolve.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Integration with LinearSolve.jl
2+
3+
Starting with version 0.7, ExtendableSparse tries to become compatible
4+
with [LinearSolve.jl](https://github.com/SciML/LinearSolve.jl).
5+
For this purpose, it extends the `LinearProblem` constructor and the
6+
`set_A` function by methods specific for `ExtendableSparseMatrix`.
7+
8+
```@docs
9+
LinearSolve.LinearProblem(::ExtendableSparseMatrix,x,p;kwargs...)
10+
LinearSolve.set_A(::LinearSolve.LinearCache,::ExtendableSparseMatrix)
11+
```
12+
13+
We can create a test problem and solve it with the `\` operator.
14+
```@example
15+
using ExtendableSparse # hide
16+
A=fdrand(10,10,10,matrixtype=ExtendableSparseMatrix)
17+
x=ones(1000)
18+
b=A*x
19+
y=A\b
20+
sum(y)
21+
```
22+
23+
The same problem can be solved by the tools available via `LinearSolve.jl`:
24+
```@example
25+
using ExtendableSparse # hide
26+
using LinearSolve # hide
27+
A=fdrand(10,10,10,matrixtype=ExtendableSparseMatrix)
28+
x=ones(1000)
29+
b=A*x
30+
y=solve(LinearProblem(A,b),KLUFactorization()).u
31+
sum(y)
32+
```
33+
34+
35+
Also, the iterative method interface works with the preconditioners defined in this package.
36+
```@example
37+
using ExtendableSparse # hide
38+
using LinearSolve # hide
39+
A=fdrand(10,10,10,matrixtype=ExtendableSparseMatrix)
40+
x=ones(1000)
41+
b=A*x
42+
y=LinearSolve.solve(LinearProblem(A,b),IterativeSolversJL_CG(),Pl=ILU0Preconditioner(A)).u
43+
sum(y)
44+
```

src/extendable.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,12 @@ $(SIGNATURES)
230230
"""
231231
function SparseArrays.rowvals(ext::ExtendableSparseMatrix)
232232
@inbounds flush!(ext)
233-
return rowvals(ext.cscmatrix)
233+
rowvals(ext.cscmatrix)
234+
end
235+
236+
function SparseArrays.getrowval(S::ExtendableSparseMatrix)
237+
flush!(S)
238+
getfield(S.cscmatrix, :rowval)
234239
end
235240

236241

@@ -239,7 +244,7 @@ $(SIGNATURES)
239244
240245
[`flush!`](@ref) and return colptr of in ext.cscmatrix.
241246
"""
242-
function colptrs(ext::ExtendableSparseMatrix)
247+
function SparseArrays.getcolptr(ext::ExtendableSparseMatrix)
243248
@inbounds flush!(ext)
244249
return ext.cscmatrix.colptr
245250
end

0 commit comments

Comments
 (0)