Skip to content

Compare the equality of address between two arrays. #20851

Answered by jakevdp
sh0416 asked this question in Q&A
Discussion options

You must be logged in to vote

You can do this:

x = jnp.zeros((4, 4))
y = x

print(x is y)  # Python-level object equality
# True

print(x.unsafe_buffer_pointer() == y.unsafe_buffer_pointer())  # memory pointer equality
# True

But note that, as the method states, this is not safe: it is implementation-dependent, and the exact behavior may change. Also, keep in mind that this only exists in eager mode: there's no way to do this kind of check within transformations like jit, because in general the compiler needs to be free to make choices about the storage of arrays (and whether to materialize them at all).

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@sh0416
Comment options

@jakevdp
Comment options

Answer selected by sh0416
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants