On Monday, April 18, 2016 at 11:03:53 AM UTC-4, Didier Verna wrote:
>
>   What I'm actually interested in is how deep in the language 
>   this needs to be grounded, since I guess this is not based on the 
>   AbstractArray interface. Does it need to access the language's 
>   internals ? How's the underlying storage  done and is it as efficient 
>   as Julia's native arrays ? 
>

Sure, the AbstractArray interface doesn't hold its sizes in the type 
domain, but that can layer on top quite nicely.  There's absolutely nothing 
preventing your SquareMatrix{Int32, 3} from behaving like an 
AbstractArray{Int32, 2} — just define it as such:

immutable SquareMatrix{T, Sz} <: AbstractArray{T, 2}

Optimizing its storage to be *faster* than the built-in Array is where this 
gets tricky.  For small immutable matrices, you'd want this object to use 
immediate stack-based storage so it doesn't hit the GC or heap allocation. 
 Tuples are good for this, but they're kinda tough to work with since you 
can't iteratively fill them.  An alternative is to dynamically generate 
specific types for the dimensions you need — that's what ImmutableArrays 
does: https://github.com/JuliaGeometry/ImmutableArrays.jl.

Reply via email to