1
+ module ApproxFunDualNumbersExt
2
+
3
+ using DualNumbers
4
+ using ApproxFun
5
+ using ApproxFun: TransformPlan, ITransformPlan
6
+ import ApproxFunBase: valsdomain_type_promote
7
+ using DomainSets
8
+ import FastTransforms: ChebyshevTransformPlan, plan_chebyshevtransform,
9
+ plan_chebyshevtransform!, plan_ichebyshevtransform,
10
+ plan_ichebyshevtransform!
11
+
1
12
# Dual number support. Should there be realpart and dualpart of Space and Domain?
2
13
DualNumbers. realpart (f:: Fun{S,T} ) where {S,T<: Dual } = Fun (space (f),realpart .(coefficients (f)))
3
14
DualNumbers. dualpart (f:: Fun{S,T} ) where {S,T<: Dual } = Fun (space (f),dualpart .(coefficients (f)))
4
15
5
16
6
17
DualNumbers. realpart (d:: Segment{<:Dual} ) = Segment (realpart (leftendpoint (d)),realpart (rightendpoint (d)))
7
18
8
- indomain (x:: Number , d:: Segment{<:Dual} ) = in (x,realpart (d))
9
- indomain (x:: Dual , d:: Segment{<:Dual} ) = in (realpart (x),realpart (d))
10
- isempty (d:: Segment{<:Dual} ) = isempty (realpart (d))
19
+ DomainSets . indomain (x:: Number , d:: Segment{<:Dual} ) = in (x,realpart (d))
20
+ DomainSets . indomain (x:: Dual , d:: Segment{<:Dual} ) = in (realpart (x),realpart (d))
21
+ Base . isempty (d:: Segment{<:Dual} ) = isempty (realpart (d))
11
22
12
23
13
24
@@ -33,22 +44,22 @@ plan_ichebyshevtransform(v::AbstractVector{D}, ::Val{kind}) where {D<:Dual,kind}
33
44
34
45
35
46
36
- * (P:: ChebyshevTransformPlan ,v:: AbstractVector{<:Dual} ) = dual .(P* realpart .(v),P* dualpart .(v))
47
+ Base.:( * ) (P:: ChebyshevTransformPlan ,v:: AbstractVector{<:Dual} ) = dual .(P* realpart .(v),P* dualpart .(v))
37
48
38
49
# TODO : Hardy{false}
39
50
for (OP,TransPlan) in ((:plan_transform ,:TransformPlan ),(:plan_itransform ,:ITransformPlan )),
40
51
TYP in (:Fourier ,:Laurent ,:SinSpace )
41
52
@eval begin
42
- function $OP (sp:: $TYP{D} ,x:: AbstractVector{T} ) where {T<: Dual ,D<: Domain }
53
+ function ApproxFun . $OP (sp:: $TYP{D} ,x:: AbstractVector{T} ) where {T<: Dual ,D<: Domain }
43
54
plan = $ OP (sp,realpart .(x))
44
55
$ TransPlan {T,typeof(sp),false,typeof(plan)} (sp,plan)
45
56
end
46
- * (P:: $TransPlan{T,$TYP{D},false} ,x:: AbstractVector{T} ) where {T<: Dual ,D<: Domain } =
57
+ Base.:( * ) (P:: $TransPlan{T,$TYP{D},false} ,x:: AbstractVector{T} ) where {T<: Dual ,D<: Domain } =
47
58
dual (P. plan* realpart .(x),P. plan* dualpart .(x))
48
59
end
49
60
end
50
61
51
- chop! (f:: Fun ,d:: Dual )= chop! (f,realpart (d))
62
+ ApproxFun . chop! (f:: Fun ,d:: Dual )= chop! (f,realpart (d))
52
63
53
64
54
65
@@ -62,12 +73,12 @@ function simplifycfs!(cfs::AbstractVector{DD},tol::Float64=4E-16) where DD<:Dual
62
73
end
63
74
64
75
65
- function dualFun (f,S,n)
76
+ function ApproxFun . dualFun (f,S,n)
66
77
pts= points (S,n) + Dual{Float64}[dual (0. ,rand (Bool)) for k= 1 : n]
67
78
Fun (transform (S,map (f,pts)),S)
68
79
end
69
80
70
- function dualcfsFun (f,S)
81
+ function ApproxFun . dualcfsFun (f,S)
71
82
T = real (float (eltype (domain (S))))
72
83
r= checkpoints (S)
73
84
f0= f (first (r))
@@ -84,7 +95,7 @@ function dualcfsFun(f,S)
84
95
for logn = 4 : 20
85
96
n= 2 ^ logn
86
97
87
- cf= dualFun (f,S,n)
98
+ cf = dualFun (f,S,n)
88
99
89
100
if maximum (abs,realpart (cf. coefficients[end - 8 : end ]))< maximum (abs,dualpart (cf. coefficients[end - 8 : end ]))* tol &&
90
101
all (k-> norm (cf (r[k])- fr[k],1 )< 1E-4 ,1 : length (r))
@@ -95,3 +106,5 @@ function dualcfsFun(f,S)
95
106
96
107
Fun (f,S,2 ^ 21 )
97
108
end
109
+
110
+ end
0 commit comments