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

Update jnp.fabs to emulate the behavior of np.fabs for complex inputs. #23290

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

rajasekharporeddy
Copy link
Contributor

@rajasekharporeddy rajasekharporeddy commented Aug 28, 2024

This PR fixes a discrepancy between jnp.fabs and np.fabs by raising a TypeError for complex inputs, as np.fabs currently does.

Current behavior:

>>> x = jnp.array([1-1j, 2+5j])
>>> jnp.fabs(x)
Array([1.4142135, 5.3851647], dtype=float32)

New behavior:

>>> x = jnp.array([1-1j, 2+5j])
>>> jnp.fabs(x)
TypeError: ufunc 'fabs' does not support complex dtypes

Also updated the docstring with code examples. The rendered preview:

Copy link
Collaborator

@jakevdp jakevdp left a comment

Choose a reason for hiding this comment

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

Looks good! Since this is a user-visible change of behavior, we should also add a changelog entry.

jax/_src/numpy/ufuncs.py Outdated Show resolved Hide resolved
jax/_src/numpy/ufuncs.py Outdated Show resolved Hide resolved
@jakevdp jakevdp self-assigned this Aug 28, 2024
@rajasekharporeddy rajasekharporeddy force-pushed the testbranch1 branch 2 times, most recently from 195ec17 to b06c0af Compare August 28, 2024 13:39
jax/_src/numpy/ufuncs.py Outdated Show resolved Hide resolved
jax/_src/numpy/ufuncs.py Outdated Show resolved Hide resolved
@google-ml-butler google-ml-butler bot added kokoro:force-run pull ready Ready for copybara import and testing labels Aug 28, 2024
@copybara-service copybara-service bot merged commit 246ad43 into jax-ml:main Aug 28, 2024
16 checks passed
@rajasekharporeddy rajasekharporeddy deleted the testbranch1 branch August 28, 2024 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pull ready Ready for copybara import and testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants