Skip to content

Commit b17e76d

Browse files
author
ioannisPApapadopoulos
committed
use Base.invperm
1 parent 5bdb5e2 commit b17e76d

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/arrays.jl

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@ function ArrayPlan(F::FTPlan{<:T}, c::AbstractArray{T}, dims::Tuple{<:Int}=(1,))
1313
ArrayPlan(F, size(c), dims)
1414
end
1515

16-
function inv_perm(d::Vector{<:Int})
17-
inv_d = Vector{Int}(undef, length(d))
18-
for (i, val) in enumerate(d)
19-
inv_d[val] = i
20-
end
21-
return inv_d
22-
end
23-
inv_perm(d::Tuple) = inv_perm([d...])
24-
2516
function *(P::ArrayPlan, f::AbstractArray)
2617
F, dims, szs = P.F, P.dims, P.szs
2718
@assert length(dims) == 1
@@ -33,7 +24,7 @@ function *(P::ArrayPlan, f::AbstractArray)
3324

3425
fr = reshape(fp, size(fp,1), :)
3526

36-
permutedims(reshape(F*fr, size(fp)...), inv_perm(perm))
27+
permutedims(reshape(F*fr, size(fp)...), invperm(perm))
3728
end
3829

3930
function \(P::ArrayPlan, f::AbstractArray)
@@ -47,7 +38,7 @@ function \(P::ArrayPlan, f::AbstractArray)
4738

4839
fr = reshape(fp, size(fp,1), :)
4940

50-
permutedims(reshape(F\fr, size(fp)...), inv_perm(perm))
41+
permutedims(reshape(F\fr, size(fp)...), invperm(perm))
5142
end
5243

5344
struct NDimsPlan{T, FF<:ArrayPlan{<:T}, Szs<:Tuple, Dims<:Tuple} <: Plan{T}
@@ -79,7 +70,7 @@ function *(P::NDimsPlan, f::AbstractArray)
7970
for d in dims
8071
perm = ntuple(k -> k == d1 ? t[d] : k == d ? t[d1] : t[k], ndims(g))
8172
gp = permutedims(g, perm)
82-
g = permutedims(F*gp, inv_perm(perm))
73+
g = permutedims(F*gp, invperm(perm))
8374
end
8475
return g
8576
end
@@ -93,7 +84,7 @@ function \(P::NDimsPlan, f::AbstractArray)
9384
for d in dims
9485
perm = ntuple(k -> k == d1 ? t[d] : k == d ? t[d1] : t[k], ndims(g))
9586
gp = permutedims(g, perm)
96-
g = permutedims(F\gp, inv_perm(perm))
87+
g = permutedims(F\gp, invperm(perm))
9788
end
9889
return g
9990
end

0 commit comments

Comments
 (0)