Skip to content

Commit 5b17ca0

Browse files
committed
✨: add HasArrayRMatmul protocol to support right matrix multiplication operator for array classes
1 parent cb3fa5d commit 5b17ca0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/array_api_typing/_array.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,22 @@ def __imatmul__(self, other: Self, /) -> Self:
434434
...
435435

436436

437+
class HasArrayRMatmul(Protocol):
438+
"""Protocol for array classes that support the right matrix multiplication operator.""" # noqa: E501
439+
440+
def __rmatmul__(self, other: Self, /) -> Self:
441+
"""Calculates the matrix product for each element of an array instance with the respective element of the array other.
442+
443+
Args:
444+
other: multiplicand array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
445+
446+
Returns:
447+
an array containing the element-wise matrix products. The returned array must have a data type determined by Type Promotion Rules.
448+
449+
""" # noqa: E501
450+
...
451+
452+
437453
class HasArrayInvert(Protocol):
438454
"""Protocol for array classes that support the inverse operator."""
439455

@@ -731,6 +747,7 @@ class Array(
731747
HasArrayRPow,
732748
HasArrayMatmul,
733749
HasArrayIMatmul,
750+
HasArrayRMatmul,
734751
HasArrayInvert,
735752
HasArrayAnd,
736753
HasArrayIAnd,

0 commit comments

Comments
 (0)