Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/butterflylu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,32 @@ struct 🦋workspace{T}
U::Matrix{T}
V::Matrix{T}
out::Vector{T}
n::Int
function 🦋workspace(A, b, ::Val{SEED} = Val(888)) where {SEED}
M = size(A, 1)
out = similar(b, M)
if (M % 4 != 0)
n = size(A, 1)
out = similar(b, n)
if (n % 4 != 0)
A = pad!(A)
xn = 4 - M % 4
xn = 4 - n % 4
b = [b; rand(xn)]
end
U, V = (similar(A), similar(A))
ws = 🦋generate_random!(A)
materializeUV(U, V, ws)
new{eltype(A)}(A, b, ws, U, V, out)
new{eltype(A)}(A, b, ws, U, V, out, n)
end
end

function 🦋lu!(workspace::🦋workspace, M, thread)
(;A, b, ws, U, V, out) = workspace
function 🦋solve!(workspace::🦋workspace, thread)
(;A, b, ws, U, V, out, n) = workspace
🦋mul!(A, ws)
F = RecursiveFactorization.lu!(A, Val(false), thread)
sol = V * (F \ (U' * b))
out .= @view sol[1:M]

mul!(b, U', b)
ldiv!(b, UnitLowerTriangular(F.factors), b, thread)
ldiv!(b, UpperTriangular(F.factors), b, thread)
mul!(b, V, b)
out .= @view b[1:n]
out
end

Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ end
A = wilkinson(i)
b = rand(i)
ws = RecursiveFactorization.🦋workspace(copy(A), copy(b))
out = RecursiveFactorization.🦋lu!(ws, i, Val(true))
out = RecursiveFactorization.🦋solve!(ws, Val(true))
@test norm(A * out .- b) <= 1e-10
end
end
Expand Down
Loading