Skip to content

Commit c98c087

Browse files
committed
Add LinearAlgebra.lu etc. for ExtendableSparse
1 parent ab48e5d commit c98c087

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

src/extendable.jl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,25 +270,22 @@ if USE_GPL_LIBS
270270

271271
for (Tv) in (:Float64,:ComplexF64)
272272
@eval begin
273-
"""
274-
$(TYPEDSIGNATURES)
275-
276-
[`\\`](@ref) for ExtendableSparse for $($Tv)
277-
"""
278273
function LinearAlgebra.:\(ext::ExtendableSparseMatrix{$Tv,Ti}, B::AbstractVecOrMat{$Tv}) where Ti
279274
flush!(ext)
280275
ext.cscmatrix\B
281276
end
282277
end
283278
end
284-
279+
285280
end # USE_GPL_LIBS
286281

287282

288283
"""
289-
$(TYPEDSIGNATURES)
284+
A\b
290285
291-
[`\\`](@ref) for ExtendableSparse for generic floating point. This calls Sparspak.jl.
286+
[`\\`](@ref) for ExtendableSparse. It calls the LU factorization form Sparspak.jl, unless GPL components
287+
are allowed in the Julia sysimage and the floating point type of the matrix is Float64 or Complex64.
288+
In that case, Julias standard `\` is called, which is realized via UMFPACK.
292289
"""
293290
function LinearAlgebra.:\(ext::ExtendableSparseMatrix{Tv,Ti}, b::AbstractVector{Tv}) where {Tv,Ti}
294291
flush!(ext)

src/factorizations.jl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,29 @@ If `nothing` is passed as first parameter, [`factorize`](@ref) is called.
8080
"""
8181
LinearAlgebra.lu!(lufact::AbstractFactorization, A::ExtendableSparseMatrix)=factorize!(lufact,A)
8282

83-
LinearAlgebra.lu(A::ExtendableSparseMatrix)=factorize!(LUFactorization(),A)
83+
84+
85+
"""
86+
```
87+
lu(matrix)
88+
```
89+
90+
Create LU factorization. It calls the LU factorization form Sparspak.jl, unless GPL components
91+
are allowed in the Julia sysimage and the floating point type of the matrix is Float64 or Complex64.
92+
In that case, Julias standard `lu` is called, which is realized via UMFPACK.
93+
"""
94+
LinearAlgebra.lu(A::ExtendableSparseMatrix{Tv,Ti}) where {Tv, Ti} =factorize!(SparspakLU{Tv,Ti}(),A)
95+
96+
if USE_GPL_LIBS
97+
98+
for (Tv) in (:Float64,:ComplexF64)
99+
@eval begin
100+
LinearAlgebra.lu(A::ExtendableSparseMatrix{$Tv,Ti}) where Ti =factorize!(LUFactorization{$Tv,Ti}(),A)
101+
end
102+
end
103+
104+
end # USE_GPL_LIBS
105+
84106

85107

86108
"""

src/ilu0.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function update!(precon::ILU0Preconditioner{Tv,Ti}) where {Tv,Ti}
7171
end
7272

7373

74-
function LinearAlgebra.ldiv!(u::AbstractArray{T,1}, precon::ILU0Preconditioner, v::AbstractArray{T,1}) where T
74+
function LinearAlgebra.ldiv!(u::AbstractArray{T,1}, precon::ILU0Preconditioner{Tv,Ti}, v::AbstractArray{T,1}) where {T,Tv,Ti}
7575
cscmatrix=precon.A.cscmatrix
7676
colptr=cscmatrix.colptr
7777
rowval=cscmatrix.rowval
@@ -81,15 +81,15 @@ function LinearAlgebra.ldiv!(u::AbstractArray{T,1}, precon::ILU0Preconditioner,
8181
idiag=precon.idiag
8282

8383
@inbounds for j=1:n
84-
x=zero(T)
84+
x=zero(Tv)
8585
@inbounds for k=colptr[j]:idiag[j]-1
8686
x+=nzval[k]*u[rowval[k]]
8787
end
8888
u[j]=xdiag[j]*(v[j]-x)
8989
end
9090

9191
@inbounds for j=n:-1:1
92-
x=zero(T)
92+
x=zero(Tv)
9393
@inbounds for k=idiag[j]+1:colptr[j+1]-1
9494
x+=u[rowval[k]]*nzval[k]
9595
end

0 commit comments

Comments
 (0)