jax.Array: support duck-typed isinstance checks #12256
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why? As part of the type promotion discussion in JAX (#11859 & #12049), @patrick-kidger and I have been discussing what API jax should support for both annotations and
isinstance
checks; we think the best approach would be to eventually makejax.Array
unify all these purposes.This is a simple enhancement to
jax.Array
that allows it to be used inisinstance
checks in traced functions, similar to howisinstance(obj, jnp.ndarray)
works currently.@yashk2810, I'm curious whether you see any issues with adding a mechanism like this to the
Array
class? Do you think this idea of unifying type checking and instance checks around the eventualjax.Array
object has merit? Do you have any hesitations here?