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

BUG: floor_divide returns strange values for integer division by zero #11990

Open
jakevdp opened this issue Aug 18, 2022 · 4 comments · May be fixed by #25032
Open

BUG: floor_divide returns strange values for integer division by zero #11990

jakevdp opened this issue Aug 18, 2022 · 4 comments · May be fixed by #25032
Assignees
Labels
bug Something isn't working P1 (soon) Assignee is working on this now, among other tasks. (Assignee required)

Comments

@jakevdp
Copy link
Collaborator

jakevdp commented Aug 18, 2022

Description

Example:

In [1]: import numpy as np                                                                                                                                                                                                                                                                  

In [2]: np.floor_divide(2, 0)                                                                                                                                                                                                                                                               
<ipython-input-2-7ecbd88da223>:1: RuntimeWarning: divide by zero encountered in floor_divide
  np.floor_divide(2, 0)
Out[2]: 0

In [3]: import jax.numpy as jnp                                                                                                                                                                                                                                                             
jn
In [4]: jnp.floor_divide(2, 0)                                                                                                                                                                                                                                                              
Out[4]: DeviceArray(-2, dtype=int32, weak_type=True)

What jax/jaxlib version are you using?

jax HEAD, jaxlib v0.3.14

Which accelerator(s) are you using?

No response

Additional System Info

No response

@jakevdp jakevdp added the bug Something isn't working label Aug 18, 2022
@hawkinsp
Copy link
Collaborator

I suspect this is working as intended: the behavior of division by zero will be implementation-defined. If you think it's important that we exactly match numpy we could add a select condition to floor_divide's implementation.

@jakevdp
Copy link
Collaborator Author

jakevdp commented Aug 18, 2022

Maybe, but "always return -2" is a strange convention

@mattjj
Copy link
Collaborator

mattjj commented Aug 22, 2022

Jake, could you add a priority label to this, and optionally reassign it to someone? (I can take it if you don't want to, where AIUI 'take it' means decide whether this WAI or else if we should add a select as Peter suggests, then add any implementation needed based on that decision.)

@jakevdp jakevdp added the P1 (soon) Assignee is working on this now, among other tasks. (Assignee required) label Aug 22, 2022
@jakevdp jakevdp assigned mattjj and unassigned jakevdp Aug 22, 2022
@jakevdp
Copy link
Collaborator Author

jakevdp commented Aug 22, 2022

Done, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P1 (soon) Assignee is working on this now, among other tasks. (Assignee required)
Projects
None yet
3 participants