ANN: UnsafeArray.jl

Dear all,

I’d like to present UnsafeArray.jl. It’s main function is to provide (heap-)allocation-free array views. It provides a (hopefully) safe alternative to ArrayViews.UnsafeArrayView, and integrates with Base.view() and Base.SubArray.

Example:

@uviews A B C ... begin
    # Within this scope, arrays A B C ... are replaced by stack-allocated (pointer-based)
    # bitstype UnsafeArrays, view()'s on these are also bitstypes and stack-allocated.
    # The original arrays are protected from GC, but it's the user's responsibility not to
    # let the unsafe version of A B C ... escape from this scope.
end

I did some initial benchmarking, the results are quite encouraging.

7 Likes

Could you compare your design goals with the design goals of StaticArrays.jl?

StaticArrays are statically sized, allowing very heavy specialisations and optimizations for a specific shape. Since some subtypes are also immutable, the whole array can be stack allocated.

The above Package offers stack allocated views into normal heap allocated julia arrays :wink: So the array itself is not immutable and doesn’t hold its size as a static type parameter.

StaticArrays (please correct me if I’m wrong) is something very different, it provides stack-allocated arrays of fixed/hard-coded size. UnsafeArrays provides stack-allocated views (of arbitrary size) of heap-allocated arrays.

Darn, you were faster, Simon. :wink: