Depending on the maximum number of dimensions, using StaticArrays can speed it up:
using StaticArrays
x = SA[1,2,4]
CartesianIndex(Tuple(x)) # 2 ns (0 allocs: 0 bytes)
Depending on the maximum number of dimensions, using StaticArrays can speed it up:
using StaticArrays
x = SA[1,2,4]
CartesianIndex(Tuple(x)) # 2 ns (0 allocs: 0 bytes)