Skip to content

Commit 8819a16

Browse files
committed
up to ODETest
1 parent 013597b commit 8819a16

16 files changed

+202
-397
lines changed

src/ApproxFunOrthogonalPolynomials.jl

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module ApproxFunOrthogonalPolynomials
2-
using Base, LinearAlgebra, Reexport, AbstractFFTs, FFTW, InfiniteArrays, FillArrays, FastTransforms, IntervalSets,
3-
DomainSets, Statistics
2+
using Base, LinearAlgebra, Reexport, BandedMatrices, AbstractFFTs, FFTW, InfiniteArrays, FillArrays, FastTransforms, IntervalSets,
3+
DomainSets, Statistics, SpecialFunctions
44

55
@reexport using ApproxFunBase
66

@@ -12,18 +12,20 @@ import ApproxFunBase: normalize!, flipsign, FiniteRange, Fun, MatrixFun, UnsetSp
1212
UnivariateSpace, AmbiguousSpace, SumSpace, SubSpace, WeightSpace, NoSpace, Space,
1313
HeavisideSpace, PointSpace,
1414
IntervalOrSegment, RaggedMatrix, AlmostBandedMatrix,
15-
AnyDomain, ZeroSpace, TrivialInterlacer, BlockInterlacer,
15+
AnyDomain, ZeroSpace, ArraySpace, TrivialInterlacer, BlockInterlacer,
1616
AbstractTransformPlan, TransformPlan, ITransformPlan,
1717
ConcreteConversion, ConcreteMultiplication, ConcreteDerivative, ConcreteIntegral,
1818
ConcreteVolterra, Volterra, VolterraWrapper,
19-
MultiplicationWrapper, ConversionWrapper, DerivativeWrapper, Evaluation,
19+
MultiplicationWrapper, ConversionWrapper, DerivativeWrapper, Evaluation, EvaluationWrapper,
2020
Conversion, Multiplication, Derivative, Integral, bandwidths,
2121
ConcreteEvaluation, ConcreteDefiniteLineIntegral, ConcreteDefiniteIntegral, ConcreteIntegral,
2222
DefiniteLineIntegral, DefiniteIntegral, ConcreteDefiniteIntegral, ConcreteDefiniteLineIntegral,
2323
ReverseOrientation, ReverseOrientationWrapper, ReverseWrapper, Reverse, NegateEven, Dirichlet, ConcreteDirichlet,
2424
TridiagonalOperator, SubOperator, Space, @containsconstants, spacescompatible,
2525
hasfasttransform, canonicalspace, domain, setdomain, prectype, domainscompatible,
26-
plan_transform, plan_itransform, plan_transform!, plan_itransform!, transform, itransform, hasfasttransform, Integral,
26+
plan_transform, plan_itransform, plan_transform!, plan_itransform!, transform, itransform, hasfasttransform,
27+
CanonicalTransformPlan,
28+
Integral,
2729
domainspace, rangespace, boundary,
2830
union_rule, conversion_rule, maxspace_rule, conversion_type, maxspace, hasconversion, points,
2931
rdirichlet, ldirichlet, lneumann, rneumann, ivp, bvp,
@@ -34,14 +36,20 @@ import ApproxFunBase: normalize!, flipsign, FiniteRange, Fun, MatrixFun, UnsetSp
3436
invfromcanonicalD, fromcanonical, tocanonical, fromcanonicalD, tocanonicalD, canonicaldomain, setcanonicaldomain, mappoint,
3537
reverseorientation, checkpoints, evaluate, mul_coefficients, coefficients, isconvertible,
3638
clenshaw, ClenshawPlan, sineshaw,
37-
toeplitz_getindex, toeplitz_axpy!, ToeplitzOperator, hankel_getindex,
39+
toeplitz_getindex, toeplitz_axpy!, sym_toeplitz_axpy!, hankel_axpy!, ToeplitzOperator, SymToeplitzOperator, hankel_getindex,
3840
SpaceOperator, ZeroOperator, InterlaceOperator,
3941
interlace!, reverseeven!, negateeven!, cfstype, pad!,
40-
extremal_args, hesseneigvals, chebyshev_clenshaw, recA, recB, recC, roots, chebmult_getindex, intpow, alternatingsum
42+
extremal_args, hesseneigvals, chebyshev_clenshaw, recA, recB, recC, roots, chebmult_getindex, intpow, alternatingsum,
43+
domaintype, diagindshift, rangetype, weight, isapproxinteger, default_Dirichlet, scal!
4144

