You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The infix operators seem to break with what you would expect normal math operator precedence to have. I'm just wondering if this is the intended behavior or not.
Here's an example.
#moduleM=Owl.Mat;;
#moduleOp=Owl.Dense.Matrix.Operator;;
#let x =M.linspace 0.10.6valx : M.mat=C0C1C2C3C4C5R00246810(* Okay *)#Op.(x *$2.+$1.);;
- : (float, Bigarray.float64_elt) Owl_dense_matrix_generic.t =C0C1C2C3C4C5R0159131721(* Not what you would expect... *)#Op.(2.$* x +$1.);;
- : (float, Bigarray.float64_elt) Owl_dense_matrix_generic.t =C0C1C2C3C4C5R02610141822
I assume this is because of OCaml's rules about operator precedence and associativity. Particularly the fact that operators starting with + (like +$) have a higher precedence than those starting with $ (like $*).
So then you have a case where scalar * matrix multiplication ($*) has a lower precedence than matrix * scalar multiplication (*$).
In particular, you can see that, scalar * matrix multiplication ($*) has a lower precedence than matrix + scalar (+$) addition.
Just for reference, here is numpy with the same example.
This is related to #21.
The infix operators seem to break with what you would expect normal math operator precedence to have. I'm just wondering if this is the intended behavior or not.
Here's an example.
I assume this is because of OCaml's rules about operator precedence and associativity. Particularly the fact that operators starting with
+
(like+$
) have a higher precedence than those starting with$
(like$*
).So then you have a case where
scalar * matrix
multiplication ($*
) has a lower precedence thanmatrix * scalar
multiplication (*$
).In particular, you can see that,
scalar * matrix
multiplication ($*
) has a lower precedence thanmatrix + scalar
(+$
) addition.Just for reference, here is numpy with the same example.
The text was updated successfully, but these errors were encountered: