Sorry there is one more question towards systematic test for all permutations.
Suppose I would like to compute
0.1 A[i,j,k,l] + 0.2 * A[i,j,l,k] + 0.3 * A[i,k,i,j] + 0.4 * A[i,k,j,i] + 0.5 * A[i,l,j,k]...
Is there any simple way to permutations, than specifying [i,k,j,i]
etc (I can try to generate strings as the indices, but it may be a bit complicted)?
I used Get all Permutations of Array?
using BenchmarkTools, Combinatorics
function perms(a)
B = reverse(collect(permutations(a)))
B
end
n=30
A=rand(Float64,(n,n,n,n))
@btime p = perms(A)
Got ERROR: LoadError: OverflowError: 531439031701620000 * 809997 overflowed for type Int64
And, if there is a prefactor equals zero, e.g., 0.0* A[i,l,k,j], can I skip the permutation to i,l,k,j
? The permutations
will generate all permutations as I understand it (In Python, I can use
np.transpose(A,(0,3,2,1))
to specify the given transpose.)
Edited: found PermutedDimsArray(A, (2,1,3,4))
in test3
is similar to Python transpose