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

Serious bug with not_equal_scalar function always returning the wrong result. #674

Closed
zoj613 opened this issue Jul 10, 2024 · 0 comments · Fixed by #675
Closed

Serious bug with not_equal_scalar function always returning the wrong result. #674

zoj613 opened this issue Jul 10, 2024 · 0 comments · Fixed by #675

Comments

@zoj613
Copy link

zoj613 commented Jul 10, 2024

There is a serious bug with the implementation of not_equal_scalar function. In it's current state, it is an alias for equal_scalar since it returns the opposite of it's expected result. Here is a reproducing example:

module Ndarray = Owl.Dense.Ndarray.Generic;;
let x = Ndarray.create Bigarray.Int64 [|2;2;2|] 10L;;
Ndarray.equal_scalar x 10L;;
(*- : bool = true *)
Ndarray.not_equal_scalar x 10L;;
(*- : bool = true *)

Evidently, not_equal_scalar is supposed to return false. With the help of my LSP server, I was able to jump to the definition of this function and to my surprised found that the underlying implementation of both functions is identical. See:

let equal_scalar x a = _owl_equal_scalar (kind x) (numel x) x a = 1
let not_equal_scalar x a = _owl_equal_scalar (kind x) (numel x) x a = 1

Basically the implementation of equal_scalar was copied over to not_equal_scalar. I looked to see if there is an implementation function named _not_equal_scalar and it turns out it does exist at:

let _owl_not_equal_scalar : type a b. (a, b) kind -> (a, b) owl_arr_op10 = function

So a simple fix for this bug is to just replace

let not_equal_scalar x a = _owl_equal_scalar (kind x) (numel x) x a = 1 

with

let not_equal_scalar x a = _owl_not_equal_scalar (kind x) (numel x) x a = 1 

Cc @mseri @jzstark

@zoj613 zoj613 changed the title Serious bug with not_equal_scalar function _always_ returning the wrong result. Serious bug with not_equal_scalar function **always** returning the wrong result. Jul 10, 2024
@zoj613 zoj613 changed the title Serious bug with not_equal_scalar function **always** returning the wrong result. Serious bug with not_equal_scalar function always returning the wrong result. Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant