Skip to content

Commit ce86206

Browse files
committed
Storage-type promotion
1 parent ca52a1e commit ce86206

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

src/cat.jl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,15 @@ function hcat(A::AbstractLinearOperator, B::AbstractLinearOperator)
4646
hcat_ctprod!(res, adjoint(A), adjoint(B), Ancol, Ancol + Bncol, w, α, β)
4747
args5 = (has_args5(A) && has_args5(B))
4848
S = promote_type(storage_type(A), storage_type(B))
49-
isconcretetype(S) ||
50-
throw(LinearOperatorException("storage types cannot be promoted to a concrete type"))
49+
if !isconcretetype(S)
50+
if isconcretetype(storage_type(A))
51+
S = storage_type(A)
52+
elseif isconcretetype(storage_type(B))
53+
S = storage_type(B)
54+
else
55+
S = Vector{T}
56+
end
57+
end
5158
CompositeLinearOperator(T, nrow, ncol, false, false, prod!, tprod!, ctprod!, args5, S = S)
5259
end
5360

@@ -105,8 +112,15 @@ function vcat(A::AbstractLinearOperator, B::AbstractLinearOperator)
105112
vcat_ctprod!(res, adjoint(A), adjoint(B), Anrow, Anrow + Bnrow, w, α, β)
106113
args5 = (has_args5(A) && has_args5(B))
107114
S = promote_type(storage_type(A), storage_type(B))
108-
isconcretetype(S) ||
109-
throw(LinearOperatorException("storage types cannot be promoted to a concrete type"))
115+
if !isconcretetype(S)
116+
if isconcretetype(storage_type(A))
117+
S = storage_type(A)
118+
elseif isconcretetype(storage_type(B))
119+
S = storage_type(B)
120+
else
121+
S = Vector{T}
122+
end
123+
end
110124
CompositeLinearOperator(T, nrow, ncol, false, false, prod!, tprod!, ctprod!, args5, S = S)
111125
end
112126

src/operations.jl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,15 @@ function *(op1::AbstractLinearOperator, op2::AbstractLinearOperator)
140140
throw(LinearOperatorException("shape mismatch"))
141141
end
142142
S = promote_type(storage_type(op1), storage_type(op2))
143-
isconcretetype(S) ||
144-
throw(LinearOperatorException("storage types cannot be promoted to a concrete type"))
143+
if !isconcretetype(S)
144+
if isconcretetype(storage_type(op1))
145+
S = storage_type(op1)
146+
elseif isconcretetype(storage_type(op2))
147+
S = storage_type(op2)
148+
else
149+
S = Vector{T}
150+
end
151+
end
145152
#tmp vector for products
146153
vtmp = fill!(S(undef, m2), zero(T))
147154
utmp = fill!(S(undef, n1), zero(T))
@@ -211,8 +218,15 @@ function +(op1::AbstractLinearOperator, op2::AbstractLinearOperator)
211218
herm = (ishermitian(op1) && ishermitian(op2))
212219
args5 = (has_args5(op1) && has_args5(op2))
213220
S = promote_type(storage_type(op1), storage_type(op2))
214-
isconcretetype(S) ||
215-
throw(LinearOperatorException("storage types cannot be promoted to a concrete type"))
221+
if !isconcretetype(S)
222+
if isconcretetype(storage_type(op1))
223+
S = storage_type(op1)
224+
elseif isconcretetype(storage_type(op2))
225+
S = storage_type(op2)
226+
else
227+
S = Vector{T}
228+
end
229+
end
216230
return CompositeLinearOperator(T, m1, n1, symm, herm, prod!, tprod!, ctprod!, args5, S = S)
217231
end
218232

0 commit comments

Comments
 (0)