JuliaArrays / StaticArrays.jl

Statically sized arrays for Julia
Other
762 stars 148 forks source link

Incorrect 0-dim `zeros` and `ones` #1274

Open jishnub opened 1 month ago

jishnub commented 1 month ago
julia> zeros(SMatrix{2,2,ComplexF64,4})
2×2 SMatrix{2, 2, ComplexF64, 4} with indices SOneTo(2)×SOneTo(2):
 0.0+0.0im  0.0+0.0im
 0.0+0.0im  0.0+0.0im

julia> ones(SMatrix{2,2,ComplexF64,4})
2×2 SMatrix{2, 2, ComplexF64, 4} with indices SOneTo(2)×SOneTo(2):
 1.0+0.0im  1.0+0.0im
 1.0+0.0im  1.0+0.0im

These should return a 0-dim Array with the only element being a 2x2 SMatrix. zeros and ones are documented to return an Array, and the number of dimensions provided as arguments should match the dimension of the returned array. In particular, zeros(T) should be consistent with fill(zero(T)):

julia> fill(zero(SMatrix{2,2,ComplexF64,4}))
0-dimensional Array{SMatrix{2, 2, ComplexF64, 4}, 0}:
[0.0 + 0.0im 0.0 + 0.0im; 0.0 + 0.0im 0.0 + 0.0im]