Skip to content

Commit 2e3a53b

Browse files
committed
Add LinearAlgebra.:\ for Symmetric{ExtendableSparse} and Hermitian{ExtendableSparse}
1 parent 27f3267 commit 2e3a53b

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

Project.toml

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

66
[deps]
77
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"

src/extendable.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ function Base.show(io::IO,::MIME"text/plain",ext::ExtendableSparseMatrix)
178178
end
179179

180180

181+
181182
"""
182183
$(SIGNATURES)
183184
@@ -283,6 +284,32 @@ function LinearAlgebra.:\(ext::ExtendableSparseMatrix,X::Union{AbstractArray{T,1
283284
end
284285

285286

287+
"""
288+
$(SIGNATURES)
289+
290+
[`\\`](@ref) for Symmetric{ExtenableSparse}
291+
"""
292+
function LinearAlgebra.:\(symm_ext::Symmetric{Tm, ExtendableSparseMatrix{Tm, Ti}}, B::Union{AbstractArray{T,1}, AbstractArray{T,2}} where T) where{Tm,Ti}
293+
flush!(symm_ext.data)
294+
symm_csc=Symmetric(symm_ext.data.cscmatrix,Symbol(symm_ext.uplo))
295+
symm_csc\B
296+
end
297+
298+
299+
"""
300+
$(SIGNATURES)
301+
302+
[`\\`](@ref) for Hermitian{ExtenableSparse}
303+
"""
304+
function LinearAlgebra.:\(symm_ext::Hermitian{Tm, ExtendableSparseMatrix{Tm, Ti}}, B::Union{AbstractArray{T,1}, AbstractArray{T,2}} where T) where{Tm,Ti}
305+
flush!(symm_ext.data)
306+
symm_csc=Hermitian(symm_ext.data.cscmatrix,Symbol(symm_ext.uplo))
307+
symm_csc\B
308+
end
309+
310+
311+
312+
286313
"""
287314
$(SIGNATURES)
288315

test/runtests.jl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,47 @@ end
177177
@test all(isapprox.(test_precon(ParallelJacobiPreconditioner,20,20,20), (true, 2.0406032775945658e-5), rtol=1.0e-5))
178178
end
179179

180+
181+
182+
function test_symmetric(n,uplo)
183+
A=ExtendableSparseMatrix(n,n)
184+
sprand_sdd!(A)
185+
b=rand(n)
186+
flush!(A)
187+
SA=Symmetric(A,uplo)
188+
Scsc=Symmetric(A.cscmatrix,uplo)
189+
SA\b Scsc\b
190+
end
191+
192+
193+
194+
@testset "symmetric" begin
195+
@test test_symmetric(3,:U)
196+
@test test_symmetric(3,:L)
197+
@test test_symmetric(30,:U)
198+
@test test_symmetric(30,:L)
199+
@test test_symmetric(300,:U)
200+
@test test_symmetric(300,:L)
201+
end
202+
203+
204+
205+
function test_hermitian(n,uplo)
206+
A=ExtendableSparseMatrix{ComplexF64,Int64}(n,n)
207+
sprand_sdd!(A)
208+
flush!(A)
209+
A.cscmatrix.nzval.=(1.0+0.01im)*A.cscmatrix.nzval
210+
b=rand(n)
211+
HA=Hermitian(A,uplo)
212+
Hcsc=Hermitian(A.cscmatrix,uplo)
213+
HA\b Hcsc\b
214+
end
215+
216+
@testset "hermitian" begin
217+
@test test_hermitian(3,:U)
218+
@test test_hermitian(3,:L)
219+
@test test_hermitian(30,:U)
220+
@test test_hermitian(30,:L)
221+
@test test_hermitian(300,:U)
222+
@test test_hermitian(300,:L)
223+
end

0 commit comments

Comments
 (0)