Skip to content

Commit

Permalink
Backport: Improve type-inference in multiplying with TimesOperator (#588
Browse files Browse the repository at this point in the history
)

* Backport: Improve type-inference in multiplying with TimesOperator

* Remove ProductSpace test
  • Loading branch information
jishnub authored Sep 7, 2023
1 parent 51f6c82 commit e25ab77
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
arch:
- x64
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
- master
- backport**
tags: '*'
paths-ignore:
- 'LICENSE'
- 'README.md'
- '.github/workflows/TagBot.yml'
pull_request:
paths-ignore:
- 'LICENSE'
Expand Down Expand Up @@ -42,14 +46,14 @@ jobs:
- {repo: ApproxFunSingularities.jl, group: JuliaApproximation}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
arch: x64
- uses: julia-actions/julia-buildpkg@latest
- name: Clone Downstream
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ${{ matrix.package.group }}/${{ matrix.package.repo }}
path: downstream
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ApproxFunBase"
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
version = "0.8.56"
version = "0.8.57"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# ApproxFunBase.jl
Core functionality of ApproxFun

[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaApproximation.github.io/ApproxFun.jl/stable)
[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaApproximation.github.io/ApproxFun.jl/dev)
[![CI](https://github.com/JuliaApproximation/ApproxFunBase.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/JuliaApproximation/ApproxFunBase.jl/actions/workflows/ci.yml)
[![IntegrationTest](https://github.com/JuliaApproximation/ApproxFunBase.jl/actions/workflows/downstream.yml/badge.svg)](https://github.com/JuliaApproximation/ApproxFunBase.jl/actions/workflows/downstream.yml)
[![codecov](https://codecov.io/gh/JuliaApproximation/ApproxFunBase.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaApproximation/ApproxFunBase.jl)
[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)
[![deps](https://juliahub.com/docs/ApproxFunBase/deps.svg)](https://juliahub.com/ui/Packages/ApproxFunBase/deO92?t=2)
[![version](https://juliahub.com/docs/ApproxFunBase/version.svg)](https://juliahub.com/ui/Packages/ApproxFunBase/deO92)
[![pkgeval](https://juliahub.com/docs/General/ApproxFunBase/stable/pkgeval.svg)](https://juliahub.com/ui/Packages/General/ApproxFunBase)

[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaApproximation.github.io/ApproxFun.jl/stable)
[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaApproximation.github.io/ApproxFun.jl/dev)
[![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)


Expand Down
18 changes: 12 additions & 6 deletions src/Operators/banded/Multiplication.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,21 @@ getindex(D::ConcreteMultiplication{F,UnsetSpace,T},k::Integer,j::Integer) where


##multiplication can always be promoted, range space is allowed to change
promotedomainspace(D::Multiplication,sp::UnsetSpace) = D
promotedomainspace(D::Multiplication,sp::Space) = Multiplication(D.f,sp)
promoterangespace(D::ConcreteMultiplication{P,UnsetSpace},sp::UnsetSpace) where {P} = D
promoterangespace(D::ConcreteMultiplication{P,UnsetSpace},sp::Space) where {P} =
promotedomainspace(D::Multiplication, sp::UnsetSpace) = D
function promotedomainspace(D::Multiplication, sp::Space)
if domainspace(D) === sp
D
else
Multiplication(D.f,sp)
end
end
promoterangespace(D::ConcreteMultiplication{P,UnsetSpace}, sp::UnsetSpace) where {P} = D
promoterangespace(D::ConcreteMultiplication{P,UnsetSpace}, sp::Space) where {P} =
promoterangespace(Multiplication(D.f,ConstantSpace(domain(sp))), sp)

choosedomainspace(M::ConcreteMultiplication{D,UnsetSpace},::UnsetSpace) where {D} = space(M.f)
choosedomainspace(M::ConcreteMultiplication{D,UnsetSpace}, ::UnsetSpace) where {D} = space(M.f)
# we assume multiplication maps spaces to themselves
choosedomainspace(M::ConcreteMultiplication{D,UnsetSpace},sp::Space) where {D} = sp
choosedomainspace(M::ConcreteMultiplication{D,UnsetSpace}, sp::Space) where {D} = sp


diagm(a::Fun) = Multiplication(a)
Expand Down
11 changes: 8 additions & 3 deletions src/Operators/general/algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ end

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

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

function +(A::Operator, B::Operator)
Expand Down Expand Up @@ -281,6 +281,9 @@ struct TimesOperator{T,BW,SZ,O<:Operator{T},BBW,SBBW} <: Operator{T}
end
end

operatortype(::T) where {T<:Operator} = T
operatortype(::TimesOperator{<:Any,<:Any,<:Any,O}) where {O} = O

const PlusOrTimesOp = Union{PlusOperator,TimesOperator}

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

for k in reverse(eachindex(opsin))
Expand Down Expand Up @@ -633,7 +638,7 @@ function A_mul_B(A::Operator, B::Operator; dspB=domainspace(B), rspA=rangespace(
elseif isconstop(B)
promotedomainspace(strictconvert(Number, B) * A, dspB)
else
promotetimes(collateops(*, A, B), dspB, false)
promotetimes(collateops(*, A : rangespace(B), B), dspB, false)
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@testset "ConstantSpace" begin
@test contains(repr(ConstantSpace()), "ConstantSpace")
c = ConstantSpace(0..1)
@test contains(repr(c), "ConstantSpace")
@test startswith(repr(c), "ConstantSpace")
@test contains(repr(c), repr(domain(c)))
end
@testset "TensorSpace" begin
Expand All @@ -32,7 +32,7 @@
p = PointSpace(1:4)
ps = PiecewiseSpace(p)
rpr = repr(ps)
@test contains(rpr, "PiecewiseSpace")
@test startswith(rpr, "PiecewiseSpace")
@test contains(rpr, repr(p))
end
@testset "ArraySpace" begin
Expand Down

2 comments on commit e25ab77

@jishnub
Copy link
Member Author

@jishnub jishnub commented on e25ab77 Sep 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/90979

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.57 -m "<description of version>" e25ab77764482a508aab2799eecc56e4cdae6e13
git push origin v0.8.57

Please sign in to comment.