Skip to content

Commit 64128cd

Browse files
committed
Added linear algbra methods
1 parent d6e2e22 commit 64128cd

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

src/extendable.jl

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,27 +324,51 @@ end
324324
"""
325325
$(TYPEDSIGNATURES)
326326
327-
Drop in replacement for LU factorization.
328-
327+
Delegating LU factorization.
329328
"""
330329
function LinearAlgebra.lu(E::ExtendableSparseMatrix)
331330
@inbounds flush!(E)
332331
return LinearAlgebra.lu(E.cscmatrix)
333332
end
334333

334+
"""
335+
$(SIGNATURES)
335336
337+
Delegating Matrix multiplication
338+
"""
339+
function LinearAlgebra.mul!(r::AbstractArray{T,1} where T, E::ExtendableSparse.ExtendableSparseMatrix, x::AbstractArray{T,1} where T)
340+
@inbounds flush!(E)
341+
return LinearAlgebra.mul!(r,E.cscmatrix,x)
342+
end
336343

337344

338345
"""
339346
$(SIGNATURES)
340347
341-
Flush and delegate to cscmatrix.
348+
Delegating Matrix ldiv
342349
"""
343-
function LinearAlgebra.mul!(r::AbstractArray{Tv,1},
344-
E::ExtendableSparse.ExtendableSparseMatrix{Tv,Ti},
345-
x::AbstractArray{Tv,1}) where{Tv,Ti<:Integer}
350+
function LinearAlgebra.ldiv!(r::AbstractArray{T,1} where T, E::ExtendableSparse.ExtendableSparseMatrix, x::AbstractArray{T,1} where T)
351+
@inbounds flush!(E)
352+
return LinearAlgebra.ldiv!(r,E.cscmatrix,x)
353+
end
354+
355+
"""
356+
$(SIGNATURES)
357+
358+
Delegating Matrix multiplication
359+
"""
360+
function LinearAlgebra.mul!(r::AbstractArray{T,2} where T, E::ExtendableSparse.ExtendableSparseMatrix, x::AbstractArray{T,2} where T)
346361
@inbounds flush!(E)
347362
return LinearAlgebra.mul!(r,E.cscmatrix,x)
348363
end
349364

350365

366+
"""
367+
$(SIGNATURES)
368+
369+
Delegating Matrix ldiv
370+
"""
371+
function LinearAlgebra.ldiv!(r::AbstractArray{T,2} where T, E::ExtendableSparse.ExtendableSparseMatrix, x::AbstractArray{T,2} where T)
372+
@inbounds flush!(E)
373+
return LinearAlgebra.ldiv!(r,E.cscmatrix,x)
374+
end

test/ExtendableSparseTest.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,24 @@ function constructors()
7878

7979
true
8080
end
81+
82+
83+
function optest(n)
84+
println("optest:")
85+
A=ExtendableSparseMatrix(n,n)
86+
nrow=min(div(n,4),5)
87+
@time for i=1:n
88+
A[i,i]=2*n
89+
for k=1:nrow
90+
j=rand((1:n))
91+
if i!=j
92+
A[i,j]=-rand()
93+
end
94+
end
95+
end
96+
b=rand(n)
97+
@time x=A\b
98+
Ax=A*x
99+
b Ax
100+
end
81101
end

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@ include("ExtendableSparseTest.jl")
2929
@test ExtendableSparseTest.check(m=m,n=n,nnz=nnz,nsplice=nsplice)
3030
end
3131

32-
32+
@test ExtendableSparseTest.optest(10)
33+
@test ExtendableSparseTest.optest(100)
34+
@test ExtendableSparseTest.optest(1000)
3335
end

0 commit comments

Comments
 (0)