8000 DOC: Enumerate the differences between numpy and numpy.array_api by asmeurer · Pull Request #21260 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

DOC: Enumerate the differences between numpy and numpy.array_api #21260

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

Merged
merged 10 commits into from
Apr 4, 2022
Merged
Prev Previous commit
Next Next commit
Update review comments on the array API document
  • Loading branch information
asmeurer committed Mar 29, 2022
commit be1f91cf5493c934a64d185038023cf6f3cc03cc
21 changes: 12 additio 8000 ns & 9 deletions doc/source/reference/array_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ independently of values or shapes.
* - ``__pow__`` and ``__rpow__`` do not do value-based casting for 0-D
arrays.
- **Breaking**
- For example, ``np.array(0., dtype=float32)*np.array(0.,
- For example, ``np.array(0., dtype=float32)**np.array(0.,
dtype=float64)`` is ``float32``. Note that this is value-based casting
Copy link
Member

Choose a reason for hiding this comment

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

The example is meant to use **, and maybe can just be considered a bug, since it does not use the typical promotion rules. But then, if we change promotion rules, this should just align anyway, so it hardly matters.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't tell what's a bug or not when it comes to value-based casting. It definitely is odd that __pow__ is the only operator that does this.

on 0-D arrays, not scalars.
* - No cross-kind casting.
Expand Down Expand Up @@ -534,11 +534,13 @@ Array Object Differences
- Type
- Notes
* - No array scalars
- ???
- The spec does not have array scalars, only 0-D arrays. It is not clear
if NumPy's scalars deviate from the spec 0-D array behavior in any ways
other than the ones outlined in
:ref:`array_api-type-promotion-differences`.
- **Strictness**
- The spec does not have array scalars, only 0-D arrays. However, other
than the promotion differences outlined in
:ref:`array_api-type-promotion-differences`, scalars duck type as 0-D
arrays for the purposes of the spec. The are immutable, but the spec
`does not require mutability
<https://data-apis.org/array-api/latest/design_topics/copies_views_and_mutation.html>`__.
* - ``bool()``, ``int()``, and ``float()`` only work on 0-D arrays.
- **Strictness**
- See https://github.com/numpy/numpy/issues/10404.
Expand Down Expand Up @@ -627,7 +629,8 @@ Linear Algebra Differences
-
* - ``diagonal`` operates on the last two axes.
- **Breaking**
Copy link
Member

Choose a reason for hiding this comment

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

But you are moving it to linalg, which may well be a way to do the transition in NumPy. I guess in a sense it is breaking, because having np.diagonal and np.linalg.diagonal do different things may be too confusing to keep both.

Copy link
Member Author

Choose a reason for hiding this comment

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

I hadn't considered that. I'll leave it as "breaking" but add a note about this.

This is definitely one of the worst "breaking" cases here for NumPy. NumPy's diagonal is completely spec noncompliant, and not in a small way either, since the semantics completely differ when you have rank > 2. I don't know if the current behavior is deprecatable either.

-
- Strictly speaking this can be **compatible** because ``diagonal`` is
moved to the ``linalg`` namespace.
* - ``eigh``, ``qr``, ``slogdet`` and ``svd`` return a named tuple.
- **Compatible**
- The corresponding ``numpy`` functions return a ``tuple``, with the
Expand All @@ -637,7 +640,7 @@ Linear Algebra Differences
- The ``norm`` function has been omitted from the array API and split
into ``matrix_norm`` for matrix norms and ``vector_norm`` for vector
norms. Note that ``vector_norm`` supports any number of axes, whereas
``np.norm`` only supports a single axis for vector norms.
``np.linalg.norm`` only supports a single axis for vector norms.
* - ``matrix_rank`` has an ``rtol`` keyword argument instead of ``tol``.
- **Compatible**
- In the array API, ``rtol`` filters singular values smaller than
Expand Down Expand Up 5553 @@ -698,7 +701,7 @@ Manipulation Functions Differences
- No cross-kind casting. No value-based casting on scalars.
* - ``stack`` has different default casting rules from ``np.stack``
- **Strictness**
- No cross-kind casting. No value-based casting on scalars.
- No cross-kind casting.
* - New function ``permute_dims``.
- **Compatible**
- Unlike ``np.transpose``, the ``axis`` keyword argument to
Expand Down
0