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
17 changes: 17 additions & 0 deletions src/abstract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,23 @@ storage_type(op::Adjoint) = storage_type(parent(op))
storage_type(op::Transpose) = storage_type(parent(op))
storage_type(op::Diagonal) = typeof(parent(op))

@inline function _select_storage_type(
op1::AbstractLinearOperator,
op2::AbstractLinearOperator,
T::Type,
)
S = promote_type(storage_type(op1), storage_type(op2))
if isconcretetype(S)
return S
elseif isconcretetype(storage_type(op1))
return storage_type(op1)
elseif isconcretetype(storage_type(op2))
return storage_type(op2)
else
return Vector{T}
end
end

"""
reset!(op)

Expand Down
8 changes: 2 additions & 6 deletions src/cat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ function hcat(A::AbstractLinearOperator, B::AbstractLinearOperator)
ctprod! = @closure (res, w, α, β) ->
hcat_ctprod!(res, adjoint(A), adjoint(B), Ancol, Ancol + Bncol, w, α, β)
args5 = (has_args5(A) && has_args5(B))
S = promote_type(storage_type(A), storage_type(B))
isconcretetype(S) ||
throw(LinearOperatorException("storage types cannot be promoted to a concrete type"))
S = _select_storage_type(A, B, T)
CompositeLinearOperator(T, nrow, ncol, false, false, prod!, tprod!, ctprod!, args5, S = S)
end

Expand Down Expand Up @@ -104,9 +102,7 @@ function vcat(A::AbstractLinearOperator, B::AbstractLinearOperator)
ctprod! = @closure (res, w, α, β) ->
vcat_ctprod!(res, adjoint(A), adjoint(B), Anrow, Anrow + Bnrow, w, α, β)
args5 = (has_args5(A) && has_args5(B))
S = promote_type(storage_type(A), storage_type(B))
isconcretetype(S) ||
throw(LinearOperatorException("storage types cannot be promoted to a concrete type"))
S = _select_storage_type(A, B, T)
CompositeLinearOperator(T, nrow, ncol, false, false, prod!, tprod!, ctprod!, args5, S = S)
end

Expand Down
8 changes: 2 additions & 6 deletions src/operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ function *(op1::AbstractLinearOperator, op2::AbstractLinearOperator)
if m2 != n1
throw(LinearOperatorException("shape mismatch"))
end
S = promote_type(storage_type(op1), storage_type(op2))
isconcretetype(S) ||
throw(LinearOperatorException("storage types cannot be promoted to a concrete type"))
S = _select_storage_type(op1, op2, T)
#tmp vector for products
vtmp = fill!(S(undef, m2), zero(T))
utmp = fill!(S(undef, n1), zero(T))
Expand Down Expand Up @@ -210,9 +208,7 @@ function +(op1::AbstractLinearOperator, op2::AbstractLinearOperator)
symm = (issymmetric(op1) && issymmetric(op2))
herm = (ishermitian(op1) && ishermitian(op2))
args5 = (has_args5(op1) && has_args5(op2))
S = promote_type(storage_type(op1), storage_type(op2))
isconcretetype(S) ||
throw(LinearOperatorException("storage types cannot be promoted to a concrete type"))
S = _select_storage_type(op1, op2, T)
return CompositeLinearOperator(T, m1, n1, symm, herm, prod!, tprod!, ctprod!, args5, S = S)
end

Expand Down
Loading