Skip to content

Commit f32cdf6

Browse files
author
Bas van Beek
committed
MAINT: Let ndarray.__imatmul__ handle inplace matrix multiplication in the array-api
1 parent 666a64c commit f32cdf6

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

numpy/array_api/_array_object.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -819,23 +819,13 @@ def __imatmul__(self: Array, other: Array, /) -> Array:
819819
"""
820820
Performs the operation __imatmul__.
821821
"""
822-
# Note: NumPy does not implement __imatmul__.
823-
824822
# matmul is not defined for scalars, but without this, we may get
825823
# the wrong error message from asarray.
826824
other = self._check_allowed_dtypes(other, "numeric", "__imatmul__")
827825
if other is NotImplemented:
828826
return other
829-
830-
# __imatmul__ can only be allowed when it would not change the shape
831-
# of self.
832-
other_shape = other.shape
833-
if self.shape == () or other_shape == ():
834-
raise ValueError("@= requires at least one dimension")
835-
if len(other_shape) == 1 or other_shape[-1] != other_shape[-2]:
836-
raise ValueError("@= cannot change the shape of the input array")
837-
self._array[:] = self._array.__matmul__(other._array)
838-
return self
827+
res = self._array.__imatmul__(other._array)
828+
return self.__class__._new(res)
839829

840830
def __rmatmul__(self: Array, other: Array, /) -> Array:
841831
"""

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy