Skip to content

Commit e25ab77

Browse files
authored
Backport: Improve type-inference in multiplying with TimesOperator (#588)
* Backport: Improve type-inference in multiplying with TimesOperator * Remove ProductSpace test
1 parent 51f6c82 commit e25ab77

File tree

7 files changed

+34
-17
lines changed

7 files changed

+34
-17
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
arch:
5050
- x64
5151
steps:
52-
- uses: actions/checkout@v3
52+
- uses: actions/checkout@v4
5353
- uses: julia-actions/setup-julia@v1
5454
with:
5555
version: ${{ matrix.version }}

.github/workflows/downstream.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
- master
66
- backport**
77
tags: '*'
8+
paths-ignore:
9+
- 'LICENSE'
10+
- 'README.md'
11+
- '.github/workflows/TagBot.yml'
812
pull_request:
913
paths-ignore:
1014
- 'LICENSE'
@@ -42,14 +46,14 @@ jobs:
4246
- {repo: ApproxFunSingularities.jl, group: JuliaApproximation}
4347

4448
steps:
45-
- uses: actions/checkout@v3
49+
- uses: actions/checkout@v4
4650
- uses: julia-actions/setup-julia@v1
4751
with:
4852
version: ${{ matrix.julia-version }}
4953
arch: x64
5054
- uses: julia-actions/julia-buildpkg@latest
5155
- name: Clone Downstream
52-
uses: actions/checkout@v3
56+
uses: actions/checkout@v4
5357
with:
5458
repository: ${{ matrix.package.group }}/${{ matrix.package.repo }}
5559
path: downstream

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.8.56"
3+
version = "0.8.57"
44

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

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# ApproxFunBase.jl
22
Core functionality of ApproxFun
33

4-
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaApproximation.github.io/ApproxFun.jl/stable)
5-
[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaApproximation.github.io/ApproxFun.jl/dev)
64
[![CI](https://github.com/JuliaApproximation/ApproxFunBase.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/JuliaApproximation/ApproxFunBase.jl/actions/workflows/ci.yml)
75
[![IntegrationTest](https://github.com/JuliaApproximation/ApproxFunBase.jl/actions/workflows/downstream.yml/badge.svg)](https://github.com/JuliaApproximation/ApproxFunBase.jl/actions/workflows/downstream.yml)
86
[![codecov](https://codecov.io/gh/JuliaApproximation/ApproxFunBase.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaApproximation/ApproxFunBase.jl)
97
[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)
108
[![deps](https://juliahub.com/docs/ApproxFunBase/deps.svg)](https://juliahub.com/ui/Packages/ApproxFunBase/deO92?t=2)
119
[![version](https://juliahub.com/docs/ApproxFunBase/version.svg)](https://juliahub.com/ui/Packages/ApproxFunBase/deO92)
10+
[![pkgeval](https://juliahub.com/docs/General/ApproxFunBase/stable/pkgeval.svg)](https://juliahub.com/ui/Packages/General/ApproxFunBase)
11+
12+
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaApproximation.github.io/ApproxFun.jl/stable)
13+
[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaApproximation.github.io/ApproxFun.jl/dev)
1214
[![Join the chat at https://gitter.im/JuliaApproximation/ApproxFun.jl](https://badges.gitter.im/JuliaApproximation/ApproxFun.jl.svg)](https://gitter.im/JuliaApproximation/ApproxFun.jl?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
1315

1416

src/Operators/banded/Multiplication.jl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,21 @@ getindex(D::ConcreteMultiplication{F,UnsetSpace,T},k::Integer,j::Integer) where
7777

7878

7979
##multiplication can always be promoted, range space is allowed to change
80-
promotedomainspace(D::Multiplication,sp::UnsetSpace) = D
81-
promotedomainspace(D::Multiplication,sp::Space) = Multiplication(D.f,sp)
82-
promoterangespace(D::ConcreteMultiplication{P,UnsetSpace},sp::UnsetSpace) where {P} = D
83-
promoterangespace(D::ConcreteMultiplication{P,UnsetSpace},sp::Space) where {P} =
80+
promotedomainspace(D::Multiplication, sp::UnsetSpace) = D
81+
function promotedomainspace(D::Multiplication, sp::Space)
82+
if domainspace(D) === sp
83+
D
84+
else
85+
Multiplication(D.f,sp)
86+
end
87+
end
88+
promoterangespace(D::ConcreteMultiplication{P,UnsetSpace}, sp::UnsetSpace) where {P} = D
89+
promoterangespace(D::ConcreteMultiplication{P,UnsetSpace}, sp::Space) where {P} =
8490
promoterangespace(Multiplication(D.f,ConstantSpace(domain(sp))), sp)
8591

86-
choosedomainspace(M::ConcreteMultiplication{D,UnsetSpace},::UnsetSpace) where {D} = space(M.f)
92+
choosedomainspace(M::ConcreteMultiplication{D,UnsetSpace}, ::UnsetSpace) where {D} = space(M.f)
8793
# we assume multiplication maps spaces to themselves
88-
choosedomainspace(M::ConcreteMultiplication{D,UnsetSpace},sp::Space) where {D} = sp
94+
choosedomainspace(M::ConcreteMultiplication{D,UnsetSpace}, sp::Space) where {D} = sp
8995

9096

9197
diagm(a::Fun) = Multiplication(a)

src/Operators/general/algebra.jl

Lines changed: 8 additions & 3 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)
@@ -281,6 +281,9 @@ struct TimesOperator{T,BW,SZ,O<:Operator{T},BBW,SBBW} <: Operator{T}
281281
end
282282
end
283283

284+
operatortype(::T) where {T<:Operator} = T
285+
operatortype(::TimesOperator{<:Any,<:Any,<:Any,O}) where {O} = O
286+
284287
const PlusOrTimesOp = Union{PlusOperator,TimesOperator}
285288

286289
bandwidthssum(f, ops) = mapfoldl(f, (t1, t2) -> t1 .+ t2, ops, init=(0, 0))
@@ -351,8 +354,10 @@ end
351354
anytimesop = any(x -> x isa TimesOperator, ops)
352355
TimesOperator(convert_vector(ops), bw, sz, bbw, sbbw, ibbb, irb, isaf; anytimesop)
353356
end
357+
maybenarroweltype(::AbstractVector{Operator{T}}) where {T} = Operator{T}
358+
maybenarroweltype(opsin) = mapreduce(operatortype, promote_type, opsin)
354359
function __promotetimes(opsin, dsp, anytimesop)
355-
ops = Vector{Operator{promote_eltypeof(opsin)}}(undef, 0)
360+
ops = Vector{maybenarroweltype(opsin)}(undef, 0)
356361
sizehint!(ops, length(opsin))
357362

358363
for k in reverse(eachindex(opsin))
@@ -633,7 +638,7 @@ function A_mul_B(A::Operator, B::Operator; dspB=domainspace(B), rspA=rangespace(
633638
elseif isconstop(B)
634639
promotedomainspace(strictconvert(Number, B) * A, dspB)
635640
else
636-
promotetimes(collateops(*, A, B), dspB, false)
641+
promotetimes(collateops(*, A : rangespace(B), B), dspB, false)
637642
end
638643
end
639644

test/show.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@testset "ConstantSpace" begin
1212
@test contains(repr(ConstantSpace()), "ConstantSpace")
1313
c = ConstantSpace(0..1)
14-
@test contains(repr(c), "ConstantSpace")
14+
@test startswith(repr(c), "ConstantSpace")
1515
@test contains(repr(c), repr(domain(c)))
1616
end
1717
@testset "TensorSpace" begin
@@ -32,7 +32,7 @@
3232
p = PointSpace(1:4)
3333
ps = PiecewiseSpace(p)
3434
rpr = repr(ps)
35-
@test contains(rpr, "PiecewiseSpace")
35+
@test startswith(rpr, "PiecewiseSpace")
3636
@test contains(rpr, repr(p))
3737
end
3838
@testset "ArraySpace" begin

0 commit comments

Comments
 (0)