Skip to content

Commit fed6a1c

Browse files
committed
feat: HasMatrixTranspose
1 parent f77be13 commit fed6a1c

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/array_api_typing/_array.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from pathlib import Path
99
from types import ModuleType
10-
from typing import Literal, Never, Protocol, TypeAlias
10+
from typing import Literal, Never, Protocol, Self, TypeAlias
1111
from typing_extensions import TypeVar
1212

1313
import optype as op
@@ -71,11 +71,33 @@ def device(self) -> object: # TODO: more specific type
7171
...
7272

7373

74+
class HasMatrixTranspose(Protocol):
75+
"""Protocol for array classes that have a matrix transpose attribute."""
76+
77+
@property
78+
def mT(self) -> Self: # noqa: N802
79+
"""Transpose of a matrix (or a stack of matrices).
80+
81+
If an array instance has fewer than two dimensions, an error should be
82+
raised.
83+
84+
Returns:
85+
Self: array whose last two dimensions (axes) are permuted in reverse
86+
order relative to original array (i.e., for an array instance
87+
having shape `(..., M, N)`, the returned array must have shape
88+
`(..., N, M))`. The returned array must have the same data type
89+
as the original array.
90+
91+
"""
92+
...
93+
94+
7495
@docstring_setter(**_array_docstrings)
7596
class Array(
7697
# ------ Attributes -------
7798
HasDType[DType_co],
7899
HasDevice,
100+
HasMatrixTranspose,
79101
# ------ Methods -------
80102
HasArrayNamespace[NS_co],
81103
op.CanPosSelf,

0 commit comments

Comments
 (0)