Skip to content

Commit 287c6c6

Browse files
authored
Adjust to [Adjoint/Transpose]Factorization (#269)
1 parent 15134f3 commit 287c6c6

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

src/SparseArrays.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ decrement(A::AbstractArray) = let y = Array(A)
5757
y .= y .- oneunit(eltype(A))
5858
end
5959

60+
AdjType = isdefined(LinearAlgebra, :AdjointFactorization) ?
61+
LinearAlgebra.AdjointFactorization :
62+
Adjoint
63+
TransType = isdefined(LinearAlgebra, :TransposeFactorization) ?
64+
LinearAlgebra.TransposeFactorization :
65+
Transpose
66+
6067
include("readonly.jl")
6168
include("abstractsparse.jl")
6269
include("sparsematrix.jl")

src/solvers/cholmod.jl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export
3030

3131
import SparseArrays: AbstractSparseMatrix, SparseMatrixCSC, indtype, sparse, spzeros, nnz
3232

33-
import ..increment, ..increment!
33+
import ..increment, ..increment!, ..AdjType, ..TransType
3434

3535
using ..LibSuiteSparse
3636
import ..LibSuiteSparse: SuiteSparse_long, TRUE, FALSE
@@ -334,9 +334,10 @@ mutable struct Factor{Tv<:VTypes} <: Factorization{Tv}
334334
end
335335
end
336336

337-
Base.adjoint(F::Factor) = Adjoint(F)
338-
Base.transpose(F::Factor) = Transpose(F)
339-
337+
if !isdefined(LinearAlgebra, :AdjointFactorization)
338+
Base.adjoint(F::Factor) = Adjoint(F)
339+
Base.transpose(F::Factor) = Transpose(F)
340+
end
340341

341342
const SuiteSparseStruct = Union{cholmod_dense, cholmod_sparse, cholmod_factor}
342343

@@ -1554,15 +1555,15 @@ end
15541555
(\)(L::Factor, B::Transpose{<:Any,<:SparseMatrixCSC}) = L \ copy(B)
15551556
(\)(L::Factor, B::SparseVector) = sparse(spsolve(CHOLMOD_A, L, Sparse(B)))
15561557

1557-
\(adjL::Adjoint{<:Any,<:Factor}, B::Dense) = (L = adjL.parent; solve(CHOLMOD_A, L, B))
1558-
\(adjL::Adjoint{<:Any,<:Factor}, B::Sparse) = (L = adjL.parent; spsolve(CHOLMOD_A, L, B))
1559-
\(adjL::Adjoint{<:Any,<:Factor}, B::SparseVecOrMat) = (L = adjL.parent; \(adjoint(L), Sparse(B)))
1558+
\(adjL::AdjType{<:Any,<:Factor}, B::Dense) = (L = adjL.parent; solve(CHOLMOD_A, L, B))
1559+
\(adjL::AdjType{<:Any,<:Factor}, B::Sparse) = (L = adjL.parent; spsolve(CHOLMOD_A, L, B))
1560+
\(adjL::AdjType{<:Any,<:Factor}, B::SparseVecOrMat) = (L = adjL.parent; \(adjoint(L), Sparse(B)))
15601561

1561-
function \(adjL::Adjoint{<:Any,<:Factor}, b::StridedVector)
1562+
function \(adjL::AdjType{<:Any,<:Factor}, b::StridedVector)
15621563
L = adjL.parent
15631564
return Vector(solve(CHOLMOD_A, L, Dense(b)))
15641565
end
1565-
function \(adjL::Adjoint{<:Any,<:Factor}, B::StridedMatrix)
1566+
function \(adjL::AdjType{<:Any,<:Factor}, B::StridedMatrix)
15661567
L = adjL.parent
15671568
return Matrix(solve(CHOLMOD_A, L, Dense(B)))
15681569
end

src/solvers/umfpack.jl

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import SparseArrays: nnz
1515
import Serialization: AbstractSerializer, deserialize, serialize
1616
using Serialization
1717

18-
import ..increment, ..increment!, ..decrement, ..decrement!
18+
import ..increment, ..increment!, ..decrement, ..decrement!, ..AdjType, ..TransType
1919

2020
using ..LibSuiteSparse
2121
import ..LibSuiteSparse:
@@ -255,7 +255,7 @@ workspace_W_size(F::UmfpackLU) = workspace_W_size(F, has_refinement(F))
255255
workspace_W_size(S::Union{UmfpackLU{<:AbstractFloat}, AbstractSparseMatrixCSC{<:AbstractFloat}}, refinement::Bool) = refinement ? 5 * size(S, 2) : size(S, 2)
256256
workspace_W_size(S::Union{UmfpackLU{<:Complex}, AbstractSparseMatrixCSC{<:Complex}}, refinement::Bool) = refinement ? 10 * size(S, 2) : 4 * size(S, 2)
257257

258-
const ATLU = Union{Transpose{<:Any, <:UmfpackLU}, Adjoint{<:Any, <:UmfpackLU}}
258+
const ATLU = Union{TransType{<:Any, <:UmfpackLU}, AdjType{<:Any, <:UmfpackLU}}
259259
has_refinement(F::ATLU) = has_refinement(F.parent)
260260
has_refinement(F::UmfpackLU) = has_refinement(F.control)
261261
has_refinement(control::AbstractVector) = control[JL_UMFPACK_IRSTEP] > 0
@@ -293,8 +293,10 @@ Base.copy(F::UmfpackLU{Tv, Ti}, ws=UmfpackWS(F)) where {Tv, Ti} =
293293
Base.copy(F::T, ws=UmfpackWS(F)) where {T <: ATLU} =
294294
T(copy(parent(F), ws))
295295

296-
Base.adjoint(F::UmfpackLU) = Adjoint(F)
297-
Base.transpose(F::UmfpackLU) = Transpose(F)
296+
if !isdefined(LinearAlgebra, :AdjointFactorization)
297+
Base.adjoint(F::UmfpackLU) = Adjoint(F)
298+
Base.transpose(F::UmfpackLU) = Transpose(F)
299+
end
298300

299301
function Base.lock(f::Function, F::UmfpackLU)
300302
lock(F)
@@ -936,28 +938,28 @@ import LinearAlgebra.ldiv!
936938

937939
ldiv!(lu::UmfpackLU{T}, B::StridedVecOrMat{T}) where {T<:UMFVTypes} =
938940
ldiv!(B, lu, copy(B))
939-
ldiv!(translu::Transpose{T,<:UmfpackLU{T}}, B::StridedVecOrMat{T}) where {T<:UMFVTypes} =
940-
(lu = translu.parent; ldiv!(B, transpose(lu), copy(B)))
941-
ldiv!(adjlu::Adjoint{T,<:UmfpackLU{T}}, B::StridedVecOrMat{T}) where {T<:UMFVTypes} =
942-
(lu = adjlu.parent; ldiv!(B, adjoint(lu), copy(B)))
941+
ldiv!(translu::TransType{T,<:UmfpackLU{T}}, B::StridedVecOrMat{T}) where {T<:UMFVTypes} =
942+
ldiv!(B, translu, copy(B))
943+
ldiv!(adjlu::AdjType{T,<:UmfpackLU{T}}, B::StridedVecOrMat{T}) where {T<:UMFVTypes} =
944+
ldiv!(B, adjlu, copy(B))
943945
ldiv!(lu::UmfpackLU{Float64}, B::StridedVecOrMat{<:Complex}) =
944946
ldiv!(B, lu, copy(B))
945-
ldiv!(translu::Transpose{Float64,<:UmfpackLU{Float64}}, B::StridedVecOrMat{<:Complex}) =
946-
(lu = translu.parent; ldiv!(B, transpose(lu), copy(B)))
947-
ldiv!(adjlu::Adjoint{Float64,<:UmfpackLU{Float64}}, B::StridedVecOrMat{<:Complex}) =
948-
(lu = adjlu.parent; ldiv!(B, adjoint(lu), copy(B)))
947+
ldiv!(translu::TransType{Float64,<:UmfpackLU{Float64}}, B::StridedVecOrMat{<:Complex}) =
948+
ldiv!(B, translu, copy(B))
949+
ldiv!(adjlu::AdjType{Float64,<:UmfpackLU{Float64}}, B::StridedVecOrMat{<:Complex}) =
950+
ldiv!(B, adjlu, copy(B))
949951

950952
ldiv!(X::StridedVecOrMat{T}, lu::UmfpackLU{T}, B::StridedVecOrMat{T}) where {T<:UMFVTypes} =
951953
_Aq_ldiv_B!(X, lu, B, UMFPACK_A)
952-
ldiv!(X::StridedVecOrMat{T}, translu::Transpose{T,<:UmfpackLU{T}}, B::StridedVecOrMat{T}) where {T<:UMFVTypes} =
954+
ldiv!(X::StridedVecOrMat{T}, translu::TransType{T,<:UmfpackLU{T}}, B::StridedVecOrMat{T}) where {T<:UMFVTypes} =
953955
(lu = translu.parent; _Aq_ldiv_B!(X, lu, B, UMFPACK_Aat))
954-
ldiv!(X::StridedVecOrMat{T}, adjlu::Adjoint{T,<:UmfpackLU{T}}, B::StridedVecOrMat{T}) where {T<:UMFVTypes} =
956+
ldiv!(X::StridedVecOrMat{T}, adjlu::AdjType{T,<:UmfpackLU{T}}, B::StridedVecOrMat{T}) where {T<:UMFVTypes} =
955957
(lu = adjlu.parent; _Aq_ldiv_B!(X, lu, B, UMFPACK_At))
956958
ldiv!(X::StridedVecOrMat{Tb}, lu::UmfpackLU{Float64}, B::StridedVecOrMat{Tb}) where {Tb<:Complex} =
957959
_Aq_ldiv_B!(X, lu, B, UMFPACK_A)
958-
ldiv!(X::StridedVecOrMat{Tb}, translu::Transpose{Float64,<:UmfpackLU{Float64}}, B::StridedVecOrMat{Tb}) where {Tb<:Complex} =
960+
ldiv!(X::StridedVecOrMat{Tb}, translu::TransType{Float64,<:UmfpackLU{Float64}}, B::StridedVecOrMat{Tb}) where {Tb<:Complex} =
959961
(lu = translu.parent; _Aq_ldiv_B!(X, lu, B, UMFPACK_Aat))
960-
ldiv!(X::StridedVecOrMat{Tb}, adjlu::Adjoint{Float64,<:UmfpackLU{Float64}}, B::StridedVecOrMat{Tb}) where {Tb<:Complex} =
962+
ldiv!(X::StridedVecOrMat{Tb}, adjlu::AdjType{Float64,<:UmfpackLU{Float64}}, B::StridedVecOrMat{Tb}) where {Tb<:Complex} =
961963
(lu = adjlu.parent; _Aq_ldiv_B!(X, lu, B, UMFPACK_At))
962964

963965
function _Aq_ldiv_B!(X::StridedVecOrMat, lu::UmfpackLU, B::StridedVecOrMat, transposeoptype)

0 commit comments

Comments
 (0)