Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always use Matrix X for CR #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
79 changes: 20 additions & 59 deletions src/cyclic_reduction.jl
Original file line number Diff line number Diff line change
@@ -1,67 +1,28 @@
using LinearAlgebra.BLAS: gemm!

if VERSION < v"1.9.0-"
@show VERSION
@eval begin
"""
CRSolverWs

Workspace used for solving with the cyclic reduction algorithm of [Bini et al.](https://link.springer.com/article/10.1007/s11075-008-9253-0).
"""
mutable struct CRSolverWs{T, WS} <: Workspace
linsolve_ws::WS
ahat1::Matrix{T}
a1copy::Matrix{T}
x::Matrix{T}
m::Matrix{T}
m1::Matrix{T}
m2::Matrix{T}
end

function CRSolverWs(a0::AbstractMatrix{T}) where {T<:AbstractFloat}
n = size(a0,1)
linsolve_ws = LUWs(n)
ahat1 = Matrix{T}(undef, n,n)
a1copy = Matrix{T}(undef, n,n)
m = Matrix{T}(undef, 2*n,2*n)
m1 = Matrix{T}(undef, n, 2*n)
m2 = Matrix{T}(undef, 2*n, n)
x = Matrix{T}(undef, n,n)
CRSolverWs(linsolve_ws, ahat1, a1copy, x, m, m1, m2)
end

end
@show methods(CRSolverWs)
else

@eval begin
"""
CRSolverWs
mutable struct CRSolverWs{T, WS} <: Workspace
linsolve_ws::WS
ahat1::Matrix{T}
a1copy::Matrix{T}
x::Matrix{T}
m::Matrix{T}
m1::Matrix{T}
m2::Matrix{T}
end

Workspace used for solving with the cyclic reduction algorithm of [Bini et al.](https://link.springer.com/article/10.1007/s11075-008-9253-0).
"""
mutable struct CRSolverWs{T, WS, MT<:AbstractMatrix{T}} <: Workspace
linsolve_ws::WS
ahat1::Matrix{T}
a1copy::Matrix{T}
x::MT
m::Matrix{T}
m1::Matrix{T}
m2::Matrix{T}
end

function CRSolverWs(a0::AbstractMatrix{T}) where {T<:AbstractFloat}
n = size(a0,1)
linsolve_ws = LUWs(n)
ahat1 = Matrix{T}(undef, n,n)
a1copy = Matrix{T}(undef, n,n)
m = Matrix{T}(undef, 2*n,2*n)
m1 = Matrix{T}(undef, n, 2*n)
m2 = Matrix{T}(undef, 2*n, n)
CRSolverWs(linsolve_ws, ahat1, a1copy, similar(a0), m, m1, m2)
end
end

function CRSolverWs(a0::AbstractMatrix{T}) where {T<:AbstractFloat}
n = size(a0,1)
linsolve_ws = LUWs(n)
ahat1 = Matrix{T}(undef, n,n)
a1copy = Matrix{T}(undef, n,n)
m = Matrix{T}(undef, 2*n,2*n)
m1 = Matrix{T}(undef, n, 2*n)
m2 = Matrix{T}(undef, 2*n, n)
x = Matrix{T}(undef, n,n)
CRSolverWs(linsolve_ws, ahat1, a1copy, x, m, m1, m2)
end

function solve!(ws::CRSolverWs{T}, a0::Matrix{T}, a1::Matrix{T}, a2::Matrix{T};
Expand Down Expand Up @@ -324,7 +285,7 @@ function solve!(ws::CRSolverWs, a0::SparseMatrixCSC, a1_::AbstractMatrix, a2::Sp
lu_t = LU(factorize!(ws.linsolve_ws, ws.ahat1)...)
ldiv!(lu_t, x)
@inbounds lmul!(-1.0, x)
return x
return sparse(x)
end

function check_convergence!(x, it, crit1, crit2, m1, tolerance, max_iterations)
Expand Down