-
Notifications
You must be signed in to change notification settings - Fork 19.7k
Validate axis1 != axis2 in ops.diagonal #22593
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2694,6 +2694,15 @@ def compute_output_spec(self, x): | |
| f"`x` is of shape {x.shape}." | ||
| ) | ||
|
|
||
| ndim = len(x_shape) | ||
| ax1 = self.axis1 if self.axis1 >= 0 else self.axis1 + ndim | ||
| ax2 = self.axis2 if self.axis2 >= 0 else self.axis2 + ndim | ||
| if ax1 == ax2: | ||
| raise ValueError( | ||
| "`axis1` and `axis2` cannot be the same. " | ||
| f"Received: axis1={self.axis1}, axis2={self.axis2}" | ||
| ) | ||
rstar327 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| shape_2d = [x_shape[self.axis1], x_shape[self.axis2]] | ||
| x_shape[self.axis1] = -1 | ||
| x_shape[self.axis2] = -1 | ||
|
|
@@ -2767,6 +2776,14 @@ def diagonal(x, offset=0, axis1=0, axis2=1): | |
| axis1=axis1, | ||
| axis2=axis2, | ||
| ).symbolic_call(x) | ||
| x_ndim = len(x.shape) | ||
| ax1 = axis1 if axis1 >= 0 else axis1 + x_ndim | ||
| ax2 = axis2 if axis2 >= 0 else axis2 + x_ndim | ||
| if ax1 == ax2: | ||
| raise ValueError( | ||
| "`axis1` and `axis2` cannot be the same. " | ||
| f"Received: axis1={axis1}, axis2={axis2}" | ||
| ) | ||
rstar327 marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+2779
to
+2786
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current pattern used is to not have any code in these functions, they're supposed to delegate to the backend functions. So please move to whichever backend doesn't throw a proper exception (tensorflow is sounds like).
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, never mind. Validation is fine. But:
|
||
| return backend.numpy.diagonal( | ||
| x, | ||
| offset=offset, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use
ax1 = canonicalize_axis(self.axis1, ndim)which does some validation.