Skip to content

Commit acd736a

Browse files
authored
improve inference in Ray (#165)
* improve inference in Ray * fix test on v1.6
1 parent 5a42cb2 commit acd736a

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
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.5.21"
3+
version = "0.5.22"
44

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

src/Domains/Ray.jl

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,20 @@ Ray{a}() where {a} = Ray{a,Float64}()
2525
angle(d::Ray{a}) where {a} = a*π
2626

2727
# ensure the angle is always in (-1,1]
28-
Ray(c,a,L,o) = Ray{a==0 ? false : (abs(a)≈(1.0π) ? true : mod(a/π-1,-2)+1),typeof(c)}(c,L,o)
29-
Ray(c,a,o) = Ray{a==0 ? false : (abs(a)≈(1.0π) ? true : mod(a/π-1,-2)+1),typeof(c)}(c,one(typeof(c)),o)
28+
@inline function _Ray(c,a,L,o)
29+
angle = if iszero(a)
30+
false
31+
else
32+
(abs(a)(1.0π) ? true : mod(a/π-1,-2)+1)
33+
end
34+
Ray{angle,typeof(c)}(c,L,o)
35+
end
36+
@static if VERSION >= v"1.8"
37+
Base.@constprop :aggressive Ray(c,a,L,o) = _Ray(c,a,L,o)
38+
else
39+
Ray(c,a,L,o) = _Ray(c,a,L,o)
40+
end
41+
Ray(c,a,o) = Ray(c,a,one(typeof(c)),o)
3042
Ray(c,a) = Ray(c,a,one(typeof(c)),true)
3143

3244
Ray() = Ray{false}()
@@ -35,14 +47,17 @@ Ray() = Ray{false}()
3547

3648
##deal with vector
3749

50+
_rayangle(x) = angle(x)
51+
_rayangle(x::Real) = 0
52+
3853
function convert(::Type{Ray}, d::AbstractInterval)
3954
a,b = endpoints(d)
4055
@assert abs(a)==Inf || abs(b)==Inf
4156

4257
if abs(b)==Inf
43-
Ray(a,angle(b),one(typeof(a)),true)
58+
Ray(a,_rayangle(b),one(typeof(a)),true)
4459
else #abs(a)==Inf
45-
Ray(b,angle(a),one(typeof(a)),false)
60+
Ray(b,_rayangle(a),one(typeof(a)),false)
4661
end
4762
end
4863
Ray(d::AbstractInterval) = strictconvert(Ray, d)

test/LaguerreTest.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ using ApproxFunBaseTest: testbandedoperator
66

77

88
@verbose @testset "Laguerre and WeightedLaguerre" begin
9-
9+
@testset "Ray" begin
10+
r = VERSION >= v"1.8" ? @inferred(Ray(0..Inf)) : Ray(0..Inf)
11+
L = Laguerre(1.0,r)
12+
f = x -> exp.(-x)
13+
F = Fun(f, L)
14+
@test F(.3) -F'(.3)
15+
end
1016
@testset "General scaled rays" begin
11-
r = Ray(-1.0,0.0,2.0,true)
17+
r = @inferred (() -> Ray(-1.0,0.0,2.0,true))()
1218
L = Laguerre(1.0,r)
1319
f = x -> exp.(-x)
1420
F = Fun(f, L)

0 commit comments

Comments
 (0)