Skip to content

Commit

Permalink
Make cexp faster using out kwarg
Browse files Browse the repository at this point in the history
Can assign real and imaginary parts directly using the out kwarg of
np.cos and np.sin without using an intermediate buffer array.
  • Loading branch information
thangleiter committed May 1, 2020
1 parent 6e759cf commit 4f0be8e
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions filter_functions/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,8 @@ def cexp(x: ndarray) -> ndarray:
https://software.intel.com/en-us/forums/intel-distribution-for-python/topic/758148 # noqa
"""
df_exp = np.empty(x.shape, dtype=np.complex128)
trig_buf = np.cos(x)
df_exp.real[:] = trig_buf
np.sin(x, out=trig_buf)
df_exp.imag[:] = trig_buf
df_exp.real = np.cos(x, out=df_exp.real)
df_exp.imag = np.sin(x, out=df_exp.imag)
return df_exp


Expand Down

0 comments on commit 4f0be8e

Please sign in to comment.