np.unwrap runtime explodes
See original GitHub issueDear jax team,
I implemented np.unwrap
by looking at the numpy source and changing the inplace-modification bits to np.where
and np.concatenate
.
While the values are correct, the runtime explodes for x.size > 1e7
and is generally a lot worse than the numpy version. See repro below.
Now, I don’t want to waste your time with some micro-optimizations for my specific code. But are there some general performance tips here? I guess the where
and concatenate
are problematic, but I wouldn’t know how to improve this in the JAX framework. Sorry for the code being so cryptic…
Repro:
import jax
import jax.numpy as np
import numpy as onp
@jax.partial(jax.jit, static_argnums=1)
def unwrap(p, axis):
nd = np.ndim(p)
dd = np.diff(p, axis=axis)
ddmod = np.mod(dd + np.pi, 2 * np.pi) - np.pi
ddmod = np.where(
np.isclose(ddmod, -np.pi) & (dd > 0),
np.pi,
ddmod)
ph_correct = np.where(
np.abs(dd) < np.pi,
0,
ddmod - dd)
up = np.concatenate((
jax.lax.slice_in_dim(p, 0, 1, axis=axis),
jax.lax.slice_in_dim(p, 1, None, axis=axis) + np.cumsum(ph_correct, axis=axis)
), axis=axis)
return up
# OKAY
x = onp.random.randn(1000) * 10
assert onp.allclose(
onp.unwrap(x),
unwrap(x, 0),
atol=1e-3, rtol=1e-3
)
# NOT OKAY
x = onp.random.randn(int(1e7)) * 10
unwrap(x, 0).block_until_ready()
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
numpy.unwrap — NumPy v1.24 Manual
If the discontinuity in p is smaller than period/2 , but larger than discont, no unwrapping is done because taking the complement would...
Read more >Unwrap angle to have continuous phase - python
How to get an array of more "continuous" phases from it? Of course, I already tried with np.unwrap : plt.plot(np.unwrap(phase)). or
Read more >Untitled
... episode 216 english subbed, Runtime of interstellar, Aeg electrolux oven manual? ... Cine argentino ricardo darin, Sequoia national park rim fire, ...
Read more >Untitled
... add wallet coupon, Baldwin denim kc hat, Qt3 runtime library install? ... Diwali festival amstelveen 2014, Unwrap hair, Leize todo por el...
Read more >Changelog — Hypothesis 6.60.0 documentation
It also does not make sense as a runtime type on its own. 6.35.1 - 2022-01-17¶. This patch fixes hypothesis write output ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It works and is super fast, thank you!
I believe this is now fixed at head. Let me know how it goes!