Skip to content

Commit

Permalink
Merge pull request #23921 from rajasekharporeddy:testbranch4
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 679203931
  • Loading branch information
Google-ML-Automation committed Sep 26, 2024
2 parents 0e082f9 + 6072f97 commit 96cf2b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions jax/_src/numpy/lax_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6812,6 +6812,10 @@ def trace(a: ArrayLike, offset: int | ArrayLike = 0, axis1: int = 0, axis2: int
util.check_arraylike("trace", a)
if out is not None:
raise NotImplementedError("The 'out' argument to jnp.trace is not supported.")

if _canonicalize_axis(axis1, ndim(a)) == _canonicalize_axis(axis2, ndim(a)):
raise ValueError(f"axis1 and axis2 can not be same. axis1={axis1} and axis2={axis2}")

dtypes.check_user_dtype_supported(dtype, "trace")

a_shape = shape(a)
Expand Down
5 changes: 5 additions & 0 deletions tests/lax_numpy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2725,6 +2725,11 @@ def np_fun(arg):
self._CheckAgainstNumpy(np_fun, jnp_fun, args_maker)
self._CompileAndCheck(jnp_fun, args_maker)

def testTraceSameAxesError(self):
a = jnp.arange(1, 13).reshape(2, 3, 2)
with self.assertRaisesRegex(ValueError, r"axis1 and axis2 can not be same"):
jnp.trace(a, axis1=1, axis2=-2)

@jtu.sample_product(
ashape=[(15,), (16,), (17,)],
vshape=[(), (5,), (5, 5)],
Expand Down

0 comments on commit 96cf2b8

Please sign in to comment.