Currently, Owl has a multidimensional Array module which uses only Bigarray.Genarray.t
and never the specialized Array{1,2,3}.t
. The best syntax Owl can currently provide for array element access is e.g. a.%{[|0|]}
. Compared to a.{0}
that’s twice the number of characters. Considering element access is very common, this is annoying.
Using a trick, it is possible to repurpose the indexing syntax of standard OCaml modules.
It goes as follows:
module S = struct
include String
let get s i =
let c = String.get s i in
print_endline "getting the character for you!"; c
end
module String = S
"sdfsdf".[2]
Is it possible to do a similar thing for Bigarray.Array{1,2,3}
and Bigarray.Genarray
simultaneously, so that in the end, one could have a module Arr
with a single type which would support all of the following:
let a, b, c, d = Arr.(zeros [|1|], zeros [|1;1|], zeros [|1;1;1|] , zeros [|1;1;1;1|])
open Arr (* or whatever is required *)
let element_list = [a.{0}, b.{0,0}, c.{0,0,0}, d.{0,0,0,0}]
and where a.{0,0}
would raise a runtime error? The idea is that opening Arr
(or maybe redefining Bigarray.Array{1,2,3}
in some way) would capture and reuse the various Bigarray indexing syntaxes. It’s ok if Bigarray gets butchered in the process – access to arrays is handled by Arr
anyway.