Skip to content

Commit a929128

Browse files
committed
applydim in ToeplitzPlan
1 parent 809aee7 commit a929128

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

src/chebyshevtransform.jl

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ function applydim!(op!, X::AbstractArray, Rpre, Rpost, ind)
6161
end
6262
X
6363
end
64+
function applydim!(op!, X::AbstractArray, d::Integer, ind)
65+
Rpre = CartesianIndices(axes(X)[1:d-1])
66+
Rpost = CartesianIndices(axes(X)[d+1:end])
67+
applydim!(op!, X, Rpre, Rpost, ind)
68+
end
6469

6570
for op in (:ldiv, :lmul)
6671
op_dim_begin! = Symbol(op, :_dim_begin!)
@@ -70,17 +75,13 @@ for op in (:ldiv, :lmul)
7075
function $op_dim_begin!(α, d::Number, y::AbstractArray)
7176
# scale just the d-th dimension by permuting it to the first
7277
d 1:ndims(y) || throw(ArgumentError("dimension $d must lie between 1 and $(ndims(y))"))
73-
Rpre = CartesianIndices(axes(y)[1:d-1])
74-
Rpost = CartesianIndices(axes(y)[d+1:end])
75-
applydim!(v -> $op!(α, v), y, Rpre, Rpost, 1)
78+
applydim!(v -> $op!(α, v), y, d, 1)
7679
end
7780

7881
function $op_dim_end!(α, d::Number, y::AbstractArray)
7982
# scale just the d-th dimension by permuting it to the first
8083
d 1:ndims(y) || throw(ArgumentError("dimension $d must lie between 1 and $(ndims(y))"))
81-
Rpre = CartesianIndices(axes(y)[1:d-1])
82-
Rpost = CartesianIndices(axes(y)[d+1:end])
83-
applydim!(v -> $op!(α, v), y, Rpre, Rpost, size(y, d))
84+
applydim!(v -> $op!(α, v), y, d, size(y, d))
8485
end
8586
end
8687
end
@@ -383,9 +384,7 @@ for f in [:_chebu1_prescale!, :_chebu1_postscale!, :_chebu2_prescale!, :_chebu2_
383384
@eval begin
384385
@inline function $f(d::Number, X::AbstractArray)
385386
d 1:ndims(X) || throw("dimension $d must lie between 1 and $(ndims(X))")
386-
Rpre = CartesianIndices(axes(X)[1:d-1])
387-
Rpost = CartesianIndices(axes(X)[d+1:end])
388-
$_f(d, X, Rpre, Rpost)
387+
$_f(d, X)
389388
X
390389
end
391390
@inline function $f(d, y::AbstractArray)
@@ -397,16 +396,16 @@ for f in [:_chebu1_prescale!, :_chebu1_postscale!, :_chebu2_prescale!, :_chebu2_
397396
end
398397
end
399398

400-
function __chebu1_prescale!(d::Number, X::AbstractArray{T}, Rpre, Rpost) where {T}
399+
function __chebu1_prescale!(d::Number, X::AbstractArray{T}) where {T}
401400
m = size(X,d)
402401
r = one(T)/(2m) .+ ((1:m) .- one(T))./m
403-
applydim!(v -> v .*= sinpi.(r) ./ m, X, Rpre, Rpost, :)
402+
applydim!(v -> v .*= sinpi.(r) ./ m, X, d, :)
404403
end
405404

406-
@inline function __chebu1_postscale!(d::Number, X::AbstractArray{T}, Rpre, Rpost) where {T}
405+
@inline function __chebu1_postscale!(d::Number, X::AbstractArray{T}) where {T}
407406
m = size(X,d)
408407
r = one(T)/(2m) .+ ((1:m) .- one(T))./m
409-
applydim!(v -> v ./= sinpi.(r) ./ m, X, Rpre, Rpost, :)
408+
applydim!(v -> v ./= sinpi.(r) ./ m, X, d, :)
410409
end
411410

412411
function *(P::ChebyshevUTransformPlan{T,1,K,true,N}, x::AbstractArray{T,N}) where {T,K,N}
@@ -428,18 +427,18 @@ function mul!(y::AbstractArray{T}, P::ChebyshevUTransformPlan{T,1,K,false}, x::A
428427
end
429428

430429

431-
@inline function __chebu2_prescale!(d, X::AbstractArray{T}, Rpre, Rpost) where {T}
430+
@inline function __chebu2_prescale!(d, X::AbstractArray{T}) where {T}
432431
m = size(X,d)
433432
c = one(T)/ (m+1)
434433
r = (1:m) .* c
435-
applydim!(v -> v .*= sinpi.(r), X, Rpre, Rpost, :)
434+
applydim!(v -> v .*= sinpi.(r), X, d, :)
436435
end
437436

438-
@inline function __chebu2_postscale!(d::Number, X::AbstractArray{T}, Rpre, Rpost) where {T}
437+
@inline function __chebu2_postscale!(d::Number, X::AbstractArray{T}) where {T}
439438
m = size(X,d)
440439
c = one(T)/ (m+1)
441440
r = (1:m) .* c
442-
applydim!(v -> v ./= sinpi.(r), X, Rpre, Rpost, :)
441+
applydim!(v -> v ./= sinpi.(r), X, d, :)
443442
end
444443

445444
function *(P::ChebyshevUTransformPlan{T,2,K,true,N}, x::AbstractArray{T,N}) where {T,K,N}
@@ -523,10 +522,10 @@ inv(P::IChebyshevUTransformPlan{T,2}) where {T} = ChebyshevUTransformPlan{T,2}(P
523522
inv(P::ChebyshevUTransformPlan{T,1}) where {T} = IChebyshevUTransformPlan{T,1}(inv(P.plan).p)
524523
inv(P::IChebyshevUTransformPlan{T,1}) where {T} = ChebyshevUTransformPlan{T,1}(inv(P.plan).p)
525524

526-
@inline function __ichebu1_postscale!(d::Number, X::AbstractArray{T}, Rpre, Rpost) where {T}
525+
@inline function __ichebu1_postscale!(d::Number, X::AbstractArray{T}) where {T}
527526
m = size(X,d)
528527
r = one(T)/(2m) .+ ((1:m) .- one(T))/m
529-
applydim!(v -> v ./= 2 .* sinpi.(r), X, Rpre, Rpost, :)
528+
applydim!(v -> v ./= 2 .* sinpi.(r), X, d, :)
530529
end
531530

532531
function *(P::IChebyshevUTransformPlan{T,1,K,true}, x::AbstractArray{T}) where {T<:fftwNumber,K}

src/toeplitzplans.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,11 @@ function *(A::ToeplitzPlan{T,N}, X::AbstractArray{T,N}) where {T,N}
6161

6262
# Fourier transform each dimension
6363
dft * Y
64-
64+
6565
# Multiply by a diagonal matrix along each dimension by permuting
6666
# to first dimension
6767
for (vc,d) in zip(vcs,dims)
68-
= PermutedDimsArray(Y, _permfirst(d, N))
69-
Ỹ .= vc .*
68+
applydim!(v -> v .= vc .* v, Y, d, :)
7069
end
7170

7271
# Transform back

0 commit comments

Comments
 (0)