Hi,
I find myself needing to do column-wise operations on matrices a lot (i.e. on A[:,j]). Or, spoken differently, I would want to use my matrix almost like a Vector{SVector}, i.e. A[j][:], which has identical data layout.
Ok, what do I need to do? Well, all the things one would like to do with vectors: arithmetic, swap, pass to functions.
Broadcast and array views have nice syntax but don’t work (they allocate). Vector{SVector} has nice syntax (I need to specialize on the number of rows though, and remember the changed order of dimensions), but crucially does not give by-reference-passing to functions.
So, I wanted to ask what other people are using. Of course I could write helper functions that try to behave like the broadcast/arrayview but keep the array-ref and the index separate; then I get no allocations, at the price of code-duplication (on functions that need to be capable of accepting both arrays and array_views).
I could also go for writing explicit loops in all instances, but this kinda defies the point of using a high-level language (you wouldn’t even do this in C).
I also could go for a horrible “C-style” view (pointer), which does not protect the underlying matrix from gc. Sprinkling gc_preserve might make this marginally better.
So: How are you people dealing with this problem? Any kind of julia-array that already solves this?
PS.
Aggressive elimination of allocations probably won’t solve this. It will be solved once immutables containing reference-fields become bitstype, for the sake of code_native (allocation/arg-passing/array-storage).
See also https://github.com/JuliaStats/Distances.jl/issues/83.