Skip to content

Commit

Permalink
first/last return floats for Int coefficients (#277)
Browse files Browse the repository at this point in the history
* first/last return floats for Int coefficients

* remove Ultraspherical specializations
  • Loading branch information
jishnub authored Jul 22, 2023
1 parent 8305d11 commit c7c2038
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ApproxFunOrthogonalPolynomials"
uuid = "b70543e2-c0d9-56b8-a290-0d4d6d4de211"
version = "0.6.38"
version = "0.6.39"

[deps]
ApproxFunBase = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
Expand Down
14 changes: 10 additions & 4 deletions src/Spaces/Chebyshev/Chebyshev.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,18 @@ ones(S::Chebyshev) = Fun(S,fill(1.0,1))

function first(f::Fun{<:Chebyshev})
n = ncoefficients(f)
n == 0 && return zero(cfstype(f))
n == 1 && return f.coefficients[1]
foldr(-,coefficients(f))
T = rangetype(space(f))
oneel = oneunit(T)
n == 0 && return zero(cfstype(f)) * oneel
n == 1 && return f.coefficients[1] * oneel
foldr(-,coefficients(f)) * oneel
end

last(f::Fun{<:Chebyshev}) = reduce(+,coefficients(f))
function last(f::Fun{<:Chebyshev})
T = rangetype(space(f))
oneel = oneunit(T)
reduce(+,coefficients(f)) * oneel
end

spacescompatible(a::Chebyshev,b::Chebyshev) = domainscompatible(a,b)
hasfasttransform(::Chebyshev) = true
Expand Down
15 changes: 0 additions & 15 deletions src/Spaces/Ultraspherical/Ultraspherical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,6 @@ ones(::Type{T},S::Ultraspherical) where {T<:Number} = Fun(S,fill(one(T),1))
ones(S::Ultraspherical) = ones(Float64, S)



## Fast evaluation

function first(f::Fun{<:Ultraspherical{Int}})
n = length(f.coefficients)
n == 0 && return zero(cfstype(f))
n == 1 && return first(f.coefficients)
foldr(-,coefficients(f,Chebyshev))
end

last(f::Fun{<:Ultraspherical{Int}}) = reduce(+,coefficients(f,Chebyshev))

first(f::Fun{<:Ultraspherical}) = f(leftendpoint(domain(f)))
last(f::Fun{<:Ultraspherical}) = f(rightendpoint(domain(f)))

function Fun(::typeof(identity), s::Ultraspherical)
d = domain(s)
m = order(s)
Expand Down
6 changes: 6 additions & 0 deletions test/ChebyshevTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ include("testutils.jl")
@test contains(summary(p), "ShiftedChebyshevGrid{Float64}")
end

@testset "first/last" begin
f = Fun(Chebyshev(), [1,2])
@test @inferred(first(f)) === f(-1)
@test @inferred(last(f)) === f(1)
end

@testset "inference in Space(::Interval)" begin
S = @inferred Space(0..1)
f = Fun(S)
Expand Down
5 changes: 5 additions & 0 deletions test/UltrasphericalTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ include("testutils.jl")
@test f(xm) xm
end
end
@testset "first/last" begin
f = Fun(Ultraspherical(2), [1,2])
@test @inferred(first(f)) === f(-1)
@test @inferred(last(f)) === f(1)
end
@testset "Conversion" begin
# Tests whether invalid/unimplemented arguments correctly throws ArgumentError
@test_throws ArgumentError Conversion(Ultraspherical(2), Ultraspherical(1))
Expand Down

2 comments on commit c7c2038

@jishnub
Copy link
Member Author

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/88069

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.6.39 -m "<description of version>" c7c20387d7449f6ed5048dba67ea3889ce4e7f5c
git push origin v0.6.39

Please sign in to comment.