From fccec1071eda25cecc14ecd307540d3d32997c9c Mon Sep 17 00:00:00 2001 From: oscarddssmith Date: Thu, 9 Oct 2025 13:11:09 -0400 Subject: [PATCH 1/4] Use TriangularSolve for Butterfly factorization --- src/butterflylu.jl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/butterflylu.jl b/src/butterflylu.jl index dd5f76d..223ece5 100644 --- a/src/butterflylu.jl +++ b/src/butterflylu.jl @@ -39,12 +39,16 @@ struct 🦋workspace{T} end end -function 🦋lu!(workspace::🦋workspace, M, thread) +function 🦋solve!(workspace::🦋workspace, M, thread) (;A, b, ws, U, V, out) = 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:M] out end From a657582d45088d8a4772dd049d2a608fc83a2890 Mon Sep 17 00:00:00 2001 From: oscarddssmith Date: Thu, 9 Oct 2025 15:36:24 -0400 Subject: [PATCH 2/4] fix test, interface --- src/butterflylu.jl | 13 +++++++------ test/runtests.jl | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/butterflylu.jl b/src/butterflylu.jl index 223ece5..e5198f0 100644 --- a/src/butterflylu.jl +++ b/src/butterflylu.jl @@ -24,9 +24,10 @@ 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) + N = size(A, 1) + out = similar(b, N) if (M % 4 != 0) A = pad!(A) xn = 4 - M % 4 @@ -35,12 +36,12 @@ struct 🦋workspace{T} 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 🦋solve!(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) @@ -48,7 +49,7 @@ function 🦋solve!(workspace::🦋workspace, M, thread) ldiv!(b, UnitLowerTriangular(F.factors), b, thread) ldiv!(b, UpperTriangular(F.factors), b, thread) mul!(b, V, b) - out .= @view b[1:M] + out .= @view b[1:N] out end diff --git a/test/runtests.jl b/test/runtests.jl index 9c3789e..8f6c2d4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 From 3686d1123772119fe03e05774fab08ddc0d0a6b7 Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Fri, 10 Oct 2025 09:48:21 -0400 Subject: [PATCH 3/4] typo --- src/butterflylu.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/butterflylu.jl b/src/butterflylu.jl index e5198f0..7087c86 100644 --- a/src/butterflylu.jl +++ b/src/butterflylu.jl @@ -26,7 +26,7 @@ struct 🦋workspace{T} out::Vector{T} n::Int function 🦋workspace(A, b, ::Val{SEED} = Val(888)) where {SEED} - N = size(A, 1) + len = size(A, 1) out = similar(b, N) if (M % 4 != 0) A = pad!(A) @@ -36,12 +36,12 @@ struct 🦋workspace{T} U, V = (similar(A), similar(A)) ws = 🦋generate_random!(A) materializeUV(U, V, ws) - new{eltype(A)}(A, b, ws, U, V, out, N) + new{eltype(A)}(A, b, ws, U, V, out, n) end end function 🦋solve!(workspace::🦋workspace, thread) - (;A, b, ws, U, V, out, N) = workspace + (;A, b, ws, U, V, out, n) = workspace 🦋mul!(A, ws) F = RecursiveFactorization.lu!(A, Val(false), thread) @@ -49,7 +49,7 @@ function 🦋solve!(workspace::🦋workspace, thread) ldiv!(b, UnitLowerTriangular(F.factors), b, thread) ldiv!(b, UpperTriangular(F.factors), b, thread) mul!(b, V, b) - out .= @view b[1:N] + out .= @view b[1:n] out end From 7b9037fb74018c68d58d70e7cfcf0eff225f7787 Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Fri, 10 Oct 2025 09:49:11 -0400 Subject: [PATCH 4/4] Update butterflylu.jl --- src/butterflylu.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/butterflylu.jl b/src/butterflylu.jl index 7087c86..6e5a691 100644 --- a/src/butterflylu.jl +++ b/src/butterflylu.jl @@ -26,11 +26,11 @@ struct 🦋workspace{T} out::Vector{T} n::Int function 🦋workspace(A, b, ::Val{SEED} = Val(888)) where {SEED} - len = size(A, 1) - out = similar(b, N) - 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))