Skip to content

even_spacing option to omit binary search#148

Draft
YigitElma wants to merge 3 commits intof0uriest:mainfrom
YigitElma:yge/even-spaced
Draft

even_spacing option to omit binary search#148
YigitElma wants to merge 3 commits intof0uriest:mainfrom
YigitElma:yge/even-spaced

Conversation

@YigitElma
Copy link

For evenly spaced regular grids, the neighboring points of the query positions can be found without a binary search. The benefits of this are hopefully twofold:

  • This should accelerate the computation for large arrays.
  • This should make the vmapped operations more efficient in terms of memory movement. For example, if one integrates an ODE for many initial positions and vmap over those via diffrax, due to jax.numpy.searchsorted each kernel needs all the arrays and hence different kernels have to wait for another to finish. Ideally, with this change, each kernel only needs to access $2^n$ components of the arrays, not all.

The current version is working fine and I think would benefit others too, however, for the second point, I need to make more profiling, and see if it is making a meaningful difference or needs additional changes.

i = jnp.clip(jnp.searchsorted(x, xq, side="right"), 1, len(x) - 1)
else:
dx = x[1] - x[0]
i = jnp.clip(jnp.floor((xq - x[0]) / dx).astype(int) + 1, 1, len(x) - 1)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if this still works for periodic inputs

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 this pull request may close these issues.

1 participant