File tree Expand file tree Collapse file tree 4 files changed +27
-0
lines changed Expand file tree Collapse file tree 4 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 6
6
"HasDType" ,
7
7
"HasDevice" ,
8
8
"HasMatrixTranspose" ,
9
+ "HasNDim" ,
9
10
"__version__" ,
10
11
"__version_tuple__" ,
11
12
)
16
17
HasDevice ,
17
18
HasDType ,
18
19
HasMatrixTranspose ,
20
+ HasNDim ,
19
21
)
20
22
from ._version import version as __version__ , version_tuple as __version_tuple__
Original file line number Diff line number Diff line change 4
4
"HasDType" ,
5
5
"HasDevice" ,
6
6
"HasMatrixTranspose" ,
7
+ "HasNDim" ,
7
8
)
8
9
9
10
from types import ModuleType
@@ -100,11 +101,26 @@ def mT(self) -> Self: # noqa: N802
100
101
...
101
102
102
103
104
+ class HasNDim (Protocol ):
105
+ """Protocol for array classes that have a number of dimensions attribute."""
106
+
107
+ @property
108
+ def ndim (self ) -> int :
109
+ """Number of array dimensions (axes).
110
+
111
+ Returns:
112
+ int: number of array dimensions (axes).
113
+
114
+ """
115
+ ...
116
+
117
+
103
118
class Array (
104
119
# ------ Attributes -------
105
120
HasDType [DTypeT_co ],
106
121
HasDevice ,
107
122
HasMatrixTranspose ,
123
+ HasNDim ,
108
124
# ------- Methods ---------
109
125
HasArrayNamespace [NamespaceT_co ],
110
126
# -------------------------
Original file line number Diff line number Diff line change @@ -63,3 +63,7 @@ _: object = x_i32.device
63
63
# Check Attribute `.mT`
64
64
_ : xpt .Array [dtype [Any ]] = x_f32 .mT
65
65
_ : xpt .Array [dtype [Any ]] = x_i32 .mT
66
+
67
+ # Check Attribute `.ndim`
68
+ _ : int = x_f32 .ndim
69
+ _ : int = x_i32 .ndim
Original file line number Diff line number Diff line change @@ -71,3 +71,8 @@ _: object = x_b.device
71
71
_ : xpt .Array [np .dtype [F32 ]] = x_f32 .mT
72
72
_ : xpt .Array [np .dtype [I32 ]] = x_i32 .mT
73
73
_ : xpt .Array [np .dtype [B ]] = x_b .mT
74
+
75
+ # Check Attribute `.ndim`
76
+ _ : int = x_f32 .ndim
77
+ _ : int = x_i32 .ndim
78
+ _ : int = x_b .ndim
You can’t perform that action at this time.
0 commit comments