Skip to content

Commit 1d10a48

Browse files
Merge pull request #29001 from johannahaffner:test-clip
PiperOrigin-RevId: 763865376
2 parents e258708 + c22bba2 commit 1d10a48

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

jax/_src/numpy/lax_numpy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3410,6 +3410,7 @@ def clip(
34103410
Returns:
34113411
An array containing values from ``arr``, with values smaller than ``min`` set
34123412
to ``min``, and values larger than ``max`` set to ``max``.
3413+
Wherever ``min`` is larger than ``max``, the value of ``max`` is returned.
34133414
34143415
See also:
34153416
- :func:`jax.numpy.minimum`: Compute the element-wise minimum value of two arrays.

tests/lax_numpy_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,14 @@ def testClipDeprecatedArgs(self):
10651065
"Passing arguments 'a', 'a_min' or 'a_max' to jax.numpy.clip is deprecated"):
10661066
jnp.clip(jnp.arange(4), a_min=2, a_max=3)
10671067

1068+
def testClipUpperPrecedence(self):
1069+
a_min = 3 * np.ones(1)
1070+
a_max = 2 * np.ones(1)
1071+
x = 4 * np.ones(1)
1072+
y = jnp.clip(x, min=a_min, max=a_max)
1073+
assert y == a_max, f"Expected {y} to equal {a_max} when a_min > a_max."
1074+
assert y == jnp.asarray(np.clip(x, a_min=a_min, a_max=a_max))
1075+
10681076
def testHypotComplexInputError(self):
10691077
rng = jtu.rand_default(self.rng())
10701078
x = rng((5,), dtype=jnp.complex64)

0 commit comments

Comments
 (0)