Skip to content

Improve inference in chebyshev_clenshaw #498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ jobs:
try
# force it to use this PR's version of the package
Pkg.develop(PackageSpec(path=".")) # resolver may fail with main deps
Pkg.develop(PackageSpec(path="ApproxFunBaseTest"))
# the following may fail because of https://github.com/JuliaLang/Pkg.jl/issues/3327
# currently, we only test on older versions that don't use Pkg extensions
if VERSION < v"1.9"
Pkg.develop(PackageSpec(path="ApproxFunBaseTest"))
end
Pkg.update()
Pkg.test(; coverage = true) # resolver may fail with test time deps
catch err
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.38"
version = "0.8.39"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand Down
4 changes: 2 additions & 2 deletions src/LinearAlgebra/clenshaw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ sineshaw(c::AbstractVector,θ::AbstractMatrix) = promote_type(eltype(c),eltype(
function chebyshev_clenshaw(c::AbstractVector, x)
N,T = length(c),promote_type(eltype(c),typeof(x))
if N == 0
return zero(x)
return zero(float(x) * oneunit(eltype(c)))
elseif N == 1 # avoid issues with NaN x
return first(c)*one(x)
return first(c) * oneunit(float(x))
end

x = 2x
Expand Down
18 changes: 17 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using ApproxFunBase
using ApproxFunBase:
using ApproxFunBase: chebyshev_clenshaw
using Aqua
using BandedMatrices
using BlockArrays
using BlockBandedMatrices
using DomainSets
using DualNumbers
using FillArrays
using InfiniteArrays
using Infinities
Expand Down Expand Up @@ -732,4 +733,19 @@ end
@time include("ETDRK4Test.jl")
include("show.jl")

@testset "chebyshev_clenshaw" begin
@test @inferred(chebyshev_clenshaw(Int[], 1)) == 0
@test @inferred(chebyshev_clenshaw(Int[], Dual(0,1))) == Dual(0,0)
@test @inferred(chebyshev_clenshaw(Int[], Dual(2,1))) == Dual(0,0)
@test @inferred(chebyshev_clenshaw(Float64[], 1)) == 0
@test @inferred(chebyshev_clenshaw(Float64[], 1.0)) == 0
@test @inferred(chebyshev_clenshaw(Int[1], 1)) == 1
@test @inferred(chebyshev_clenshaw([1,2], 1)) == 3
@test @inferred(chebyshev_clenshaw([1,2], Dual(0,1))) == Dual(1,2)
@test @inferred(chebyshev_clenshaw([1,2], Dual(1,1))) == Dual(3,2)
@test @inferred(chebyshev_clenshaw([1,2], Dual(2,1))) == Dual(5,2)

@test @inferred(chebyshev_clenshaw(BigInt[1], 1)) == 1
end

include("PolynomialSpacesTests.jl")