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

jax.numpy.tile inconsistent with np.tile (when 0 in repeats) #3919

Closed
kratsg opened this issue Jul 31, 2020 · 1 comment · Fixed by #3922
Closed

jax.numpy.tile inconsistent with np.tile (when 0 in repeats) #3919

kratsg opened this issue Jul 31, 2020 · 1 comment · Fixed by #3922
Labels
bug Something isn't working

Comments

@kratsg
Copy link

kratsg commented Jul 31, 2020

>>> import numpy as np
>>> import jax.numpy as jnp
>>> np.tile(np.array([0, 1, 2]), (1, 1, 2))
array([[[0, 1, 2, 0, 1, 2]]])
>>> jnp.tile(jnp.array([0, 1, 2]), (1, 2, 2))
DeviceArray([[[0, 1, 2, 0, 1, 2]]], dtype=int64)
>>> np.tile(np.array([0, 1, 2]), (1, 0, 2))
array([], shape(1, 0, 6), dtype=int64)
>>> jnp.tile(jnp.array([0, 1, 2]), (1, 0, 2)
...
ValueError: Need at least one array to concatenate

A fix locally is to wrap the jax.numpy.tile like so:

        if 0 in repeats:
            return jnp.array([]).reshape(np.array(tensor_in.shape) * np.array(repeats))
        return jnp.tile(tensor_in, repeats)
@matthewfeickert
Copy link

Wow that was fast @jakevdp! Thanks so much! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants