Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4b34571
Add functions from the linear algebra array API extension
asmeurer Jun 25, 2021
494d0e8
Move linear algebra named tuples to the linalg file to avoid circular…
asmeurer Jun 25, 2021
7e2ceb1
Fix discrepancies between the NumPy cross() and the array API cross()
asmeurer Jun 25, 2021
256f3da
Fix some bugs in the array API linear algebra module
asmeurer Jun 25, 2021
c9357a7
Fix some more bugs in the array API linear algebra module
asmeurer Jun 25, 2021
a6d2402
Merge branch 'array-api-updates1' into array-api-linalg
asmeurer Sep 29, 2021
c7be50f
Update the array_api linalg extension code for changes to the array_a…
asmeurer Sep 24, 2021
9a9240d
Fix Array class rename in the array API linear algebra extension
asmeurer Sep 24, 2021
e60c40a
Remove references to eig and eigvals in the array API submodule
asmeurer Sep 24, 2021
5c27cfe
Remove a todo item from the numpy/_array_api/__init__.py docstring
asmeurer Sep 24, 2021
021c81b
Remove numpy/array_api/_linear_algebra_functions.py
asmeurer Sep 24, 2021
03c2e5e
Fix the mT attribute in the array_api extension
asmeurer Sep 27, 2021
b29b03b
Use mT in the array_api cholesky
asmeurer Sep 27, 2021
3b355a7
Update the array API linalg extension signatures
asmeurer Sep 27, 2021
2e26f56
Update the array_api linalg extension namedtuple names
asmeurer Sep 27, 2021
100b355
Fix the signature for the array API vector_norm
asmeurer Oct 1, 2021
17f7b96
Fix the implementation of the array API matrix_norm() and vector_norm()
asmeurer Oct 1, 2021
edcb209
Fix the logic in vector_norm()
asmeurer Oct 1, 2021
b099684
Use CamelCase for the array_api linalg namedtuple classes
asmeurer Oct 1, 2021
ee49a7c
Add notes for array API linalg functions that aren't in np.linalg
asmeurer Oct 6, 2021
89dbcb3
Fix the array API diagonal and trace implementations
asmeurer Oct 6, 2021
2b41f91
Small fixes to numpy.array_api.linalg docstrings
asmeurer Nov 11, 2021
3da93d5
Update numpy.array_api.linalg.vecdot to not accept axis=None
asmeurer Nov 11, 2021
608c4bc
Remove the axis argument from numpy.array_api.matrix_norm
asmeurer Nov 11, 2021
dfcccbe
Make numpy.array_api.linalg.solve only allow stacks of matrices
asmeurer Nov 11, 2021
f13b22d
Update Literal types to not use floating-point literals
asmeurer Nov 11, 2021
939eeb3
Update the field names for the array API qr() and svd() namedtuples
asmeurer Nov 11, 2021
7375556
Merge remote-tracking branch 'upstream/main' into array-api-linalg
rgommers Nov 13, 2021
5e31552
MAINT: add `array_api.linalg` to public API test
rgommers Nov 13, 2021
07dbb8c
MAINT: address all remaining review comments
rgommers Nov 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions numpy/array_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@
- The spec is still in an RFC phase and may still have minor updates, which
will need to be reflected here.

- The linear algebra extension in the spec will be added in a future pull
request.

- Complex number support in array API spec is planned but not yet finalized,
as are the fft extension and certain linear algebra functions such as eig
that require complex dtypes.
Expand Down Expand Up @@ -334,12 +331,13 @@
"trunc",
]

# einsum is not yet implemented in the array API spec.
# linalg is an extension in the array API spec, which is a sub-namespace. Only
# a subset of functions in it are imported into the top-level namespace.
from . import linalg

# from ._linear_algebra_functions import einsum
# __all__ += ['einsum']
__all__ += ["linalg"]

from ._linear_algebra_functions import matmul, tensordot, matrix_transpose, vecdot
from .linalg import matmul, tensordot, matrix_transpose, vecdot

__all__ += ["matmul", "tensordot", "matrix_transpose", "vecdot"]

Expand Down
2 changes: 1 addition & 1 deletion numpy/array_api/_array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ def device(self) -> Device:
# Note: mT is new in array API spec (see matrix_transpose)
@property
def mT(self) -> Array:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I feel this was discussed in NumPy before (including the potential .T limitation!), time to revive that discussion!? I find it mildly annoying that we do these things in the new namespace, but seem avers to discussing it for NumPy proper. If we can get away with doing these things in NumPy it would be the best way to move code towards the better standard!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The new APIs for matrix transpose were chosen so that they can be as backwards compatible as possible with libraries like NumPy that already use .T for reversing the axes. See data-apis/array-api#228 and the corresponding PRs.

Copy link
Copy Markdown
Member

@rgommers rgommers Sep 30, 2021

Choose a reason for hiding this comment

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

I feel this was discussed in NumPy before (including the potential .T limitation!), time to revive that discussion!?

Yes I think so.

I find it mildly annoying that we do these things in the new namespace, but seem avers to discussing it for NumPy proper.

I don't think we are, it's just that no one followed up/through on making matrix_transpose public, and the discussion was framed around a big backcompat break in .T, which did not help. I think no one would object to making the private matrix_transpose public (EDIT: and then add .mT), it just needs doing?

If we can get away with doing these things in NumPy it would be the best way to move code towards the better standard!

agreed

from ._linear_algebra_functions import matrix_transpose
from .linalg import matrix_transpose
return matrix_transpose(self)

@property
Expand Down
67 changes: 0 additions & 67 deletions numpy/array_api/_linear_algebra_functions.py

This file was deleted.

9 changes: 5 additions & 4 deletions numpy/array_api/_statistical_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ def sum(
) -> Array:
if x.dtype not in _numeric_dtypes:
raise TypeError("Only numeric dtypes are allowed in sum")
# Note: sum() and prod() always upcast float32 to float64 for dtype=None
# We need to do so here before summing to avoid overflow
# Note: sum() and prod() always upcast integers to (u)int64 and float32 to
# float64 for dtype=None. `np.sum` does that too for integers, but not for
# float32, so we need to special-case it here
if dtype is None and x.dtype == float32:
x = asarray(x, dtype=float64)
return Array._new(np.sum(x._array, axis=axis, keepdims=keepdims))
dtype = float64
return Array._new(np.sum(x._array, axis=axis, dtype=dtype, keepdims=keepdims))


def var(
Expand Down
Loading