Skip to content

Commit a830e33

Browse files
authored
limit eltype in ConstantTimesOperator (#209)
1 parent c3cfaaf commit a830e33

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/Operators/general/algebra.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,23 @@ end
147147

148148
## Times Operator
149149

150-
struct ConstantTimesOperator{B,T} <: Operator{T}
150+
struct ConstantTimesOperator{T<:Number, B<:Operator{T}} <: Operator{T}
151151
λ::T
152152
op::B
153-
ConstantTimesOperator{B,T}(c,op) where {B,T} = new{B,T}(c,op)
153+
ConstantTimesOperator{T,B}(c::T, op::B) where {T,B<:Operator{T}} = new{T,B}(c,op)
154154
end
155-
function ConstantTimesOperator(c::Number,op::Operator{TT}) where TT<:Number
155+
156+
ConstantTimesOperator(c::T, op::Operator{T}) where T<:Number =
157+
ConstantTimesOperator{T, typeof(op)}(c, op)
158+
159+
function ConstantTimesOperator(c::Number, op::Operator{<:Number})
156160
T=promote_type(typeof(c),eltype(op))
157161
B=strictconvert(Operator{T},op)
158-
ConstantTimesOperator{typeof(B),T}(T(c),B)
162+
ConstantTimesOperator(T(c)::T, B)
159163
end
160164

161-
ConstantTimesOperator(c::Number,op::ConstantTimesOperator) =
162-
ConstantTimesOperator(c*op.λ,op.op)
165+
ConstantTimesOperator(c::Number, op::ConstantTimesOperator) =
166+
ConstantTimesOperator(c*op.λ, op.op)
163167

164168
@wrapperstructure ConstantTimesOperator
165169
@wrapperspaces ConstantTimesOperator
@@ -179,7 +183,7 @@ function convert(::Type{Operator{T}},C::ConstantTimesOperator) where T
179183
C
180184
else
181185
op=strictconvert(Operator{T},C.op)
182-
ConstantTimesOperator{typeof(op),T}(T(C.λ),op)
186+
ConstantTimesOperator(T(C.λ)::T, op)::Operator{T}
183187
end
184188
end
185189

0 commit comments

Comments
 (0)