Skip to content

Commit 5ceec43

Browse files
authored
Improve type-inference in multiplying with TimesOperator (#587)
* Improve type-inference in multiplying with TimesOperator * promote domainspace in operator multiplication collateops
1 parent 8871a81 commit 5ceec43

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunBase"
22
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
3-
version = "0.9.12"
3+
version = "0.9.13"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/Operators/banded/Multiplication.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ getindex(D::ConcreteMultiplication{F,UnsetSpace,T},k::Integer,j::Integer) where
7979
##multiplication can always be promoted, range space is allowed to change
8080
promotedomainspace(D::Multiplication, sp::UnsetSpace) = D
8181
function promotedomainspace(D::Multiplication, sp::Space)
82-
if domainspace(D) == sp
82+
if domainspace(D) === sp
8383
D
8484
else
8585
Multiplication(D.f,sp)

src/Operators/general/algebra.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ end
8080

8181
domain(P::PlusOperator) = commondomain(P.ops)
8282

83-
_extractops(A, ::Any) = SVector{1}(A)
83+
_extractops(A, ::Any) = [A]
8484
_extractops(A::PlusOperator, ::typeof(+)) = A.ops
8585

8686
function +(A::Operator, B::Operator)
@@ -265,6 +265,9 @@ struct TimesOperator{T,BW,SZ,O<:Operator{T},BBW,SBBW} <: Operator{T}
265265
end
266266
end
267267

268+
operatortype(::T) where {T<:Operator} = T
269+
operatortype(::TimesOperator{<:Any,<:Any,<:Any,O}) where {O} = O
270+
268271
const PlusOrTimesOp = Union{PlusOperator,TimesOperator}
269272

270273
bandwidthssum(f, ops) = mapfoldl(f, (t1, t2) -> t1 .+ t2, ops, init=(0, 0))
@@ -329,8 +332,10 @@ Base.@constprop :aggressive function promotetimes(opsin,
329332
anytimesop = any(x -> x isa TimesOperator, ops)
330333
TimesOperator(convert_vector(ops), bw, sz, bbw, sbbw, ibbb, irb, isaf; anytimesop)
331334
end
335+
maybenarroweltype(::AbstractVector{Operator{T}}) where {T} = Operator{T}
336+
maybenarroweltype(opsin) = mapreduce(operatortype, promote_type, opsin)
332337
function __promotetimes(opsin, dsp, anytimesop)
333-
ops = Vector{Operator{promote_eltypeof(opsin)}}(undef, 0)
338+
ops = Vector{maybenarroweltype(opsin)}(undef, 0)
334339
sizehint!(ops, length(opsin))
335340

336341
for k in reverse(eachindex(opsin))
@@ -597,7 +602,7 @@ anyplustimes(::typeof(*), op::TimesOperator, ops...) = true
597602
anyplustimes(f) = false
598603

599604
collateops(op, As::Operator...) = collateops(op, Val(anyplustimes(op, As...)), As...)
600-
collateops(op, ::Val{true}, As...) = mapreduce(x -> _extractops(x, op), vcat, As)
605+
collateops(op, ::Val{true}, As...) = reduce(vcat, map(x -> _extractops(x, op), As))
601606
collateops(op, ::Val{false}, As...) = As
602607

603608
*(A::Operator, B::Operator) = A_mul_B(A, B)
@@ -611,7 +616,7 @@ function A_mul_B(A::Operator, B::Operator; dspB=domainspace(B), rspA=rangespace(
611616
elseif isconstop(B)
612617
promotedomainspace(strictconvert(Number, B) * A, dspB)
613618
else
614-
promotetimes(collateops(*, A, B), dspB, false)
619+
promotetimes(collateops(*, A : rangespace(B), B), dspB, false)
615620
end
616621
end
617622

0 commit comments

Comments
 (0)