-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add scalar python types to array-like types #1081
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
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
You could check six.PY3
and include long
if we're in PY2. WDYT?
Thanks Matt and James, added your suggestions! |
It's a little surprising that types change under |
@shoyer let's keep discussing this! Though we should keep in mind we're going for "best reasonable solution" rather than "perfect." Attributes like But I am concerned if you think this 'fix' is worse. Can you say more about how this might be worse? Is it about diverging further from NumPy/Python scalar behavior, or rather about having different behavior under Maybe another principle we should include here is the principle of least surprise. Is |
Honestly, I'm a little amazed that JAX manages to make Perhaps we should think about use cases? For the use case of checking for arrays/scalars vs. other non-primitive Python things inside some sort of nested Python data structure, |
I cannot think of circumstances when it would be useful to distinguish between Python scalars and arrays with JAX, with the possible exception of value-based casting (and that can be handled by some separate mechanism). It does seems like something like |
This will make `isinstance` called on scalars return True for both jitted and non-jitted JAX programs. Note that `isinstance(x, onp.ndarray)` is False for these types, so it breaks this correspondence.
Co-Authored-By: James Bradbury <jekbradbury@google.com>
Closing this PR, since it's fairly stale at this point. I think #1080 is to some extent working as intended; |
This will make
isinstance
called on scalars return True for both jitted and non-jitted JAX programs. Note thatisinstance(x, onp.ndarray)
is False for these types, so it breaks this correspondence.#1080