Skip to content

Commit c7c2038

Browse files
authored
first/last return floats for Int coefficients (#277)
* first/last return floats for Int coefficients * remove Ultraspherical specializations
1 parent 8305d11 commit c7c2038

File tree

5 files changed

+22
-20
lines changed

5 files changed

+22
-20
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunOrthogonalPolynomials"
22
uuid = "b70543e2-c0d9-56b8-a290-0d4d6d4de211"
3-
version = "0.6.38"
3+
version = "0.6.39"
44

55
[deps]
66
ApproxFunBase = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"

src/Spaces/Chebyshev/Chebyshev.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,18 @@ ones(S::Chebyshev) = Fun(S,fill(1.0,1))
5959

6060
function first(f::Fun{<:Chebyshev})
6161
n = ncoefficients(f)
62-
n == 0 && return zero(cfstype(f))
63-
n == 1 && return f.coefficients[1]
64-
foldr(-,coefficients(f))
62+
T = rangetype(space(f))
63+
oneel = oneunit(T)
64+
n == 0 && return zero(cfstype(f)) * oneel
65+
n == 1 && return f.coefficients[1] * oneel
66+
foldr(-,coefficients(f)) * oneel
6567
end
6668

67-
last(f::Fun{<:Chebyshev}) = reduce(+,coefficients(f))
69+
function last(f::Fun{<:Chebyshev})
70+
T = rangetype(space(f))
71+
oneel = oneunit(T)
72+
reduce(+,coefficients(f)) * oneel
73+
end
6874

6975
spacescompatible(a::Chebyshev,b::Chebyshev) = domainscompatible(a,b)
7076
hasfasttransform(::Chebyshev) = true

src/Spaces/Ultraspherical/Ultraspherical.jl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,6 @@ ones(::Type{T},S::Ultraspherical) where {T<:Number} = Fun(S,fill(one(T),1))
100100
ones(S::Ultraspherical) = ones(Float64, S)
101101

102102

103-
104-
## Fast evaluation
105-
106-
function first(f::Fun{<:Ultraspherical{Int}})
107-
n = length(f.coefficients)
108-
n == 0 && return zero(cfstype(f))
109-
n == 1 && return first(f.coefficients)
110-
foldr(-,coefficients(f,Chebyshev))
111-
end
112-
113-
last(f::Fun{<:Ultraspherical{Int}}) = reduce(+,coefficients(f,Chebyshev))
114-
115-
first(f::Fun{<:Ultraspherical}) = f(leftendpoint(domain(f)))
116-
last(f::Fun{<:Ultraspherical}) = f(rightendpoint(domain(f)))
117-
118103
function Fun(::typeof(identity), s::Ultraspherical)
119104
d = domain(s)
120105
m = order(s)

test/ChebyshevTest.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ include("testutils.jl")
5656
@test contains(summary(p), "ShiftedChebyshevGrid{Float64}")
5757
end
5858

59+
@testset "first/last" begin
60+
f = Fun(Chebyshev(), [1,2])
61+
@test @inferred(first(f)) === f(-1)
62+
@test @inferred(last(f)) === f(1)
63+
end
64+
5965
@testset "inference in Space(::Interval)" begin
6066
S = @inferred Space(0..1)
6167
f = Fun(S)

test/UltrasphericalTest.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ include("testutils.jl")
2727
@test f(xm) xm
2828
end
2929
end
30+
@testset "first/last" begin
31+
f = Fun(Ultraspherical(2), [1,2])
32+
@test @inferred(first(f)) === f(-1)
33+
@test @inferred(last(f)) === f(1)
34+
end
3035
@testset "Conversion" begin
3136
# Tests whether invalid/unimplemented arguments correctly throws ArgumentError
3237
@test_throws ArgumentError Conversion(Ultraspherical(2), Ultraspherical(1))

0 commit comments

Comments
 (0)