4 ms·
The first thing I did was to check how slicing and indexing works. If anyone else is curious it is explained here http://ocaml.xyz/chapter/slicing.html http://
by srean 7y ago
The first thing I did was to check how slicing and indexing works. If anyone else is curious it is explained here
http://ocaml.xyz/chapter/slicing.html http://ocaml.xyz/chapter/slicing.html
The syntax is quite verbose. Anyway to make it better with macros ? Coming from number crunching world makes me wish that the syntax for list and arrays in OCaml were swapped.
On a different note, I hope Owl allows flexibility over memory layout in future. Inter-operating with Fortran is often necessary. Besides that, compile time reshaping n-dimensinal-arrays is very useful for having efficient code. As far as I know Julia can do this with macros, may be without macros too.
> OCaml’s Bigarray can further use kind GADT to specify the
> number type, precision, and memory layout. In Owl, I only
> keep the first two but fix the last one because Owl only
> uses C-layout, or Row-based layout in its implementation.
> See the type definition in Ndarray module.
- marmaduke 7y agoI think flexibility becomes a double edged sword over time: when you need to read, understand and modify some code with overloaded operators it can take longer to figure out what's happening.
- srean 7y ago> I think flexibility becomes a double edged sword over time Agreed in general. For the specific case of number crunching though, sooner or later you would like to call out to a Fortran library. That and with DNNs being so popular now, flexibility over how 'tensors' are laid out in memory by an upstream library or how it has to be laid out to call another library is quite crucial. > when you need to read, understand and modify some code with overloaded operators it can take longer to figure out what's happening. If overloading has been a resounding success anywhere that would be in scientific computing. Unless someone goes overboard it really helps rather than hinders understanding by matching traditional mathematical notation.
- marmaduke 7y agoI had non arithmetic syntax in mind when making this comment, such as indexing. Those can be simple as in get the i'th element or get elements corresponding to a mask etc. This makes it easy to write, less easy to know what's actually happening later.
- octachron 7y agoThere are some change in the pipes that should make the syntax for slicing lighter in OCaml 4.10 by eliminating the need of the outermost [| |] or [ ]. For instance, let a = x.%{ [|2; 3; 4|] } x.%{ [|2; 3; 4|] } <- 111. let a = x.${ [[0;4]; [6;-1]; [-1;0]] } might be simplified to: let a = x.%{ 2; 3; 4 } x.%{ 2; 3; 4 } <- 111. let a = x.${ [0;4]; [6;-1]; [-1;0] } It is possible to go further with ppxs(OCaml version of macros), but at a greater readability cost.