From 945bf0ee52843de67066a3e4654a5a22aeec60e9 Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 5 Oct 2021 06:55:08 -0400 Subject: [PATCH] Reduce compilation time for `permutedims` with high dimensional arrays (#42486) --- base/multidimensional.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/base/multidimensional.jl b/base/multidimensional.jl index 8bbfc6d2f2be7d..1e9f0d2cae7e71 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -1577,13 +1577,12 @@ for (V, PT, BT) in Any[((:N,), BitArray, BitArray), ((:T,:N), Array, StridedArra #Creates offset, because indexing starts at 1 offset = 1 - sum(@ntuple $N d->strides_{d+1}) + sumc = 0 ind = 1 - @nexprs 1 d->(counts_{$N+1} = strides_{$N+1}) # a trick to set counts_($N+1) @nloops($N, i, P, - d->(counts_d = strides_d), # PRE - d->(counts_{d+1} += strides_{d+1}), # POST + d->(sumc += i_d*strides_{d+1}), # PRE + d->(sumc -= i_d*strides_{d+1}), # POST begin # BODY - sumc = sum(@ntuple $N d->counts_{d+1}) @inbounds P[ind] = B[sumc+offset] ind += 1 end)