Skip to content

Commit 511a8a1

Browse files
authored
Improve inference in chebyshev_clenshaw (#498)
* improve inference in chebyshev_clenshaw * bump version to v0.8.39 * don't dev ApproxFunBaseTest on v1.9 * Test for empty vector * use points in domain * Test for BigInt coeffs
1 parent a1d1393 commit 511a8a1

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

.github/workflows/downstream.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ jobs:
5858
try
5959
# force it to use this PR's version of the package
6060
Pkg.develop(PackageSpec(path=".")) # resolver may fail with main deps
61-
Pkg.develop(PackageSpec(path="ApproxFunBaseTest"))
61+
# the following may fail because of https://github.com/JuliaLang/Pkg.jl/issues/3327
62+
# currently, we only test on older versions that don't use Pkg extensions
63+
if VERSION < v"1.9"
64+
Pkg.develop(PackageSpec(path="ApproxFunBaseTest"))
65+
end
6266
Pkg.update()
6367
Pkg.test(; coverage = true) # resolver may fail with test time deps
6468
catch err

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.38"
3+
version = "0.8.39"
44

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

src/LinearAlgebra/clenshaw.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,9 @@ sineshaw(c::AbstractVector,θ::AbstractMatrix) = promote_type(eltype(c),eltype(
219219
function chebyshev_clenshaw(c::AbstractVector, x)
220220
N,T = length(c),promote_type(eltype(c),typeof(x))
221221
if N == 0
222-
return zero(x)
222+
return zero(float(x) * oneunit(eltype(c)))
223223
elseif N == 1 # avoid issues with NaN x
224-
return first(c)*one(x)
224+
return first(c) * oneunit(float(x))
225225
end
226226

227227
x = 2x

test/runtests.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using ApproxFunBase
2-
using ApproxFunBase:
2+
using ApproxFunBase: chebyshev_clenshaw
33
using Aqua
44
using BandedMatrices
55
using BlockArrays
66
using BlockBandedMatrices
77
using DomainSets
8+
using DualNumbers
89
using FillArrays
910
using InfiniteArrays
1011
using Infinities
@@ -732,4 +733,19 @@ end
732733
@time include("ETDRK4Test.jl")
733734
include("show.jl")
734735

736+
@testset "chebyshev_clenshaw" begin
737+
@test @inferred(chebyshev_clenshaw(Int[], 1)) == 0
738+
@test @inferred(chebyshev_clenshaw(Int[], Dual(0,1))) == Dual(0,0)
739+
@test @inferred(chebyshev_clenshaw(Int[], Dual(2,1))) == Dual(0,0)
740+
@test @inferred(chebyshev_clenshaw(Float64[], 1)) == 0
741+
@test @inferred(chebyshev_clenshaw(Float64[], 1.0)) == 0
742+
@test @inferred(chebyshev_clenshaw(Int[1], 1)) == 1
743+
@test @inferred(chebyshev_clenshaw([1,2], 1)) == 3
744+
@test @inferred(chebyshev_clenshaw([1,2], Dual(0,1))) == Dual(1,2)
745+
@test @inferred(chebyshev_clenshaw([1,2], Dual(1,1))) == Dual(3,2)
746+
@test @inferred(chebyshev_clenshaw([1,2], Dual(2,1))) == Dual(5,2)
747+
748+
@test @inferred(chebyshev_clenshaw(BigInt[1], 1)) == 1
749+
end
750+
735751
include("PolynomialSpacesTests.jl")

0 commit comments

Comments
 (0)