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

Prepare for AdjointFactorization, multiple dispatch #138

Merged
merged 2 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 9 additions & 7 deletions src/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ function DiagonalOperator(diag::AbstractVector; update_func=DEFAULT_UPDATE_FUNC)
end
LinearAlgebra.Diagonal(L::MatrixOperator) = MatrixOperator(Diagonal(L.A))

const AdjointFact = isdefined(LinearAlgebra, :AdjointFactorization) ? LinearAlgebra.AdjointFactorization : Adjoint
const TransposeFact = isdefined(LinearAlgebra, :TransposeFactorization) ? LinearAlgebra.TransposeFactorization : Transpose

"""
InvertibleOperator(F)

Expand Down Expand Up @@ -153,13 +156,12 @@ function Base.convert(::Type{<:Factorization}, L::InvertibleOperator{T,<:Factori
L.F
end

function Base.convert(::Type{AbstractMatrix}, L::InvertibleOperator)
if L.F isa Adjoint
convert(AbstractMatrix,L.F')'
else
convert(AbstractMatrix, L.F)
end
end
Base.convert(::Type{AbstractMatrix}, L::InvertibleOperator) =
convert(AbstractMatrix, L.F)
Base.convert(::Type{AbstractMatrix}, L::InvertibleOperator{<:Any,<:Union{Adjoint,AdjointFact}}) =
adjoint(convert(AbstractMatrix, adjoint(L.F)))
Base.convert(::Type{AbstractMatrix}, L::InvertibleOperator{<:Any,<:Union{Transpose,TransposeFact}}) =
transpose(convert(AbstractMatrix, transpose(L.F)))

# traits
Base.size(L::InvertibleOperator) = size(L.F)
Expand Down
7 changes: 6 additions & 1 deletion test/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,12 @@ for square in [false, true] #for K in [1, K]
v2=copy(u2); @test ldiv!(opAB_F , u2) ≈ AB \ v2
v3=copy(u3); @test ldiv!(opABC_F, u3) ≈ ABC \ v3
else # TODO
u2=rand(N2,K); @test_broken ldiv!(u2, opAB_F , v2) ≈ AB \ v2 # fails
u2=rand(N2,K);
if VERSION < v"1.9-"
@test_broken ldiv!(u2, opAB_F , v2) ≈ AB \ v2
else
@test ldiv!(u2, opAB_F , v2) ≈ AB \ v2 # fails
ChrisRackauckas marked this conversation as resolved.
Show resolved Hide resolved
end
u3=rand(N3,K); @test_broken ldiv!(u3, opABC_F, v3) ≈ ABC \ v3 # errors
end

Expand Down