Skip to content

Commit 834017d

Browse files
authored
Real -> Number (#18)
1 parent fb155a5 commit 834017d

File tree

8 files changed

+29
-31
lines changed

8 files changed

+29
-31
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ QuasiArrays = "0.0.2"
2525

2626
[extras]
2727
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
28+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
2829

2930
[targets]
30-
test = ["Test"]
31+
test = ["Test","ForwardDiff"]

src/ContinuumArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ cardinality(::AbstractInterval) = ℵ₁
3131
*(ℵ::AlephInfinity) =
3232

3333

34-
checkindex(::Type{Bool}, inds::AbstractInterval, i::Real) = (leftendpoint(inds) <= i) & (i <= rightendpoint(inds))
34+
checkindex(::Type{Bool}, inds::AbstractInterval, i::Number) = (leftendpoint(inds) <= i) & (i <= rightendpoint(inds))
3535
checkindex(::Type{Bool}, inds::AbstractInterval, i::Inclusion) = i.domain inds
3636
function checkindex(::Type{Bool}, inds::AbstractInterval, I::AbstractArray)
3737
@_inline_meta

src/bases/jacobi.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ end
99
JacobiWeight(b::T, a::V) where {T,V} = JacobiWeight{promote_type(T,V)}(b,a)
1010

1111
axes(::AbstractJacobiWeight) = (Inclusion(ChebyshevInterval()),)
12-
function getindex(w::JacobiWeight, x::Real)
12+
function getindex(w::JacobiWeight, x::Number)
1313
x axes(w,1) || throw(BoundsError())
1414
(1-x)^w.a * (1+x)^w.b
1515
end

src/bases/orthogonalpolynomials.jl

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,7 @@ abstract type OrthogonalPolynomial{T} <: Basis{T} end
22

33
@inline jacobioperator(P::OrthogonalPolynomial) =
44
materialize(applied(\, P, applied(*, Diagonal(axes(P,1)), P)))
5-
6-
# function forwardrecurrence(::Type{T},S::Space,r::AbstractRange,x::Number) where T
7-
# if isempty(r)
8-
# return T[]
9-
# end
10-
# n=maximum(r)+1
11-
# v=Vector{T}(undef, n) # x may be complex
12-
# if n > 0
13-
# v[1]=1
14-
# if n > 1
15-
# v[2] = muladd(recA(T,S,0),x,recB(T,S,0))
16-
# @inbounds for k=2:n-1
17-
# v[k+1]=muladd(muladd(recA(T,S,k-1),x,recB(T,S,k-1)),v[k],-recC(T,S,k-1)*v[k-1])
18-
# end
19-
# end
20-
# end
21-
22-
# return v[r.+1]
23-
# end
5+
246

257
function forwardrecurrence!(v::AbstractVector{T}, b::AbstractVector, a::AbstractVector, c::AbstractVector, x) where T
268
isempty(v) && return v
@@ -77,7 +59,7 @@ _vec(a) = vec(a)
7759
_vec(a::Adjoint{<:Any,<:AbstractVector}) = a'
7860
bands(J) = _vec.(J.data.args)
7961

80-
function getindex(P::OrthogonalPolynomial{T}, x::Real, n::OneTo) where T
62+
function getindex(P::OrthogonalPolynomial{T}, x::Number, n::OneTo) where T
8163
J = jacobioperator(P)
8264
b,a,c = bands(J)
8365
forwardrecurrence!(similar(n,T),b,a,c,x)
@@ -93,10 +75,10 @@ function getindex(P::OrthogonalPolynomial{T}, x::AbstractVector, n::OneTo) where
9375
V
9476
end
9577

96-
getindex(P::OrthogonalPolynomial, x::Real, n::AbstractVector{<:Integer}) =
78+
getindex(P::OrthogonalPolynomial, x::Number, n::AbstractVector{<:Integer}) =
9779
P[x,OneTo(maximum(n))][n]
9880

9981
getindex(P::OrthogonalPolynomial, x::AbstractVector, n::AbstractVector{<:Integer}) =
10082
P[x,OneTo(maximum(n))][:,n]
10183

102-
getindex(P::OrthogonalPolynomial, x::Real, n::Real) = P[x,OneTo(n)][end]
84+
getindex(P::OrthogonalPolynomial, x::Number, n::Number) = P[x,OneTo(n)][end]

src/bases/splines.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ axes(B::Spline{o}) where o =
1212
(Inclusion(first(B.points)..last(B.points)), OneTo(length(B.points)+o-1))
1313
==(A::Spline{o}, B::Spline{o}) where o = A.points == B.points
1414

15-
function getindex(B::LinearSpline{T}, x::Real, k::Int) where T
15+
function getindex(B::LinearSpline{T}, x::Number, k::Int) where T
1616
x axes(B,1) && 1 k  size(B,2)|| throw(BoundsError())
1717

1818
p = B.points
@@ -25,7 +25,7 @@ function getindex(B::LinearSpline{T}, x::Real, k::Int) where T
2525
return (x-p[k+1])/(p[k]-p[k+1]) # x ≥ p[k]
2626
end
2727

28-
function getindex(B::HeavisideSpline{T}, x::Real, k::Int) where T
28+
function getindex(B::HeavisideSpline{T}, x::Number, k::Int) where T
2929
x axes(B,1) && 1 k  size(B,2)|| throw(BoundsError())
3030

3131
p = B.points

src/bases/ultraspherical.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
struct ChebyshevWeight{T} <: AbstractJacobiWeight{T} end
22

3-
function getindex(w::ChebyshevWeight, x::Real)
3+
function getindex(w::ChebyshevWeight, x::Number)
44
x axes(w,1) || throw(BoundsError())
55
1/sqrt(1-x^2)
66
end
@@ -9,7 +9,7 @@ struct UltrasphericalWeight{T,Λ} <: AbstractJacobiWeight{T}
99
λ::Λ
1010
end
1111

12-
function getindex(w::UltrasphericalWeight, x::Real)
12+
function getindex(w::UltrasphericalWeight, x::Number)
1313
x axes(w,1) || throw(BoundsError())
1414
(1-x^2)^(w.λ-one(w.λ)/2)
1515
end

src/operators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ IndexStyle(::Type{<:DiracDelta}) = IndexLinear()
127127

128128
==(a::DiracDelta, b::DiracDelta) = a.axis == b.axis && a.x == b.x
129129

130-
function getindex::DiracDelta{T}, x::Real) where T
130+
function getindex::DiracDelta{T}, x::Number) where T
131131
x δ.axis || throw(BoundsError())
132132
x == δ.x ? inv(zero(T)) : zero(T)
133133
end

