[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

ZeroDimensionalArrays.jl v1.1.0 is registered just now. Changes:

  • Added another zero-dimensional array type, ZeroDimArrayInTypeParameter. It stores its element only in a type parameter.

  • For all types except Box, the default element type of Arr(element) is now the more precise Type{element} whenever element isa Type. There were no changes to Box to prevent breakage, as Box supports mutation, which might fail if an element type of DataType was replaced with the more precise Type{T}.

5 Likes

Thanks for this package @nsajko ! I had been looking for an immutable (and isbits with an isbits value) array type like ZeroDimArray for a while now.

2 Likes