4245
import DomainSets: Domain, indomain, UnionDomain, ProductDomain, FullSpace, Point, elements, DifferenceDomain,
4346
Interval, ChebyshevInterval, boundary, ∂, rightendpoint, leftendpoint,
44-
dimension, Domain1d, Domain2d
47+
dimension, Domain1d, Domain2d
48+
49+
import BandedMatrices: bandrange, bandshift,
50+
inbands_getindex, inbands_setindex!, bandwidth, AbstractBandedMatrix,
51+
colstart, colstop, colrange, rowstart, rowstop, rowrange,
52+
bandwidths, _BandedMatrix, BandedMatrix
4553

4654
import Base: values, convert, getindex, setindex!, *, +, -, ==, <, <=, >, |, !, !=, eltype, iterate,
4755
>=, /, ^, \, , transpose, size, reindex, tail, broadcast, broadcast!, copyto!, copy, to_index, (:),
@@ -66,10 +74,26 @@ import FastTransforms: ChebyshevTransformPlan, IChebyshevTransformPlan, plan_che
6674
plan_chebyshevtransform!, plan_ichebyshevtransform, plan_ichebyshevtransform!,
6775
pochhammer
6876

77+
# we need to import all special functions to use Calculus.symbolic_derivatives_1arg
78+
# we can't do importall Base as we replace some Base definitions
79+
import SpecialFunctions: sinpi, cospi, airy, besselh,
80+
asinh, acosh,atanh, erfcx, dawson, erf, erfi,
81+
sin, cos, sinh, cosh, airyai, airybi, airyaiprime, airybiprime,
82+
hankelh1, hankelh2, besselj, besselj0, bessely, besseli, besselk,
83+
besselkx, hankelh1x, hankelh2x, exp2, exp10, log2, log10,
84+
tan, tanh, csc, asin, acsc, sec, acos, asec,
85+
cot, atan, acot, sinh, csch, asinh, acsch,
86+
sech, acosh, asech, tanh, coth, atanh, acoth,
87+
expm1, log1p, lfact, sinc, cosc, erfinv, erfcinv, beta, lbeta,
88+
eta, zeta, gamma, lgamma, polygamma, invdigamma, digamma, trigamma,
89+
abs, sign, log, expm1, tan, abs2, sqrt, angle, max, min, cbrt, log,
90+
atan, acos, asin, erfc, inv
91+
6992
include("ultraspherical.jl")
7093
include("Domains/Domains.jl")
7194
include("Spaces/Spaces.jl")
7295
include("roots.jl")
7396
include("specialfunctions.jl")
97+
include("fastops.jl")
7498

7599
end

src/Spaces/Chebyshev/ChebyshevOperators.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
recA(::Type{T},::Chebyshev,k) where {T} = 2one(T)
2+
recA(::Type{T},::Chebyshev,k) where {T} = k == 0 ? one(T) : 2one(T)
33
recB(::Type{T},::Chebyshev,_) where {T} = zero(T)
44
recC(::Type{T},::Chebyshev,k) where {T} = one(T) # one(T) ensures we get correct type
55

@@ -38,7 +38,7 @@ function evaluatechebyshev(n::Integer,x::T) where T<:Number
3838
end
3939

4040

