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

interpolate method from the Grid class raises IndexError #5

Closed
bschnitzler opened this issue Nov 13, 2023 · 1 comment · Fixed by #9
Closed

interpolate method from the Grid class raises IndexError #5

bschnitzler opened this issue Nov 13, 2023 · 1 comment · Fixed by #9

Comments

@bschnitzler
Copy link

When trying to interpolate an array over a Grid using the interpolate method, an error is returned if the interpolation point is beyond the upper bounds.

Expected behavior

Extrapolate away the data array to interpolate when point lies outside boundaries

Actual behavior

Raises an IndexError

Steps to reproduce the behavior

The following example code shows the issue

import hj_reachability as hj
import numpy as np

bl = np.array((0., 0.))
tr = np.array((1., 1.))
grid = hj.Grid.from_lattice_parameters_and_boundary_conditions(hj.sets.Box(bl, tr), (10, 10))
values = np.random.random((10, 10))

grid.interpolate(values, np.array((1., 1.)))
@schmrlng
Copy link
Collaborator

schmrlng commented Dec 3, 2023

Sorry for the delayed response -- thanks for finding this! Actually for grid values that are of type jax.Array instead of np.ndarray (the typical use case, at least for me) it seems that JAX's out-of-bounds indexing behavior has been masking the problem and making the buggy jnp.clip superfluous. Upon reflection, extrapolation probably shouldn't be allowed (or at least should be explicitly controlled by the user) so in addition to fixing the jnp.clip bounds I've changed the extrapolation behavior to return nans in #9.

schmrlng added a commit that referenced this issue Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants