Upper limit for size of static array

Hello, I tried to allocate large static arrays but failed as shown below. Is there a way to find out the upper limits? I couldn’t find related information around.

julia> using StaticArrays

julia> @SMatrix zeros(16, 16)
16×16 StaticArrays.SArray{Tuple{16,16},Float64,2,256}:
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0

julia> @SMatrix zeros(160, 160)
ERROR: syntax: invalid syntax (memory-error out of gc handles)
Stacktrace:
 [1] Type(...) at /Users/spc/.julia/v0.6/StaticArrays/src/SMatrix.jl:33
 [2] macro expansion at /Users/spc/.julia/v0.6/StaticArrays/src/arraymath.jl:11 [inlined]
 [3] _zeros at /Users/spc/.julia/v0.6/StaticArrays/src/arraymath.jl:4 [inlined]
 [4] zeros(::Type{StaticArrays.SArray{Tuple{160,160},T,2,L} where L where T}) at /Users/spc/.julia/v0.6/StaticArrays/src/arraymath.jl:2

julia> @SMatrix zeros(1600, 1600)
ERROR: syntax: expression too large
Stacktrace:
 [1] zeros(::Type{StaticArrays.SArray{Tuple{1600,1600},T,2,L} where L where T}) at /Users/spc/.julia/v0.6/StaticArrays/src/arraymath.jl:2

IIRC the StaticArrays documentation says you shouldn’t use it for arrays larger than 100x100.

This upper limit was due to being built on tuples, and the inference restriction on tuple size was removed in Julia v0.7:

https://github.com/JuliaLang/julia/pull/27398

That said, using static arrays shouldn’t be done for arbitrarily large arrays since using the stack and optimizing directly on the size tends to not work so well for big arrays, but the removal of the arbitrary size limit should help the “largest size for which static arrays are useful” get a good bump to a higher number.

4 Likes