41-
function getindex(op::ConcreteEvaluation{Chebyshev{DD,RR},typeof(leftendpoint)},j::Integer) where {DD<:IntervalOrSegment,RR}
41+
function getindex(op::ConcreteEvaluation{<:Chebyshev{DD,RR},typeof(leftendpoint)},j::Integer) where {DD<:IntervalOrSegment,RR}
4242
T=eltype(op)
4343
if op.order == 0
4444
ifelse(isodd(j), # right rule
@@ -50,7 +50,7 @@ function getindex(op::ConcreteEvaluation{Chebyshev{DD,RR},typeof(leftendpoint)},
5050
end
5151
end
5252

53-
function getindex(op::ConcreteEvaluation{Chebyshev{DD,RR},typeof(rightendpoint)},j::Integer) where {DD<:IntervalOrSegment,RR}
53+
function getindex(op::ConcreteEvaluation{<:Chebyshev{DD,RR},typeof(rightendpoint)},j::Integer) where {DD<:IntervalOrSegment,RR}
5454
T=eltype(op)
5555
if op.order == 0
5656
one(T)
@@ -60,7 +60,7 @@ function getindex(op::ConcreteEvaluation{Chebyshev{DD,RR},typeof(rightendpoint)}
6060
end
6161
end
6262

63-
function getindex(op::ConcreteEvaluation{Chebyshev{DD,RR},typeof(leftendpoint)},k::AbstractRange) where {DD<:IntervalOrSegment,RR}
63+
function getindex(op::ConcreteEvaluation{<:Chebyshev{DD,RR},typeof(leftendpoint)},k::AbstractRange) where {DD<:IntervalOrSegment,RR}
6464
T=eltype(op)
6565
x = op.x
6666
d = domain(op)
@@ -86,7 +86,7 @@ function getindex(op::ConcreteEvaluation{Chebyshev{DD,RR},typeof(leftendpoint)},
8686
end
8787

8888

89-
function getindex(op::ConcreteEvaluation{Chebyshev{DD,RR},typeof(rightendpoint)},k::AbstractRange) where {DD<:IntervalOrSegment,RR}
89+
function getindex(op::ConcreteEvaluation{<:Chebyshev{DD,RR},typeof(rightendpoint)},k::AbstractRange) where {DD<:IntervalOrSegment,RR}
9090
T=eltype(op)
9191
x = op.x
9292
d = domain(op)

src/Spaces/PolynomialSpace.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ function BandedMatrix(S::SubOperator{T,ConcreteMultiplication{C,PS,T},
201201
# for e_1^⊤ U_x\a == a[1]*I-(α-J)*a[2]/β == (a[1]-α*a[2]/β)*I + J*a[2]/β
202202
# implying
203203
α,β=recα(T,sp,1),recβ(T,sp,1)
204-
ret=Operator{T}(ApproxFun.Recurrence(M.space))[kr,jr]::BandedMatrix{T}
204+
ret=Operator{T}(Recurrence(M.space))[kr,jr]::BandedMatrix{T}
205205
lmul!(a[2]/β,ret)
206206
shft=kr[1]-jr[1]
207207
ret[band(shft)] .+= a[1]-α*a[2]/β
@@ -211,7 +211,7 @@ function BandedMatrix(S::SubOperator{T,ConcreteMultiplication{C,PS,T},
211211
jkr=max(1,min(jr[1],kr[1])-(n-1)÷2):max(jr[end],kr[end])+(n-1)÷2
212212

213213
#Multiplication is transpose
214-
J=Operator{T}(ApproxFun.Recurrence(M.space))[jkr,jkr]
214+
J=Operator{T}(Recurrence(M.space))[jkr,jkr]
215215

216216
B=n-1 # final bandwidth
217217

@@ -318,14 +318,14 @@ end
318318
function getindex(op::ConcreteEvaluation{J,typeof(leftendpoint)},kr::AbstractRange) where J<:PolynomialSpace
319319
sp=op.space
320320
T=eltype(op)
321-
321+
@assert op.order == 0
322322
forwardrecurrence(T,sp,kr.-1,-one(T))
323323
end
324324

325325
function getindex(op::ConcreteEvaluation{J,typeof(rightendpoint)},kr::AbstractRange) where J<:PolynomialSpace
326326
sp=op.space
327327
T=eltype(op)
328-
328+
@assert op.order == 0
329329
forwardrecurrence(T,sp,kr.-1,one(T))
330330
end
331331

@@ -334,8 +334,8 @@ function getindex(op::ConcreteEvaluation{J,TT},kr::AbstractRange) where {J<:Poly
334334
sp=op.space
335335
T=eltype(op)
336336
x=op.x
337-
338-
forwardrecurrence(T,sp,kr.-1,tocanonical(sp,x))
337+
@assert op.order == 0
338+
forwardrecurrence(T,sp,kr .- 1,tocanonical(sp,x))
339339
end
340340

341341

src/fastops.jl

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
###
2+
# This file contains BLAS/BandedMatrix overrides for operators
3+
# that depend on the structure of BandedMatrix
4+
####
5+
6+
7+
8+
9+
#####
10+
# Conversions
11+
#####
12+
13+
function BandedMatrix(S::SubOperator{T,ConcreteConversion{Chebyshev{DD,RR},Ultraspherical{Int,DD,RR},T},
14+
Tuple{UnitRange{Int},UnitRange{Int}}}) where {T,DD,RR}
15+
# we can assume order is 1
16+
ret = BandedMatrix{eltype(S)}(undef, size(S), bandwidths(S))
17+
kr,jr = parentindices(S)
18+
dg = diagindshift(S)
19+
20+
@assert -bandwidth(ret,1) dg  bandwidth(ret,2)-2
21+
22+
ret[band(dg)] .= 0.5
23+
ret[band(dg+1)] .= 0.0
24+
ret[band(dg+2)] .= -0.5
25+
26+
# correct first entry
27+
if 1 in kr && 1 in jr
28+
ret[1,1] = 1.0
29+
end
30+
31+
ret
32+
end
33+
34+
function BandedMatrix(V::SubOperator{T,ConcreteConversion{Ultraspherical{LT,DD,RR},Ultraspherical{LT,DD,RR},T},
35+
Tuple{UnitRange{Int},UnitRange{Int}}}) where {T,LT,DD,RR}
36+
37+
n,m = size(V)
38+
V_l, V_u = bandwidths(V)
39+
ret = BandedMatrix{eltype(V)}(undef, (n,m), (V_l,V_u))
40+
kr,jr = parentindices(V)
41+
dg = diagindshift(V)
42+
43+
44+
λ = order(rangespace(parent(V)))
45+
c = λ-one(T)
46+
47+
# need to drop columns
48+
49+
50+
51+
1-n  dg  m-1 && (ret[band(dg)] .= c./(jr[max(0,dg)+1:min(n+dg,m)] .- 2 .+ λ))
52+
1-n  dg+1  m-1 && (ret[band(dg+1)] .= 0)
53+
1-n  dg+2  m-1 && (ret[band(dg+2)] .= c./(2 .- λ .- jr[max(0,dg+2)+1:min(n+dg+2,m)]))
54+
55+
ret
56+
end
57+
58+
59+
#####
60+
# Derivatives
61+
#####
62+
63+
64+
65+
function BandedMatrix(S::SubOperator{T,ConcreteDerivative{Chebyshev{DD,RR},K,T},
66+
Tuple{UnitRange{Int},UnitRange{Int}}}) where {T,K,DD,RR}
67+
68+
n,m = size(S)
69+
ret = BandedMatrix{eltype(S)}(undef, (n,m), bandwidths(S))
70+
kr,jr = parentindices(S)
71+
dg = diagindshift(S)
72+
73+
D = parent(S)
74+
k = D.order
75+
d = domain(D)
76+
77+
C=convert(T,pochhammer(one(T),k-1)/2*(4/(complexlength(d)))^k)
78+
79+
80+
# need to drop columns
81+
82+
83+
if 1-n dg+k m-1
84+
ret[band(dg+k)] .= C.*(jr[max(0,dg+k)+1:min(n+dg+k,m)] .- one(T))
85+
end
86+
87+
ret
88+
end
89+
90+
91+
function BandedMatrix(S::SubOperator{T,ConcreteDerivative{Ultraspherical{LT,DD,RR},K,T},
92+
Tuple{UnitRange{Int},UnitRange{Int}}}) where {T,K,DD,RR,LT}
93+
n,m = size(S)
94+
ret = BandedMatrix{eltype(S)}(undef, (n,m), bandwidths(S))
95+
kr,jr = parentindices(S)
96+
dg = diagindshift(S)
97+
98+
D = parent(S)
99+
k = D.order
100+
λ = order(domainspace(D))
101+
d = domain(D)
102+
103+
C = convert(T,pochhammer(one(T)*λ,k)*(4/(complexlength(d)))^k)
104+
ret[band(dg+k)] .= C
105+
106+
ret
107+
end
108+

test/ChebyshevTest.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
using ApproxFunOrthogonalPolynomials, ApproxFunBase, LinearAlgebra, Test
2-
import ApproxFunBase: testspace
2+
import ApproxFunBase: testspace, recA, recB, recC
3+
import ApproxFunOrthogonalPolynomials: forwardrecurrence
34

45
@testset "Chebyshev" begin
6+
@testset "Forward recurrence" begin
7+
@test forwardrecurrence(Float64,Chebyshev(),0:9,1.0) == ones(10)
8+
end
9+
510
@testset "ChebyshevInterval" begin
611
@test Fun(x->2,10)(.1) 2
712
@test Fun(x->2)(.1) 2
@@ -151,6 +156,7 @@ using ApproxFunOrthogonalPolynomials, ApproxFunBase, LinearAlgebra, Test
151156
x = Fun(identity,0..10)
152157
f = sin(x^2)
153158
g = cos(x)
159+
@test exp(x)(0.1) exp(0.1)
154160
@test f(.1) sin(.1^2)
155161

156162
x = Fun(identity,0..100)
@@ -160,7 +166,7 @@ using ApproxFunOrthogonalPolynomials, ApproxFunBase, LinearAlgebra, Test
160166

161167
@testset "Reverse" begin
162168
f=Fun(exp)
163-
@test ApproxFunOrthogonalPolynomials.default_Fun(f, Chebyshev(Segment(1 , -1)), ncoefficients(f))(0.1) exp(0.1)
169+
@test ApproxFunBase.default_Fun(f, Chebyshev(Segment(1 , -1)), ncoefficients(f))(0.1) exp(0.1)
164170
@test Fun(f,Chebyshev(Segment(1,-1)))(0.1) f(0.1)
165171
end
166172

test/ComplexTest.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ApproxFun, Test
1+
using ApproxFunOrthogonalPolynomials, Test
22

33
@testset "Complex" begin
44
@testset "Differentiation" begin

test/EigTest.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using ApproxFun, BandedMatrices, SpecialFunctions, Test
2-
import ApproxFun: bandwidth
1+
using ApproxFunOrthogonalPolynomials, ApproxFunBase, BandedMatrices, SpecialFunctions, Test
2+
import ApproxFunBase: bandwidth
33

44
#
55
# Fix for BigFloat stackoverflow

0 commit comments

Comments
 (0)