test/runtests.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
using ContinuumArrays, QuasiArrays, LazyArrays, IntervalSets, FillArrays, LinearAlgebra, BandedMatrices, Test, InfiniteArrays
1+
using ContinuumArrays, QuasiArrays, LazyArrays, IntervalSets, FillArrays, LinearAlgebra, BandedMatrices, Test, InfiniteArrays, ForwardDiff
22
import ContinuumArrays: ℵ₁, materialize, Chebyshev, Ultraspherical, jacobioperator, SimplifyStyle
33
import QuasiArrays: SubQuasiArray, MulQuasiMatrix, Vec, Inclusion, QuasiDiagonal, LazyQuasiArrayApplyStyle, LmaterializeApplyStyle
44
import LazyArrays: MemoryLayout, ApplyStyle, Applied, colsupport
5+
import ForwardDiff: Dual
56

67

78
@testset "Inclusion" begin
@@ -380,4 +381,18 @@ end
380381
cfs = C \ [1; zeros(n-2); 2] # Chebyshev coefficients
381382
u = P[:,1:n]*cfs # interpret in basis
382383
@test u[0.1] (3cos(0.1)sec(1) + csc(1)sin(0.1))/2
384+
end
385+
386+
@testset "Auto-diff" begin
387+
U = Ultraspherical(1)
388+
C = Ultraspherical(2)
389+
390+
f = x -> Chebyshev{eltype(x)}()[x,5]
391+
@test ForwardDiff.derivative(f,0.1) 4*U[0.1,4]
392+
f = x -> Chebyshev{eltype(x)}()[x,5][1]
393+
@test ForwardDiff.gradient(f,[0.1]) [4*U[0.1,4]]
394+
@test ForwardDiff.hessian(f,[0.1]) [8*C[0.1,3]]
395+
396+
f = x -> Chebyshev{eltype(x)}()[x,1:5]
397+
@test ForwardDiff.derivative(f,0.1) [0;(1:4).*U[0.1,1:4]]
383398
end

0 commit comments

Comments
 (0)