Skip to content

Commit 0b7ecbb

Browse files
authored
Optimize identity Fun in Ultraspherical (#163)
1 parent 48c7954 commit 0b7ecbb

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
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.5.19"
3+
version = "0.5.20"
44

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

2121
[compat]
22-
ApproxFunBase = "0.7.43"
22+
ApproxFunBase = "0.7.50"
2323
ApproxFunBaseTest = "0.1"
2424
Aqua = "0.5"
2525
BandedMatrices = "0.16, 0.17"

src/Spaces/Chebyshev/Chebyshev.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,18 @@ end
3636
normalization(::Type{T}, sp::Chebyshev, k::Int) where T = T(π)/(2-FastTransforms.δ(k,0))
3737

3838
Space(d::SegmentDomain) = Chebyshev(d)
39+
_norm(x) = norm(x)
40+
_norm(x::Real) = abs(x) # this preserves integers, whereas norm returns a float
3941
function Space(d::AbstractInterval)
4042
a,b = endpoints(d)
41-
if isinf(norm(a)) && isinf(norm(b))
42-
Chebyshev(Line(d))
43-
elseif isinf(norm(a)) || isinf(norm(b))
44-
Chebyshev(Ray(d))
43+
d2 = if isinf(_norm(a)) && isinf(_norm(b))
44+
Line(d)
45+
elseif isinf(_norm(a)) || isinf(_norm(b))
46+
Ray(d)
4547
else
46-
Chebyshev(d)
48+
d
4749
end
50+
Chebyshev(d2)
4851
end
4952

5053

src/Spaces/IntervalSpace.jl

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
Space(d::IntervalOrSegment) = Chebyshev(d)
22
Space(d::FullSpace{<:Real}) = Chebyshev(Line())
33

4-
Fun(::typeof(identity), d::IntervalOrSegment{T}) where {T<:Number} =
4+
Fun(::typeof(identity), d::IntervalOrSegment{<:Number}) =
55
Fun(Chebyshev(d), [mean(d), complexlength(d)/2])
6-
7-
8-
## Calculus
9-
10-
11-
12-
# the default domain space is higher to avoid negative ultraspherical spaces
13-
Integral(d::IntervalOrSegment,n::Integer) = Integral(Ultraspherical(1,d),n)
14-

src/Spaces/Ultraspherical/Ultraspherical.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ plan_itransform!(sp::Ultraspherical,cfs::AbstractVector) = UltrasphericalIPlan(o
100100
#domain(S) may be any domain
101101

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

105105

106106

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

121-
Fun(::typeof(identity), d::Ultraspherical) = Fun(Fun(identity, domain(d)),d)
121+
function Fun(::typeof(identity), s::Ultraspherical)
122+
d = domain(s)
123+
m = order(s)
124+
Fun(s, [mean(d), complexlength(d)/4m])
125+
end
122126

123127

124128
## Calculus

test/UltrasphericalTest.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ using ApproxFunBaseTest: testbandedbelowoperator, testbandedoperator, testspace,
99
using ApproxFunOrthogonalPolynomials: jacobip
1010

1111
@testset "Ultraspherical" begin
12+
@testset "identity fun" begin
13+
for d in (ChebyshevInterval(), 3..4, Segment(2, 5), Segment(1, 4im)), order in (1, 2, 0.5)
14+
s = Ultraspherical(order, d)
15+
f = Fun(s)
16+
xl = leftendpoint(domain(s))
17+
xr = rightendpoint(domain(s))
18+
xm = (xl + xr)/2
19+
@test f(xl) xl
20+
@test f(xr) xr
21+
@test f(xm) xm
22+
end
23+
end
1224
@testset "Conversion" begin
1325
# Tests whether invalid/unimplemented arguments correctly throws ArgumentError
1426
@test_throws ArgumentError Conversion(Ultraspherical(2), Ultraspherical(1))

0 commit comments

Comments
 (0)