Skip to content

Commit a94d5f8

Browse files
Merge pull request #104 from oscardssmith/use-triangular-solve-for-butterfly
Use TriangularSolve for Butterfly factorization
2 parents 7d78703 + db248e9 commit a94d5f8

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/butterflylu.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,33 @@ struct 🦋workspace{T}
2424
U::Matrix{T}
2525
V::Matrix{T}
2626
out::Vector{T}
27+
tmp::Vector{T}
28+
n::Int
2729
function 🦋workspace(A, b, ::Val{SEED} = Val(888)) where {SEED}
28-
M = size(A, 1)
29-
out = similar(b, M)
30-
if (M % 4 != 0)
30+
n = size(A, 1)
31+
out = similar(b)
32+
if (n % 4 != 0)
3133
A = pad!(A)
32-
xn = 4 - M % 4
34+
xn = 4 - n % 4
3335
b = [b; rand(xn)]
3436
end
37+
tmp = similar(b)
3538
U, V = (similar(A), similar(A))
3639
ws = 🦋generate_random!(A)
3740
materializeUV(U, V, ws)
38-
new{eltype(A)}(A, b, ws, U, V, out)
41+
new{eltype(A)}(A, b, ws, U, V, out, tmp, n)
3942
end
4043
end
4144

42-
function 🦋lu!(workspace::🦋workspace, M, thread)
43-
(;A, b, ws, U, V, out) = workspace
45+
function 🦋solve!(workspace::🦋workspace, thread)
46+
(;A, b, ws, U, V, out, tmp, n) = workspace
4447
🦋mul!(A, ws)
4548
F = RecursiveFactorization.lu!(A, Val(false), thread)
46-
sol = V * (F \ (U' * b))
47-
out .= @view sol[1:M]
49+
50+
mul!(tmp, U', b)
51+
ldiv!(F, tmp, thread)
52+
mul!(b, V, tmp)
53+
out .= @view b[1:n]
4854
out
4955
end
5056

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ end
8181
for i in 790 : 810
8282
A = wilkinson(i)
8383
b = rand(i)
84-
ws = RecursiveFactorization.🦋workspace(copy(A), copy(b))
85-
out = RecursiveFactorization.🦋lu!(ws, i, Val(true))
84+
ws = RecursiveFactorization.🦋workspace(copy(A), copy(b))
85+
out = RecursiveFactorization.🦋solve!(ws, Val(true))
8686
@test norm(A * out .- b) <= 1e-10
8787
end
8888
end

0 commit comments

Comments
 (0)