Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Owl rewrites the standard integer binary operations #571

Open
qaristote opened this issue Jan 6, 2021 · 3 comments
Open

Owl rewrites the standard integer binary operations #571

qaristote opened this issue Jan 6, 2021 · 3 comments
Labels

Comments

@qaristote
Copy link

Let's say I open a repl and execute the following code.

#require "owl" ;;
open Owl.Dense.Matrix.D ;;
let n = 5 in get_slice [ [] ; [ 1 ; n - 1 ] ] (eye n) ;;

Then I will get a typing error on n-1 :

Error: This expression has type int but an expression was expected of type
         ('a, 'b) Owl_dense_matrix_generic.t =
           ('a, 'b, Bigarray.c_layout) Bigarray.Genarray.t

The reason is that Owl.Dense.Matrix.D redefines the - operator to work with matrices.

Although this is expected behavior, I wonder whether this is the right choice for the library. As the example shows even when doing linear algebra the integer binary operators may still be used. Of course I could simply use Stdlib.(-) n 1 or define an other symbol for integer operations but I would not call that a great user experience.

I must say it seems like something quite obvious so I wonder if I missed something in the documentation or even whether that's a deliberate choice.

@nilsbecker
Copy link
Contributor

Maybe the idiomatic usage that was intended is

module M = Owl.Dense.Matrix.D
let n = 5;;
let slice = M.get_slice [ []; n-1 ] (M.eye n);;
let zero = M.(eye n - eye n)

?

It might be more ergonomic if Owl used decorated binary operators like -# or some such. I don't know if this has been discussed? In any case it seems a pretty breaking change at this point.

@mseri
Copy link
Member

mseri commented Jul 21, 2021

I am not aware of a discussion around this, but I understand the pain. Fwiw, I stumbled upon the same at the beginning and ended up doing what you do in your last comment (and sometime also rely on Stdlib. to recover integer operators).

@mseri mseri added the question label Jul 21, 2021
@nilsbecker
Copy link
Contributor

in view of https://ocaml.xyz/book/convention.html#pure-vs.-impure a more consistent set of operators for element wise algebra might be +. etc. these would overwrite plain float operations. not sure if that's better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants