190 points · by alokrai · 7y ago · 76 comments
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.
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.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.
http://ocaml.xyz/chapter/index.html
They seem to be implementing the most popular parts of the Python numerical ecosystem from ndarrays to AD graph and neural nets, as well as plotting.https://github.com/ocaml/ocaml/blob/d3e73595e55e84250fa77f04...
What is a little strange is that Bigarray seems to support both C and Fortran order, but as of now Owl Ndarrays are C order only.
[1]: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Bigarray....
Without static typing, the discoverability is so low so that you're literally feeling pain tinkering with python. REPL experience with static types is so much better. With numpy and scipy, I had to stick to documentation all the time even to do the most trivial things. What kinds of arguments could I pass to the plotting function? Read the docs. Does this work with dense or sparse matrix? Does it work with array? Read the docs.
In OCaml you could derive most of the information from the type, for example a plotting api
http://ocaml.xyz/apidoc/owl_plot.html
Much of this is simply obvious within a REPL session without looking at the doc. Simple calling a function name would show you its type.
I don't think that has anything to do with static vs dynamic typing. I can do all of that in Julia which is a dynamically typed language. 1) I can start typing a function name and hit tab to complete it, or show matching alternatives with possible argument combinations and their types listed.
2) As I start typing arguments I can hit tab more times to see matching completions. The REPL will take into account the type of arguments I've already given when offering possible completion alternatives.
3) If I got a type, which I am not sure what I can do with I can write methodswith(sometype) to get a list of all functions taking an argument of type sometype.
4) Wonder if something works with dense, sparse, arrays etc? Check the function signature. Usually it will say AbstractArray and sparse matrix and dense matrix are subtypes of AbstractArrays. Not sure, you can quickly check that on the REPL by asking AbstractSparseArray <: AbstractArray, or you just look at subtypes of AbstractArray with subtypes(AbstractArray).
Having said that I might want to check out Owl in the future. I have had a number of temporary engagements with statically typed functional languages. Haskell was interesting, but I found it to be impractical and too much of a time investment. OCaml may be more pragmatic, but it has often seemed a bit verbose to me.
The first thing I do when evaluating languages for myself is to look at processing text files line by line or all at once and splitting strings. If that is complicated, then the language might not be well suited to my needs.
With types, a repl, native support for scientific computing and sparse matrices, LLVM JIT, LLVM assembly code inspector, all kinds of macros and support for macros, s-expression macro inspector, speed, easy package manager, large community, good graphics packages...etc, I'm really liking Julia.
Naturally OCaml benefits from almost 20 years existence.
From numerical lib designers' perspective, a holistic design (note which does not necessarily mean a monolithic lib) leads to a more coherent and consistent design (e.g. APIs), which makes a large software system easier to optimise and maintain. As a young and experimental system, Owl seems doing a quite decent job so far IMO.
However, from a (broad) users' perspective, being very honest, I never believe which one should replace which despite how much I love Owl myself. Each tool has own pros and cons deeply root in its internal design, depends on the language it uses, its design assumptions and goals. I think the choice of tools is really a matter of project requirements, coders' own skill, personal taste, management choice, as well as the context (i.e. what kind of apps you are going to build for whom and where).
liang
From what I understand, the key points are:
1. The author claims that various libraries in Python (Scipy, Pandas, etc.) have a large amount of duplicated code and overlap, if you look deeply in the code. Having one library with a holistic design prevents this overlap and allows for easier optimisation.
2. He further claims that because "numerical computing is built atop of a small amount of abstract number types (e.g. real and complex), then derives a fat set of advanced numerical operations for various fields", unlike systems programming, holism, such as in OWL, is preferable to reductionism.
Can anyone point me towards a good free online resource for learning OCaml?
Of course, you can't get funding for something that unambitious, so I understand the tack. Still...
I look forward to trying this out once more significant work has been done. I'm a big fan of OCaml-like languages, if that wasn't already obvious.
We should want to see examples grow not just for F# or Ocaml but also Haskell, Rust, Scala and others. Then we should prioritize as much as possible, inter-operation of libraries, model definitions and outputs.
What? Why would they do it? Unix is a standard in the field of scientific computations, so wrapping blas and lapack totally makes sense. Besides, OCaml already had good blas, lapack bindings.
OCaml works great in windows and have good .Net bindings. LexiFi earns money nearly solely from OCaml on windows.
>F# works just fine in Linux.
Does it have bindings for the majority of popular libs? For example are there Gstreamer and Gtk F# bindings? Do they work on both .Net Core and Mono?
Which ones ? A free one analogous to libmath that works with float32 would be a good start.
Am serious, would love to know of some .Net libraries for number crunching that one would miss if one were to move out of the .Net platform. Or did you mean non-numeric libraries ?
That I would have to (i) write my own cos or (ii) take a dependency on a commercial 3rd party library that will likely not be around for long or (iii) call a native library through and FFI, for something as simple as a cos of float32 is not terribly exciting.