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

API: Add diagonal and trace to numpy.linalg [Array API] #24887

Merged
merged 1 commit into from Oct 9, 2023

Conversation

mtsokol
Copy link
Member

@mtsokol mtsokol commented Oct 9, 2023

Hi @rgommers @ngoldbaum,

This PR contains another set of small Array API compatibility changes. It adds numpy.linalg.diagonal and numpy.linalg.trace with docs taken from Array API specification.

@mtsokol mtsokol force-pushed the array-api-diagonal-and-trace branch from 21c0a39 to cefa7eb Compare October 9, 2023 13:40
@mtsokol mtsokol self-assigned this Oct 9, 2023
@mtsokol mtsokol changed the title API: Add diagonal and trace to numpy.linalg API: Add diagonal and trace to numpy.linalg [Array API] Oct 9, 2023
@charris charris merged commit 27f39dc into numpy:main Oct 9, 2023
52 checks passed
@charris
Copy link
Member

charris commented Oct 9, 2023

Thanks Mateusz.

@mtsokol mtsokol deleted the array-api-diagonal-and-trace branch October 9, 2023 19:10
@rgommers rgommers added this to the 2.0.0 release milestone Oct 10, 2023
@mtsokol
Copy link
Member Author

mtsokol commented Oct 10, 2023

It looks that I forgot a release note file. I will add it in a follow-up PR.

Returns specified diagonals of a matrix (or a stack of matrices) ``x``.

This function is Array API compatible, contrary to
:py:func:`numpy.diagonal`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Seeing this only because these new additions to the numpy API triggered astropy warnings, and perhaps too late since it is already merged, but wouldn't it be better to tell what the difference is here rather than what is here now? As is, this comment forces the user to either look up the array API or to look at the docstring of np.diagonal to find out that it is the axes that are used. Maybe add something like
"""
This function is Array API compatible, contrary to
:py:func:numpy.diagonal: the matrix is assumed
to be defined by the last two dimensions.
"""

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right - it's clearer about the difference. I will update the docstring.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants