I needed a few functions which were missing in the OCaml library : Bigarray.Genarray, and decided to write them for my own purpose :
Iteration on genarrays
mapping on genarrays
folding on genarrays
Today I believe this can be usefull for others, and may suffer a code inspection as I am not that experienced in OCaml. I am ready to have this piece of code evolve if it is usefull so even (and maybe first) a feedback on the usefullness of such code is welcome.
The only alternative I was given was the famous Owl library, which was way to heavy for my needs, and not easily usable (if not understandable). This extension is very simple, it is its strenght. Ultimately, it could be merged in the standard library … maybe after some work indeed : you tell me.
There is a clean documentation I guess, hope this can help : GenArrayIter
I personally have wished frequently that mapping across Genarrays was something available in the stdlib. For my case, given an n-dimensional array I would like to map a function on (n-1)-dimensional arrays across it (which we can implement using slice_left). But, one could make it even more general and say that one can map across (n-k)-dimensional arrays by iterating over the first k dimensions of the shape.
I think you have mixed slice_left and sub_left, haven’t you ? sub_left has indeed this constraint of being only n-1 whereas slice_left does not. These two primitives are indeed part of the standard library now (and complex in my understanding, at least in their description).
The purpose of the standard library is indeed to keep only the primitives, i.e. the most simple/reusable/generic/… functions that you can build upon to have more complex functions. I believe that the ones I provided are of this kind.
I would indeed love to, but If I need to clone the ocaml repos and build everything to make sur my change requests does not break anything before submitting, I guess I won’t be able to make it (or it would take a lot of time). Plus looking at some part of their code, it looks like (although I am not an ocaml expert at all) that these functions are actually written in C. I believe one should be able to implement quite efficient functions in OCaml as well, shouldn’t we ? At least I would need some guidance on how to proceed (in C or OCaml) first.
I did not speak clearly. I agree you can use slice_left to solve both of these problems at once. I meant that I only have encountered the need to map across (n-1)-dimensional arrays, but one could make it even more general using slice_left, and map an operator across a k-dimensional array of (n-k)-dimensional array.