[ANN]: ZeroDimensionalArrays.jl: zero-dimensional arrays/references/boxes

I think it’s similar to the difference between a Vector and a Matrix. A matrix can be NxM, Nx1, or even Nx0, but a vector is constrained to being length 1 in the second dimension, even when it’s empty (to the extent that one can say it has a size in the second dimension at all, but at least it is fixed):

julia> size(Int[], 1)
0

julia> size(Int[], 2)
1

A 0-dimensional array is constrained to always containing exactly one single value, and is therefore similar to a scalar, while a vector can be empty, length 1 or length N.

2 Likes

Purity assumption is common and totally makes sense IMO. Eg, among stdlibs:

julia> using SparseArrays
julia> (_ -> rand()).(spzeros(5)) .+ zeros(5)
5-element SparseVector{Float64, Int64} with 5 stored entries:
  [1]  =  0.860252
  [2]  =  0.860252
  [3]  =  0.860252
  [4]  =  0.860252
  [5]  =  0.860252

Can we fix that with Document Base.RefValue and clarify that this is public API by bbrehm · Pull Request #58101 · JuliaLang/julia · GitHub ?

1 Like