54
54
@inline _plan_mul! (y:: AbstractArray{T} , P:: Plan{T} , x:: StridedArray{T} ) where T = mul! (y, P, x)
55
55
@inline _plan_mul! (y:: AbstractArray{T} , P:: Plan{T} , x:: AbstractArray ) where T = mul! (y, P, convert (Array{T}, x))
56
56
57
+ function applydim! (op!, X:: AbstractArray , Rpre, Rpost, ind)
58
+ for Ipost in Rpost, Ipre in Rpre
59
+ v = view (X, Ipre, ind, Ipost)
60
+ op! (v)
61
+ end
62
+ X
63
+ end
57
64
58
65
for op in (:ldiv , :lmul )
59
- op_dim_begin! = Symbol (string (op) * " _dim_begin!" )
60
- op_dim_end! = Symbol (string (op) * " _dim_end!" )
61
- op! = Symbol (string (op) * " ! " )
66
+ op_dim_begin! = Symbol (op, : _dim_begin! )
67
+ op_dim_end! = Symbol (op, : _dim_end! )
68
+ op! = Symbol (op, : ! )
62
69
@eval begin
63
- function $op_dim_begin! (α, d:: Number , y:: AbstractArray{<:Any,N} ) where N
70
+ function $op_dim_begin! (α, d:: Number , y:: AbstractArray )
64
71
# scale just the d-th dimension by permuting it to the first
65
- ỹ = PermutedDimsArray (y, _permfirst (d, N))
66
- $ op! (α, view (ỹ, 1 , ntuple (_ -> :, Val (N- 1 ))... ))
72
+ Rpre = CartesianIndices (axes (y)[1 : d- 1 ])
73
+ Rpost = CartesianIndices (axes (y)[d+ 1 : end ])
74
+ applydim! (v -> $ op! (α, v), y, Rpre, Rpost, 1 )
67
75
end
68
76
69
- function $op_dim_end! (α, d:: Number , y:: AbstractArray{<:Any,N} ) where N
77
+ function $op_dim_end! (α, d:: Number , y:: AbstractArray )
70
78
# scale just the d-th dimension by permuting it to the first
71
- ỹ = PermutedDimsArray (y, _permfirst (d, N))
72
- $ op! (α, view (ỹ, size (ỹ,1 ), ntuple (_ -> :, Val (N- 1 ))... ))
79
+ Rpre = CartesianIndices (axes (y)[1 : d- 1 ])
80
+ Rpost = CartesianIndices (axes (y)[d+ 1 : end ])
81
+ applydim! (v -> $ op! (α, v), y, Rpre, Rpost, size (y, d))
73
82
end
74
83
end
75
84
end
@@ -366,32 +375,35 @@ end
366
375
367
376
_permfirst (d, N) = [d; 1 : d- 1 ; d+ 1 : N]
368
377
369
- @inline function _chebu1_prescale! (d:: Number , X:: AbstractArray{T,N} ) where {T,N}
370
- X̃ = PermutedDimsArray (X, _permfirst (d, N))
371
- m = size (X̃,1 )
372
- X̃ .= (sinpi .(one (T)/ (2 m) .+ ((1 : m) .- one (T))/ m) ./ m) .* X̃
373
- X
374
- end
375
-
376
- @inline function _chebu1_prescale! (d, y:: AbstractArray )
377
- for k in d
378
- _chebu1_prescale! (k, y)
378
+ for f in [:_chebu1_prescale! , :_chebu1_postscale! , :_chebu2_prescale! , :_chebu2_postscale! ,
379
+ :_ichebu1_postscale! ]
380
+ _f = Symbol (:_ , f)
381
+ @eval begin
382
+ @inline function $f (d:: Number , X:: AbstractArray )
383
+ Rpre = CartesianIndices (axes (X)[1 : d- 1 ])
384
+ Rpost = CartesianIndices (axes (X)[d+ 1 : end ])
385
+ $ _f (d, X, Rpre, Rpost)
386
+ X
387
+ end
388
+ @inline function $f (d, y:: AbstractArray )
389
+ for k in d
390
+ $ f (k, y)
391
+ end
392
+ y
393
+ end
379
394
end
380
- y
381
395
end
382
396
383
- @inline function _chebu1_postscale! (d:: Number , X:: AbstractArray{T,N} ) where {T,N}
384
- X̃ = PermutedDimsArray (X, _permfirst (d, N))
385
- m = size (X̃,1 )
386
- X̃ .= X̃ ./ (sinpi .(one (T)/ (2 m) .+ ((1 : m) .- one (T))/ m) ./ m)
387
- X
397
+ function __chebu1_prescale! (d:: Number , X:: AbstractArray{T} , Rpre, Rpost) where {T}
398
+ m = size (X,d)
399
+ r = one (T)/ (2 m) .+ ((1 : m) .- one (T)). / m
400
+ applydim! (v -> v .*= sinpi .(r) ./ m, X, Rpre, Rpost, :)
388
401
end
389
402
390
- @inline function _chebu1_postscale! (d, y:: AbstractArray )
391
- for k in d
392
- _chebu1_postscale! (k, y)
393
- end
394
- y
403
+ @inline function __chebu1_postscale! (d:: Number , X:: AbstractArray{T} , Rpre, Rpost) where {T}
404
+ m = size (X,d)
405
+ r = one (T)/ (2 m) .+ ((1 : m) .- one (T)). / m
406
+ applydim! (v -> v ./= sinpi .(r) ./ m, X, Rpre, Rpost, :)
395
407
end
396
408
397
409
function * (P:: ChebyshevUTransformPlan{T,1,K,true,N} , x:: AbstractArray{T,N} ) where {T,K,N}
@@ -413,35 +425,18 @@ function mul!(y::AbstractArray{T}, P::ChebyshevUTransformPlan{T,1,K,false}, x::A
413
425
end
414
426
415
427
416
- @inline function _chebu2_prescale! (d:: Number , X:: AbstractArray{T,N} ) where {T,N}
417
- X̃ = PermutedDimsArray (X, _permfirst (d, N))
418
- m = size (X̃,1 )
428
+ @inline function __chebu2_prescale! (d, X:: AbstractArray{T} , Rpre, Rpost) where {T}
429
+ m = size (X,d)
419
430
c = one (T)/ (m+ 1 )
420
- X̃ .= sinpi .((1 : m) .* c) .* X̃
421
- X
422
- end
423
-
424
- @inline function _chebu2_prescale! (d, y:: AbstractArray )
425
- for k in d
426
- _chebu2_prescale! (k, y)
427
- end
428
- y
431
+ r = (1 : m) .* c
432
+ applydim! (v -> v .*= sinpi .(r), X, Rpre, Rpost, :)
429
433
end
430
434
431
-
432
- @inline function _chebu2_postscale! (d:: Number , X:: AbstractArray{T,N} ) where {T,N}
433
- X̃ = PermutedDimsArray (X, _permfirst (d, N))
434
- m = size (X̃,1 )
435
+ @inline function __chebu2_postscale! (d:: Number , X:: AbstractArray{T} , Rpre, Rpost) where {T}
436
+ m = size (X,d)
435
437
c = one (T)/ (m+ 1 )
436
- X̃ .= X̃ ./ sinpi .((1 : m) .* c)
437
- X
438
- end
439
-
440
- @inline function _chebu2_postscale! (d, y:: AbstractArray )
441
- for k in d
442
- _chebu2_postscale! (k, y)
443
- end
444
- y
438
+ r = (1 : m) .* c
439
+ applydim! (v -> v ./= sinpi .(r), X, Rpre, Rpost, :)
445
440
end
446
441
447
442
function * (P:: ChebyshevUTransformPlan{T,2,K,true,N} , x:: AbstractArray{T,N} ) where {T,K,N}
@@ -525,19 +520,10 @@ inv(P::IChebyshevUTransformPlan{T,2}) where {T} = ChebyshevUTransformPlan{T,2}(P
525
520
inv (P:: ChebyshevUTransformPlan{T,1} ) where {T} = IChebyshevUTransformPlan {T,1} (inv (P. plan). p)
526
521
inv (P:: IChebyshevUTransformPlan{T,1} ) where {T} = ChebyshevUTransformPlan {T,1} (inv (P. plan). p)
527
522
528
- @inline function _ichebu1_postscale! (d:: Number , X:: AbstractArray{T,N} ) where {T,N}
529
- X̃ = PermutedDimsArray (X, _permfirst (d, N))
530
- m = size (X̃,1 )
531
- X̃ .= X̃ ./ (2 .* sinpi .(one (T)/ (2 m) .+ ((1 : m) .- one (T))/ m))
532
- X
533
- end
534
-
535
-
536
- @inline function _ichebu1_postscale! (d, y:: AbstractArray )
537
- for k in d
538
- _ichebu1_postscale! (k, y)
539
- end
540
- y
523
+ @inline function __ichebu1_postscale! (d:: Number , X:: AbstractArray{T} , Rpre, Rpost) where {T}
524
+ m = size (X,d)
525
+ r = one (T)/ (2 m) .+ ((1 : m) .- one (T))/ m
526
+ applydim! (v -> v ./= 2 .* sinpi .(r), X, Rpre, Rpost, :)
541
527
end
542
528
543
529
function * (P:: IChebyshevUTransformPlan{T,1,K,true} , x:: AbstractArray{T} ) where {T<: fftwNumber ,K}
@@ -742,4 +728,4 @@ for pln in (:plan_chebyshevtransform!, :plan_chebyshevtransform,
742
728
$ pln (x:: AbstractArray , dims... ; kws... ) = $ pln (x, Val (1 ), dims... ; kws... )
743
729
$ pln (:: Type{T} , szs, dims... ; kwds... ) where T = $ pln (Array {T} (undef, szs... ), dims... ; kwds... )
744
730
end
745
- end
731
+ end
0 commit comments