Skip to content

Commit d1d3267

Browse files
authored
Merge pull request #38 from fverdugo/lu_support
adding lu support for PSparseMatrix (just for testing purposes)
2 parents 20bc5e9 + 92dbeca commit d1d3267

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/Interfaces.jl

+24
Original file line numberDiff line numberDiff line change
@@ -2451,6 +2451,30 @@ function Base.:\(a::PSparseMatrix{Ta},b::PVector{Tb}) where {Ta,Tb}
24512451
c
24522452
end
24532453

2454+
# Not efficient, just for convenience and debugging purposes
2455+
struct PLU{A,B,C}
2456+
lu_in_main::A
2457+
rows::B
2458+
cols::C
2459+
end
2460+
function LinearAlgebra.lu(a::PSparseMatrix)
2461+
a_in_main = gather(a)
2462+
lu_in_main = map_main(lu,a_in_main.values)
2463+
PLU(lu_in_main,a_in_main.rows,a_in_main.cols)
2464+
end
2465+
function LinearAlgebra.lu!(b::PLU,a::PSparseMatrix)
2466+
a_in_main = gather(a,b.rows,b.cols)
2467+
map_main(lu!,b.lu_in_main,a_in_main.values)
2468+
b
2469+
end
2470+
function LinearAlgebra.ldiv!(c::PVector,a::PLU,b::PVector)
2471+
b_in_main = gather(b,a.rows)
2472+
c_in_main = gather(c,a.cols)
2473+
map_main(ldiv!,c_in_main.values,a.lu_in_main,b_in_main.values)
2474+
scatter!(c,c_in_main)
2475+
c
2476+
end
2477+
24542478
function gather(
24552479
a::PSparseMatrix{Ta},
24562480
rows_in_main::PRange=_to_main(a.rows),

test/test_interfaces.jl

+13
Original file line numberDiff line numberDiff line change
@@ -658,4 +658,17 @@ function test_interfaces(parts)
658658
to_gids!(J,A.cols)
659659
exchange!(I,J,V,A.cols)
660660

661+
factors = lu(A)
662+
x .= 0
663+
ldiv!(x,factors,y)
664+
r = A*x-y
665+
@test norm(r) < 1.0e-9
666+
667+
lu!(factors,A)
668+
x .= 0
669+
ldiv!(x,factors,y)
670+
r = A*x-y
671+
@test norm(r) < 1.0e-9
672+
673+
661674
end

0 commit comments

Comments
 (0)