@@ -17,13 +17,10 @@ ChebyshevTransformPlan{k,inp}(plan) where {k,inp} =
17
17
18
18
function plan_chebyshevtransform! (x:: AbstractVector{T} ; kind:: Integer = 1 ) where T<: fftwNumber
19
19
if kind == 1
20
- plan = plan_r2r! (x, REDFT10)
20
+ plan = isempty (x) ? fill ( one (T), 1 , length (x)) : plan_r2r! (x, REDFT10)
21
21
ChebyshevTransformPlan {1,true} (plan)
22
22
elseif kind == 2
23
- if length (x) ≤ 1
24
- error (" Cannot create a length $(length (x)) chebyshev transform" )
25
- end
26
- plan = plan_r2r! (x, REDFT00)
23
+ plan = length (x) ≤ 1 ? fill (one (T),1 ,length (x)) : plan_r2r! (x, REDFT00)
27
24
ChebyshevTransformPlan {2,true} (plan)
28
25
end
29
26
end
35
32
36
33
function * (P:: ChebyshevTransformPlan{T,1,true} ,x:: AbstractVector{T} ) where T
37
34
n = length (x)
38
- if n == 1
39
- x
40
- else
41
- x = P. plan* x
42
- x[1 ]/= 2
43
- lmul! (inv (convert (T,n)), x)
44
- end
35
+ n ≤ 1 && return x
36
+
37
+ x = P. plan* x
38
+ x[1 ] /= 2
39
+ lmul! (inv (convert (T,n)), x)
45
40
end
46
41
47
- function * (P:: ChebyshevTransformPlan{T,2,true} ,x:: AbstractVector{T} ) where T
42
+ function * (P:: ChebyshevTransformPlan{T,2,true} , x:: AbstractVector{T} ) where T
48
43
n = length (x)
49
- if n == 1
50
- x
51
- else
52
- n = length (x)
53
- if n == 1
54
- x
55
- else
56
- x = P. plan* x
57
- x[1 ] /= 2 ;x[end ] /= 2
58
- lmul! (inv (convert (T,n- 1 )),x)
59
- end
60
- end
44
+ n ≤ 1 && return x
45
+
46
+ x = P. plan* x
47
+ x[1 ] /= 2 ; x[end ] /= 2
48
+ lmul! (inv (convert (T,n- 1 )),x)
61
49
end
62
50
63
51
chebyshevtransform! (x:: AbstractVector{T} ;kind:: Integer = 1 ) where {T<: fftwNumber } =
@@ -88,15 +76,9 @@ inv(P::IChebyshevTransformPlan{T,2,true}) where T = P.plan
88
76
89
77
function plan_ichebyshevtransform! (x:: AbstractVector{T} ;kind:: Integer = 1 ) where T<: fftwNumber
90
78
if kind == 1
91
- if length (x) == 0
92
- error (" Cannot create a length 0 inverse chebyshev transform" )
93
- end
94
- plan = plan_r2r! (x, REDFT01)
79
+ plan = isempty (x) ? fill (one (T),1 ,length (x)) : plan_r2r! (x, REDFT01)
95
80
IChebyshevTransformPlan {T,1,true,typeof(plan)} (plan)
96
81
elseif kind == 2
97
- if length (x) ≤ 1
98
- error (" Cannot create a length $(length (x)) inverse chebyshev transform" )
99
- end
100
82
inv (plan_chebyshevtransform! (x;kind= 2 ))
101
83
end
102
84
end
@@ -107,28 +89,25 @@ function plan_ichebyshevtransform(x::AbstractVector{T};kind::Integer=1) where T<
107
89
end
108
90
109
91
function * (P:: IChebyshevTransformPlan{T,1,true} ,x:: AbstractVector{T} ) where T<: fftwNumber
92
+ isempty (x) && return x
110
93
x[1 ] *= 2
111
- x = lmul! (convert (T,0.5 ),P. plan* x)
94
+ x = lmul! (convert (T,0.5 ), P. plan* x)
112
95
x
113
96
end
114
97
115
98
function * (P:: IChebyshevTransformPlan{T,2,true} ,x:: AbstractVector{T} ) where T<: fftwNumber
116
99
n = length (x)
117
- if n == 1
118
- x
119
- else
120
- # #TODO : make thread safe
121
- x[1 ] *= 2 ;x[end ] *= 2
122
- x = P. plan* x
123
- x[1 ] *= 2 ;x[end ] *= 2
124
- lmul! (convert (T,.5 (n- 1 )),x)
125
- end
100
+ n ≤ 1 && return x
101
+ x[1 ] *= 2 ; x[end ] *= 2
102
+ x = P. plan* x
103
+ x[1 ] *= 2 ; x[end ] *= 2
104
+ lmul! (convert (T,0.5 (n- 1 )),x)
126
105
end
127
106
128
107
ichebyshevtransform! (x:: AbstractVector{T} ;kind:: Integer = 1 ) where {T<: fftwNumber } =
129
108
plan_ichebyshevtransform! (x;kind= kind)* x
130
109
131
- ichebyshevtransform (x;kind:: Integer = 1 ) = ichebyshevtransform! (copy (x);kind= kind)
110
+ ichebyshevtransform (x;kind:: Integer = 1 ) = ichebyshevtransform! (copy (x); kind= kind)
132
111
133
112
* (P:: IChebyshevTransformPlan{T,k,false} ,x:: AbstractVector{T} ) where {T,k} = P. plan* copy (x)
134
113
142
121
# Matrix inputs
143
122
144
123
145
- function chebyshevtransform! (X:: AbstractMatrix{T} ;kind:: Integer = 1 ) where T<: fftwNumber
124
+ function chebyshevtransform! (X:: AbstractMatrix{T} ; kind:: Integer = 1 ) where T<: fftwNumber
146
125
if kind == 1
147
126
if size (X) == (1 ,1 )
148
127
X
@@ -164,7 +143,7 @@ function chebyshevtransform!(X::AbstractMatrix{T};kind::Integer=1) where T<:fftw
164
143
end
165
144
end
166
145
167
- function ichebyshevtransform! (X:: AbstractMatrix{T} ;kind:: Integer = 1 ) where T<: fftwNumber
146
+ function ichebyshevtransform! (X:: AbstractMatrix{T} ; kind:: Integer = 1 ) where T<: fftwNumber
168
147
if kind == 1
169
148
if size (X) == (1 ,1 )
170
149
X
@@ -200,13 +179,10 @@ ChebyshevUTransformPlan{k,inp}(plan) where {k,inp} =
200
179
201
180
function plan_chebyshevutransform! (x:: AbstractVector{T} ; kind:: Integer = 1 ) where T<: fftwNumber
202
181
if kind == 1
203
- plan = plan_r2r! (x, RODFT10)
182
+ plan = isempty (x) ? fill ( one (T), 1 , length (x)) : plan_r2r! (x, RODFT10)
204
183
ChebyshevUTransformPlan {1,true} (plan)
205
184
elseif kind == 2
206
- if length (x) ≤ 1
207
- error (" Cannot create a length $(length (x)) chebyshevu transform" )
208
- end
209
- plan = plan_r2r! (x, RODFT00)
185
+ plan = length (x) ≤ 1 ? fill (one (T),1 ,length (x)) : plan_r2r! (x, RODFT00)
210
186
ChebyshevUTransformPlan {2,true} (plan)
211
187
end
212
188
end
218
194
219
195
function * (P:: ChebyshevUTransformPlan{T,1,true} ,x:: AbstractVector{T} ) where T
220
196
n = length (x)
197
+ n ≤ 1 && return x
198
+
221
199
for k= 1 : n # sqrt(1-x_j^2) weight
222
200
x[k] *= sinpi (one (T)/ (2 n) + (k- one (T))/ n)/ n
223
201
end
226
204
227
205
function * (P:: ChebyshevUTransformPlan{T,2,true} ,x:: AbstractVector{T} ) where T
228
206
n = length (x)
207
+ n ≤ 1 && return x
208
+
229
209
c = one (T)/ (n+ 1 )
230
210
for k= 1 : n # sqrt(1-x_j^2) weight
231
211
x[k] *= sinpi (k* c)
@@ -247,18 +227,13 @@ struct IChebyshevUTransformPlan{T,kind,inplace,P}
247
227
plan:: P
248
228
end
249
229
230
+
250
231
function plan_ichebyshevutransform! (x:: AbstractVector{T} ;kind:: Integer = 1 ) where T<: fftwNumber
251
232
if kind == 1
252
- if length (x) == 0
253
- error (" Cannot create a length 0 inverse chebyshevu transform" )
254
- end
255
- plan = plan_r2r! (x, RODFT01)
233
+ plan = isempty (x) ? fill (one (T),1 ,length (x)) : plan_r2r! (x, RODFT01)
256
234
IChebyshevUTransformPlan {T,1,true,typeof(plan)} (plan)
257
235
elseif kind == 2
258
- if length (x) ≤ 1
259
- error (" Cannot create a length $(length (x)) inverse chebyshevu transform" )
260
- end
261
- plan = plan_r2r! (x, RODFT00)
236
+ plan = length (x) ≤ 1 ? fill (one (T),1 ,length (x)) : plan_r2r! (x, RODFT00)
262
237
IChebyshevUTransformPlan {T,2,true,typeof(plan)} (plan)
263
238
end
264
239
end
270
245
271
246
function * (P:: IChebyshevUTransformPlan{T,1,true} , x:: AbstractVector{T} ) where T<: fftwNumber
272
247
n = length (x)
248
+ n ≤ 1 && return x
249
+
273
250
x = P. plan * x
274
251
for k= 1 : n # sqrt(1-x_j^2) weight
275
252
x[k] /= 2 sinpi (one (T)/ (2 n) + (k- one (T))/ n)
281
258
282
259
function * (P:: IChebyshevUTransformPlan{T,2,true} , x:: AbstractVector{T} ) where T<: fftwNumber
283
260
n = length (x)
261
+ n ≤ 1 && return x
262
+
284
263
c = one (T)/ (n+ 1 )
285
264
lmul! ((n+ 1 )/ (2 n+ 2 * one (T)), x)
286
265
x = P. plan * x
@@ -312,7 +291,7 @@ function chebyshevpoints(::Type{T}, n::Integer; kind::Int=1) where T<:Number
312
291
if kind == 1
313
292
T[sinpi ((n- 2 k- one (T))/ 2 n) for k= 0 : n- 1 ]
314
293
elseif kind == 2
315
- if n== 1
294
+ if n == 1
316
295
zeros (T,1 )
317
296
else
318
297
T[cospi (k/ (n- one (T))) for k= 0 : n- 1 ]
@@ -323,19 +302,19 @@ chebyshevpoints(n::Integer; kind::Int=1) = chebyshevpoints(Float64, n; kind=kind
323
302
324
303
325
304
# sin(nθ) coefficients to values at Clenshaw-Curtis nodes except ±1
326
-
327
- struct DSTPlan{T,kind,inplace,P} <: Plan{T}
328
- plan:: P
329
- end
330
-
331
- DSTPlan {k,inp} (plan) where {k,inp} =
332
- DSTPlan {eltype(plan),k,inp,typeof(plan)} (plan)
333
-
334
-
335
- plan_DSTI! (x) = length (x) > 0 ? DSTPlan {1,true} (FFTW. plan_r2r! (x, FFTW. RODFT00)) :
336
- ones (x) '
337
-
338
- function * (P:: DSTPlan{T,1} , x:: AbstractArray ) where {T}
339
- x = P. plan* x
340
- rmul! (x,half (T))
341
- end
305
+ #
306
+ # struct DSTPlan{T,kind,inplace,P} <: Plan{T}
307
+ # plan::P
308
+ # end
309
+ #
310
+ # DSTPlan{k,inp}(plan) where {k,inp} =
311
+ # DSTPlan{eltype(plan),k,inp,typeof(plan)}(plan)
312
+ #
313
+ #
314
+ # plan_DSTI!(x) = length(x) > 0 ? DSTPlan{1,true}(FFTW.plan_r2r!(x, FFTW.RODFT00)) :
315
+ # fill(one(T),1,length(x))
316
+ #
317
+ # function *(P::DSTPlan{T,1}, x::AbstractArray) where {T}
318
+ # x = P.plan*x
319
+ # rmul!(x,half(T))
320
+ # end
0 commit comments