@@ -3,7 +3,7 @@ import builtins
3
3
from typing import (
4
4
Any , Dict , Iterable , List , Optional , Mapping , Sequence , Sized ,
5
5
SupportsInt , SupportsFloat , SupportsComplex , SupportsBytes , SupportsAbs ,
6
- Text , Tuple , Union ,
6
+ Text , Tuple , Type , TypeVar , Union ,
7
7
)
8
8
9
9
import sys
@@ -131,7 +131,7 @@ class dtype:
131
131
def str (self ) -> builtins .str : ...
132
132
133
133
@property
134
- def type (self ) -> builtins . type : ...
134
+ def type (self ) -> Type [ generic ] : ...
135
135
136
136
137
137
_Dtype = dtype # to avoid name conflicts with ndarray.dtype
@@ -195,35 +195,24 @@ class flatiter:
195
195
def __next__ (self ) -> Any : ...
196
196
197
197
198
- class ndarray (Iterable , Sized , SupportsInt , SupportsFloat , SupportsComplex ,
199
- SupportsBytes , SupportsAbs [Any ]):
200
-
201
- imag : ndarray
202
- real : ndarray
203
-
198
+ _ArraySelf = TypeVar ("_ArraySelf" , bound = _ArrayOrScalarCommon )
199
+ class _ArrayOrScalarCommon (SupportsInt , SupportsFloat , SupportsComplex ,
200
+ SupportsBytes , SupportsAbs [Any ]):
204
201
@property
205
- def T (self ) -> ndarray : ...
202
+ def T (self : _ArraySelf ) -> _ArraySelf : ...
206
203
207
204
@property
208
205
def base (self ) -> Optional [ndarray ]: ...
209
206
210
207
@property
211
208
def dtype (self ) -> _Dtype : ...
212
- @dtype .setter
213
- def dtype (self , value : _DtypeLike ): ...
214
-
215
- @property
216
- def ctypes (self ) -> _ctypes : ...
217
209
218
210
@property
219
211
def data (self ) -> memoryview : ...
220
212
221
213
@property
222
214
def flags (self ) -> _flagsobj : ...
223
215
224
- @property
225
- def flat (self ) -> flatiter : ...
226
-
227
216
@property
228
217
def size (self ) -> int : ...
229
218
@@ -238,22 +227,9 @@ class ndarray(Iterable, Sized, SupportsInt, SupportsFloat, SupportsComplex,
238
227
239
228
@property
240
229
def shape (self ) -> _Shape : ...
241
- @shape .setter
242
- def shape (self , value : _ShapeLike ): ...
243
230
244
231
@property
245
232
def strides (self ) -> _Shape : ...
246
- @strides .setter
247
- def strides (self , value : _ShapeLike ): ...
248
-
249
- # Many of these special methods are irrelevant currently, since protocols
250
- # aren't supported yet. That said, I'm adding them for completeness.
251
- # https://docs.python.org/3/reference/datamodel.html
252
- def __len__ (self ) -> int : ...
253
- def __getitem__ (self , key ) -> Any : ...
254
- def __setitem__ (self , key , value ): ...
255
- def __iter__ (self ) -> Any : ...
256
- def __contains__ (self , key ) -> bool : ...
257
233
258
234
def __int__ (self ) -> int : ...
259
235
def __float__ (self ) -> float : ...
@@ -269,17 +245,8 @@ class ndarray(Iterable, Sized, SupportsInt, SupportsFloat, SupportsComplex,
269
245
def __str__ (self ) -> str : ...
270
246
def __repr__ (self ) -> str : ...
271
247
272
- def __index__ (self ) -> int : ...
273
-
274
- def __copy__ (self , order : str = ...) -> ndarray : ...
275
- def __deepcopy__ (self , memo : dict ) -> ndarray : ...
276
-
277
- # https://github.com/numpy/numpy/blob/v1.13.0/numpy/lib/mixins.py#L63-L181
278
-
279
- # TODO(shoyer): add overloads (returning ndarray) for cases where other is
280
- # known not to define __array_priority__ or __array_ufunc__, such as for
281
- # numbers or other numpy arrays. Or even better, use protocols (once they
282
- # work).
248
+ def __copy__ (self : _ArraySelf , order : str = ...) -> _ArraySelf : ...
249
+ def __deepcopy__ (self : _ArraySelf , memo : dict ) -> _ArraySelf : ...
283
250
284
251
def __lt__ (self , other ): ...
285
252
def __le__ (self , other ): ...
@@ -349,15 +316,122 @@ class ndarray(Iterable, Sized, SupportsInt, SupportsFloat, SupportsComplex,
349
316
def __matmul__ (self , other ): ...
350
317
def __rmatmul__ (self , other ): ...
351
318
352
- def __neg__ (self ) -> ndarray : ...
353
- def __pos__ (self ) -> ndarray : ...
354
- def __abs__ (self ) -> ndarray : ...
355
- def __invert__ (self ) -> ndarray : ...
319
+ def __neg__ (self : _ArraySelf ) -> _ArraySelf : ...
320
+ def __pos__ (self : _ArraySelf ) -> _ArraySelf : ...
321
+ def __abs__ (self : _ArraySelf ) -> _ArraySelf : ...
322
+ def __invert__ (self : _ArraySelf ) -> _ArraySelf : ...
356
323
357
324
# TODO(shoyer): remove when all methods are defined
358
325
def __getattr__ (self , name ) -> Any : ...
359
326
360
327
328
+ class ndarray (_ArrayOrScalarCommon , Iterable , Sized ):
329
+ real : ndarray
330
+ imag : ndarray
331
+
332
+ @property
333
+ def dtype (self ) -> _Dtype : ...
334
+ @dtype .setter
335
+ def dtype (self , value : _DtypeLike ): ...
336
+
337
+ @property
338
+ def ctypes (self ) -> _ctypes : ...
339
+
340
+ @property
341
+ def shape (self ) -> _Shape : ...
342
+ @shape .setter
343
+ def shape (self , value : _ShapeLike ): ...
344
+
345
+ @property
346
+ def flat (self ) -> flatiter : ...
347
+
348
+ @property
349
+ def strides (self ) -> _Shape : ...
350
+ @strides .setter
351
+ def strides (self , value : _ShapeLike ): ...
352
+
353
+ # Many of these special methods are irrelevant currently, since protocols
354
+ # aren't supported yet. That said, I'm adding them for completeness.
355
+ # https://docs.python.org/3/reference/datamodel.html
356
+ def __len__ (self ) -> int : ...
357
+ def __getitem__ (self , key ) -> Any : ...
358
+ def __setitem__ (self , key , value ): ...
359
+ def __iter__ (self ) -> Any : ...
360
+ def __contains__ (self , key ) -> bool : ...
361
+ def __index__ (self ) -> int : ...
362
+
363
+ class generic (_ArrayOrScalarCommon ):
364
+ def __init__ (self , value : Any = ...) -> None : ...
365
+ @property
366
+ def base (self ) -> None : ...
367
+
368
+ class _real_generic (generic ):
369
+ @property
370
+ def real (self : _ArraySelf ) -> _ArraySelf : ...
371
+
372
+ @property
373
+ def imag (self : _ArraySelf ) -> _ArraySelf : ...
374
+
375
+ class number (generic ):
376
+ def __init__ (
377
+ self , value : Union [SupportsInt , SupportsFloat ] = ...
378
+ ) -> None : ...
379
+ class bool_ (_real_generic ): ...
380
+ class object_ (generic ): ...
381
+ class datetime64 (_real_generic ): ...
382
+
383
+ class integer (number , _real_generic ): ...
384
+ class signedinteger (integer ): ...
385
+ class int8 (signedinteger ): ...
386
+ class int16 (signedinteger ): ...
387
+ class int32 (signedinteger ): ...
388
+ class int64 (signedinteger ): ...
389
+ class timedelta64 (signedinteger ): ...
390
+
391
+ class unsignedinteger (integer ): ...
392
+ class uint8 (unsignedinteger ): ...
393
+ class uint16 (unsignedinteger ): ...
394
+ class uint32 (unsignedinteger ): ...
395
+ class uint64 (unsignedinteger ): ...
396
+
397
+ class inexact (number ): ...
398
+ class floating (inexact , _real_generic ): ...
399
+ class float16 (floating ): ...
400
+ class float32 (floating ): ...
401
+ class float64 (floating ): ...
402
+
403
+ class complexfloating (inexact ):
404
+ def __init__ (
405
+ self ,
406
+ value : Union [SupportsInt , SupportsFloat , SupportsComplex ,
407
+ complex ] = ...,
408
+ ) -> None : ...
409
+ class complex64 (complexfloating ):
410
+ @property
411
+ def real (self ) -> float32 : ...
412
+ @property
413
+ def imag (self ) -> float32 : ...
414
+ class complex128 (complexfloating ):
415
+ @property
416
+ def real (self ) -> float64 : ...
417
+ @property
418
+ def imag (self ) -> float64 : ...
419
+
420
+ class flexible (_real_generic ): ...
421
+ class void (flexible ): ...
422
+ class character (_real_generic ): ...
423
+ class bytes_ (character ): ...
424
+ class str_ (character ): ...
425
+
426
+ # TODO(alan): Platform dependent types
427
+ # longcomplex, longdouble, longfloat
428
+ # bytes, short, intc, intp, longlong
429
+ # half, single, double, longdouble
430
+ # uint_, int_, float_, complex_
431
+ # float128, complex256
432
+ # float96
433
+
434
+
361
435
def array (
362
436
object : object ,
363
437
dtype : _DtypeLike = ...,
0 commit comments