Skip to content

Commit 1a1b829

Browse files
authored
Add more functionality (#22)
- Addition, multiplication etc. for ExtendableSparse - ILUZero.jl as dependency for ILUZeroPreconditioner - fix ILU0Preconditioner backsubstitution for unsymmetric matrices
1 parent 3377f85 commit 1a1b829

File tree

11 files changed

+278
-101
lines changed

11 files changed

+278
-101
lines changed

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name = "ExtendableSparse"
22
uuid = "95c220a8-a1cf-11e9-0c77-dbfce5f500b3"
33
authors = ["Juergen Fuhrmann <juergen.fuhrmann@wias-berlin.de>"]
4-
version = "0.9.2"
4+
version = "0.9.3"
55

66
[deps]
77
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
8+
ILUZero = "88f59080-6952-5380-9ea5-54057fb9a43f"
89
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
910
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1011
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
@@ -15,9 +16,10 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1516

1617
[compat]
1718
DocStringExtensions = "0.8.0,0.9"
19+
ILUZero= "0.2"
1820
Requires = "1.1.3"
21+
Sparspak = "0.3.0"
1922
julia = "1.6"
20-
Sparspak= "0.3.0"
2123

2224
[extras]
2325
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"

docs/src/iter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,6 @@ nm1,nm2
124124

125125
```@autodocs
126126
Modules = [ExtendableSparse]
127-
Pages = ["jacobi.jl","ilu0.jl","parallel_jacobi.jl","ilut.jl","amg.jl"]
127+
Pages = ["jacobi.jl","parallel_jacobi.jl","iluzero.jl","ilu0.jl","ilut.jl","amg.jl"]
128128
```
129129

src/ExtendableSparse.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module ExtendableSparse
22
using SparseArrays
33
using LinearAlgebra
44
using Sparspak
5+
using ILUZero
56

67

78
# Define our own constant here in order to be able to
@@ -28,19 +29,16 @@ export SparseMatrixLNK,ExtendableSparseMatrix,flush!,nnz, updateindex!, rawupdat
2829

2930

3031
include("factorizations.jl")
31-
export JacobiPreconditioner, ILU0Preconditioner, ParallelJacobiPreconditioner, ParallelILU0Preconditioner, reorderlinsys
32+
33+
export JacobiPreconditioner, ILU0Preconditioner,ILUZeroPreconditioner, ParallelJacobiPreconditioner, ParallelILU0Preconditioner, reorderlinsys
3234
export AbstractFactorization,LUFactorization, CholeskyFactorization
3335
export issolver
3436
export factorize!, update!
35-
export ILUTPreconditioner, AMGPreconditioner
36-
export PardisoLU, MKLPardisoLU,SparspakLU
3737

3838
include("simple_iteration.jl")
3939
export simple,simple!
4040

4141

42-
43-
4442
include("sprand.jl")
4543
export sprand!,sprand_sdd!, fdrand,fdrand!,fdrand_coo, solverbenchmark
4644

@@ -51,6 +49,8 @@ function __init__()
5149
@require AlgebraicMultigrid = "2169fc97-5a83-5252-b627-83903c6c433c" include("amg.jl")
5250
end
5351

52+
export ILUTPreconditioner, AMGPreconditioner
53+
export PardisoLU, MKLPardisoLU,SparspakLU
5454

5555

5656
end # module

src/extendable.jl

Lines changed: 108 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ function ExtendableSparseMatrix(valuetype::Type{Tv},indextype::Type{Ti},m, n) wh
4444
end
4545

4646
ExtendableSparseMatrix(valuetype::Type{Tv},m, n) where{Tv}=ExtendableSparseMatrix{Tv,Int}(m,n)
47+
4748
ExtendableSparseMatrix(m, n)=ExtendableSparseMatrix{Float64,Int}(m,n)
4849

4950
"""
@@ -55,6 +56,59 @@ function ExtendableSparseMatrix(csc::SparseMatrixCSC{Tv,Ti}) where{Tv,Ti<:Intege
5556
return ExtendableSparseMatrix{Tv,Ti}(csc, nothing, phash(csc))
5657
end
5758

59+
60+
"""
61+
$(SIGNATURES)
62+
63+
Create ExtendableSparseMatrix from Diagonal
64+
"""
65+
ExtendableSparseMatrix(D::Diagonal)=ExtendableSparseMatrix(sparse(D))
66+
67+
"""
68+
$(SIGNATURES)
69+
70+
Create ExtendableSparseMatrix from AbstractMatrix, dropping all zero entries.
71+
This is the equivalent to `sparse(A)`.
72+
"""
73+
ExtendableSparseMatrix(A::AbstractMatrix)=ExtendableSparseMatrix(sparse(A))
74+
75+
"""
76+
ExtendableSparseMatrix(I,J,V)
77+
ExtendableSparseMatrix(I,J,V,m,n)
78+
ExtendableSparseMatrix(I,J,V,combine::Function)
79+
ExtendableSparseMatrix(I,J,V,m,n,combine::Function)
80+
81+
Create ExtendableSparseMatrix from triplet (COO) data.
82+
"""
83+
ExtendableSparseMatrix(I,J,V::AbstractVector)=ExtendableSparseMatrix(sparse(I,J,V))
84+
ExtendableSparseMatrix(I,J,V::AbstractVector,m,n)=ExtendableSparseMatrix(sparse(I,J,V,m,n))
85+
ExtendableSparseMatrix(I,J,V::AbstractVector,combine::Function)=ExtendableSparseMatrix(sparse(I,J,V,combine))
86+
ExtendableSparseMatrix(I,J,V::AbstractVector,m,n,combine::Function)=ExtendableSparseMatrix(sparse(I,J,V,m,n,combine))
87+
88+
89+
# THese are probably too much...
90+
# function Base.transpose(A::ExtendableSparseMatrix)
91+
# flush!(A)
92+
# ExtendableSparseMatrix(Base.transpose(sparse(A)))
93+
# end
94+
# function Base.adjoint(A::ExtendableSparseMatrix)
95+
# flush!(A)
96+
# ExtendableSparseMatrix(Base.adjoint(sparse(A)))
97+
# end
98+
# function SparseArrays.sparse(text::LinearAlgebra.Transpose{Tv,ExtendableSparseMatrix{Tv,Ti}}) where {Tv,Ti}
99+
# transpose(sparse(parent(text)))
100+
# end
101+
102+
"""
103+
$(SIGNATURES)
104+
105+
Create SparseMatrixCSC from ExtendableSparseMatrix
106+
"""
107+
function SparseArrays.sparse(A::ExtendableSparseMatrix)
108+
flush!(A)
109+
A.cscmatrix
110+
end
111+
58112
"""
59113
$(SIGNATURES)
60114
@@ -211,7 +265,7 @@ $(SIGNATURES)
211265
[`flush!`](@ref) and return number of nonzeros in ext.cscmatrix.
212266
"""
213267
function SparseArrays.nnz(ext::ExtendableSparseMatrix)
214-
@inbounds flush!(ext)
268+
flush!(ext)
215269
return nnz(ext.cscmatrix)
216270
end
217271

@@ -222,7 +276,7 @@ $(SIGNATURES)
222276
[`flush!`](@ref) and return nonzeros in ext.cscmatrix.
223277
"""
224278
function SparseArrays.nonzeros(ext::ExtendableSparseMatrix)
225-
@inbounds flush!(ext)
279+
flush!(ext)
226280
return nonzeros(ext.cscmatrix)
227281
end
228282

@@ -234,7 +288,7 @@ $(SIGNATURES)
234288
[`flush!`](@ref) and return rowvals in ext.cscmatrix.
235289
"""
236290
function SparseArrays.rowvals(ext::ExtendableSparseMatrix)
237-
@inbounds flush!(ext)
291+
flush!(ext)
238292
rowvals(ext.cscmatrix)
239293
end
240294

@@ -244,13 +298,16 @@ function SparseArrays.getrowval(S::ExtendableSparseMatrix)
244298
end
245299

246300

301+
302+
303+
247304
"""
248305
$(SIGNATURES)
249306
250307
[`flush!`](@ref) and return colptr of in ext.cscmatrix.
251308
"""
252309
function SparseArrays.getcolptr(ext::ExtendableSparseMatrix)
253-
@inbounds flush!(ext)
310+
flush!(ext)
254311
return ext.cscmatrix.colptr
255312
end
256313

@@ -261,7 +318,7 @@ $(SIGNATURES)
261318
[`flush!`](@ref) and return findnz(ext.cscmatrix).
262319
"""
263320
function SparseArrays.findnz(ext::ExtendableSparseMatrix)
264-
@inbounds flush!(ext)
321+
flush!(ext)
265322
return findnz(ext.cscmatrix)
266323
end
267324

@@ -334,7 +391,7 @@ $(SIGNATURES)
334391
[`flush!`](@ref) and ldiv with ext.cscmatrix
335392
"""
336393
function LinearAlgebra.ldiv!(r, ext::ExtendableSparse.ExtendableSparseMatrix, x)
337-
@inbounds flush!(ext)
394+
flush!(ext)
338395
return LinearAlgebra.ldiv!(r,ext.cscmatrix,x)
339396
end
340397

@@ -344,7 +401,7 @@ $(SIGNATURES)
344401
[`flush!`](@ref) and multiply with ext.cscmatrix
345402
"""
346403
function LinearAlgebra.mul!(r,ext::ExtendableSparse.ExtendableSparseMatrix, x)
347-
@inbounds flush!(ext)
404+
flush!(ext)
348405
return LinearAlgebra.mul!(r,ext.cscmatrix,x)
349406
end
350407

@@ -355,7 +412,7 @@ $(SIGNATURES)
355412
[`flush!`](@ref) and calculate norm from cscmatrix
356413
"""
357414
function LinearAlgebra.norm(A::ExtendableSparseMatrix, p::Real=2)
358-
@inbounds flush!(A)
415+
flush!(A)
359416
return LinearAlgebra.norm(A.cscmatrix,p)
360417
end
361418

@@ -365,7 +422,7 @@ $(SIGNATURES)
365422
[`flush!`](@ref) and calculate opnorm from cscmatrix
366423
"""
367424
function LinearAlgebra.opnorm(A::ExtendableSparseMatrix, p::Real=2)
368-
@inbounds flush!(A)
425+
flush!(A)
369426
return LinearAlgebra.opnorm(A.cscmatrix,p)
370427
end
371428

@@ -375,7 +432,7 @@ $(SIGNATURES)
375432
[`flush!`](@ref) and calculate cond from cscmatrix
376433
"""
377434
function LinearAlgebra.cond(A::ExtendableSparseMatrix, p::Real=2)
378-
@inbounds flush!(A)
435+
flush!(A)
379436
return LinearAlgebra.cond(A.cscmatrix,p)
380437
end
381438

@@ -385,7 +442,7 @@ $(SIGNATURES)
385442
[`flush!`](@ref) and check for symmetry of cscmatrix
386443
"""
387444
function LinearAlgebra.issymmetric(A::ExtendableSparseMatrix)
388-
@inbounds flush!(A)
445+
flush!(A)
389446
return LinearAlgebra.issymmetric(A.cscmatrix)
390447
end
391448

@@ -397,17 +454,53 @@ $(SIGNATURES)
397454
Add SparseMatrixCSC matrix and [`ExtendableSparseMatrix`](@ref) ext.
398455
"""
399456
function Base.:+(ext::ExtendableSparseMatrix,csc::SparseMatrixCSC)
400-
@inbounds flush!(ext)
457+
flush!(ext)
401458
return ext.cscmatrix+csc
402459
end
403460

461+
function Base.:+(A::ExtendableSparseMatrix,B::ExtendableSparseMatrix)
462+
flush!(A)
463+
flush!(B)
464+
return ExtendableSparseMatrix(A.cscmatrix+B.cscmatrix)
465+
end
466+
467+
function Base.:-(A::ExtendableSparseMatrix,B::ExtendableSparseMatrix)
468+
flush!(A)
469+
flush!(B)
470+
return ExtendableSparseMatrix(A.cscmatrix-B.cscmatrix)
471+
end
472+
473+
474+
function Base.:*(A::ExtendableSparseMatrix,B::ExtendableSparseMatrix)
475+
flush!(A)
476+
flush!(B)
477+
return ExtendableSparseMatrix(A.cscmatrix*B.cscmatrix)
478+
end
479+
480+
"""
481+
$(SIGNATURES)
482+
"""
483+
function Base.:*(d::Diagonal,ext::ExtendableSparseMatrix)
484+
flush!(ext)
485+
return ExtendableSparseMatrix(d*ext.cscmatrix)
486+
end
487+
488+
"""
489+
$(SIGNATURES)
490+
"""
491+
function Base.:*(ext::ExtendableSparseMatrix,d::Diagonal)
492+
flush!(ext)
493+
return ExtendableSparseMatrix(ext.cscmatrix*d)
494+
end
495+
496+
404497
"""
405498
$(SIGNATURES)
406499
407500
Subtract SparseMatrixCSC matrix from [`ExtendableSparseMatrix`](@ref) ext.
408501
"""
409502
function Base.:-(ext::ExtendableSparseMatrix,csc::SparseMatrixCSC)
410-
@inbounds flush!(ext)
503+
flush!(ext)
411504
return ext.cscmatrix-csc
412505
end
413506

@@ -417,7 +510,7 @@ $(SIGNATURES)
417510
Subtract [`ExtendableSparseMatrix`](@ref) ext from SparseMatrixCSC.
418511
"""
419512
function Base.:-(csc::SparseMatrixCSC,ext::ExtendableSparseMatrix)
420-
@inbounds flush!(ext)
513+
flush!(ext)
421514
return csc - ext.cscmatrix
422515
end
423516

@@ -426,17 +519,10 @@ end
426519
$(SIGNATURES)
427520
"""
428521
function SparseArrays.dropzeros!(ext::ExtendableSparseMatrix)
429-
@inbounds flush!(ext)
522+
flush!(ext)
430523
dropzeros!(ext.cscmatrix)
431524
end
432525

433-
"""
434-
$(SIGNATURES)
435-
"""
436-
function Base.:*(d::Diagonal,ext::ExtendableSparseMatrix)
437-
@inbounds flush!(ext)
438-
return ExtendableSparseMatrix(d*ext.cscmatrix)
439-
end
440526

441527
"""
442528
$(SIGNATURES)

src/factorizations.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ and provide a method
1616
The idea is that, depending if the matrix pattern has changed,
1717
different steps are needed to update the preconditioner.
1818
19-
Moreover, they have the ExtendableSparseMatrix as a field, ensuring
19+
Moreover, they have the ExtendableSparseMatrix `A` as a field and an `update!` method, ensuring
2020
consistency after construction.
2121
"""
2222
abstract type AbstractFactorization{Tv, Ti} end
@@ -146,15 +146,16 @@ end
146146

147147
include("jacobi.jl")
148148
include("ilu0.jl")
149+
include("iluzero.jl")
149150
include("parallel_jacobi.jl")
150151
include("parallel_ilu0.jl")
151152

152153
include("SparspakCSCInterface.jl")
153154
include("sparspak.jl")
154155

155156
@eval begin
156-
157157
@makefrommatrix ILU0Preconditioner
158+
@makefrommatrix ILUZeroPreconditioner
158159
@makefrommatrix JacobiPreconditioner
159160
@makefrommatrix ParallelJacobiPreconditioner
160161
@makefrommatrix ParallelILU0Preconditioner

0 commit comments

Comments
 (0)