Skip to content

Optimize identity Fun in Ultraspherical #163

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 1 commit into from
Dec 8, 2022
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
4 changes: 2 additions & 2 deletions 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.5.19"
version = "0.5.20"

[deps]
ApproxFunBase = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
Expand All @@ -19,7 +19,7 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
ApproxFunBase = "0.7.43"
ApproxFunBase = "0.7.50"
ApproxFunBaseTest = "0.1"
Aqua = "0.5"
BandedMatrices = "0.16, 0.17"
Expand Down
13 changes: 8 additions & 5 deletions src/Spaces/Chebyshev/Chebyshev.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ end
normalization(::Type{T}, sp::Chebyshev, k::Int) where T = T(π)/(2-FastTransforms.δ(k,0))

Space(d::SegmentDomain) = Chebyshev(d)
_norm(x) = norm(x)
_norm(x::Real) = abs(x) # this preserves integers, whereas norm returns a float
function Space(d::AbstractInterval)
a,b = endpoints(d)
if isinf(norm(a)) && isinf(norm(b))
Chebyshev(Line(d))
elseif isinf(norm(a)) || isinf(norm(b))
Chebyshev(Ray(d))
d2 = if isinf(_norm(a)) && isinf(_norm(b))
Line(d)
elseif isinf(_norm(a)) || isinf(_norm(b))
Ray(d)
else
Chebyshev(d)
d
end
Chebyshev(d2)
end


Expand Down
11 changes: 1 addition & 10 deletions src/Spaces/IntervalSpace.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
Space(d::IntervalOrSegment) = Chebyshev(d)
Space(d::FullSpace{<:Real}) = Chebyshev(Line())

Fun(::typeof(identity), d::IntervalOrSegment{T}) where {T<:Number} =
Fun(::typeof(identity), d::IntervalOrSegment{<:Number}) =
Fun(Chebyshev(d), [mean(d), complexlength(d)/2])


## Calculus



# the default domain space is higher to avoid negative ultraspherical spaces
Integral(d::IntervalOrSegment,n::Integer) = Integral(Ultraspherical(1,d),n)

8 changes: 6 additions & 2 deletions src/Spaces/Ultraspherical/Ultraspherical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ plan_itransform!(sp::Ultraspherical,cfs::AbstractVector) = UltrasphericalIPlan(o
#domain(S) may be any domain

ones(::Type{T},S::Ultraspherical) where {T<:Number} = Fun(S,fill(one(T),1))
ones(S::Ultraspherical) = Fun(S,fill(1.0,1))
ones(S::Ultraspherical) = ones(Float64, S)



Expand All @@ -118,7 +118,11 @@ Base.last(f::Fun{Ultraspherical{Int,D,R}}) where {D,R} = reduce(+,coefficients(f
Base.first(f::Fun{Ultraspherical{O,D,R}}) where {O,D,R} = f(leftendpoint(domain(f)))
Base.last(f::Fun{Ultraspherical{O,D,R}}) where {O,D,R} = f(rightendpoint(domain(f)))

Fun(::typeof(identity), d::Ultraspherical) = Fun(Fun(identity, domain(d)),d)
function Fun(::typeof(identity), s::Ultraspherical)
d = domain(s)
m = order(s)
Fun(s, [mean(d), complexlength(d)/4m])
end


## Calculus
Expand Down
12 changes: 12 additions & 0 deletions test/UltrasphericalTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ using ApproxFunBaseTest: testbandedbelowoperator, testbandedoperator, testspace,
using ApproxFunOrthogonalPolynomials: jacobip

@testset "Ultraspherical" begin
@testset "identity fun" begin
for d in (ChebyshevInterval(), 3..4, Segment(2, 5), Segment(1, 4im)), order in (1, 2, 0.5)
s = Ultraspherical(order, d)
f = Fun(s)
xl = leftendpoint(domain(s))
xr = rightendpoint(domain(s))
xm = (xl + xr)/2
@test f(xl) ≈ xl
@test f(xr) ≈ xr
@test f(xm) ≈ xm
end
end
@testset "Conversion" begin
# Tests whether invalid/unimplemented arguments correctly throws ArgumentError
@test_throws ArgumentError Conversion(Ultraspherical(2), Ultraspherical(1))
Expand Down