|
| 1 | +import ctypes |
| 2 | +from typing import Any |
| 3 | + |
1 | 4 | import numpy as np |
| 5 | +import numpy.typing as npt |
| 6 | + |
| 7 | +AR_bool: npt.NDArray[np.bool_] |
| 8 | +AR_ubyte: npt.NDArray[np.ubyte] |
| 9 | +AR_ushort: npt.NDArray[np.ushort] |
| 10 | +AR_uintc: npt.NDArray[np.uintc] |
| 11 | +AR_uint: npt.NDArray[np.uint] |
| 12 | +AR_ulonglong: npt.NDArray[np.ulonglong] |
| 13 | +AR_byte: npt.NDArray[np.byte] |
| 14 | +AR_short: npt.NDArray[np.short] |
| 15 | +AR_intc: npt.NDArray[np.intc] |
| 16 | +AR_int: npt.NDArray[np.int_] |
| 17 | +AR_longlong: npt.NDArray[np.longlong] |
| 18 | +AR_single: npt.NDArray[np.single] |
| 19 | +AR_double: npt.NDArray[np.double] |
| 20 | +AR_void: npt.NDArray[np.void] |
| 21 | + |
| 22 | +pointer: ctypes.pointer[Any] |
2 | 23 |
|
3 | 24 | reveal_type(np.ctypeslib.c_intp()) # E: {c_intp} |
| 25 | + |
| 26 | +reveal_type(np.ctypeslib.ndpointer()) # E: Type[numpy.ctypeslib._ndptr[None]] |
| 27 | +reveal_type(np.ctypeslib.ndpointer(dtype=np.float64)) # E: Type[numpy.ctypeslib._ndptr[numpy.dtype[{float64}]]] |
| 28 | +reveal_type(np.ctypeslib.ndpointer(dtype=float)) # E: Type[numpy.ctypeslib._ndptr[numpy.dtype[Any]]] |
| 29 | +reveal_type(np.ctypeslib.ndpointer(shape=(10, 3))) # E: Type[numpy.ctypeslib._ndptr[None]] |
| 30 | +reveal_type(np.ctypeslib.ndpointer(np.int64, shape=(10, 3))) # E: Type[numpy.ctypeslib._concrete_ndptr[numpy.dtype[{int64}]]] |
| 31 | +reveal_type(np.ctypeslib.ndpointer(int, shape=(1,))) # E: Type[numpy.ctypeslib._concrete_ndptr[numpy.dtype[Any]]] |
| 32 | + |
| 33 | +reveal_type(np.ctypeslib.as_ctypes_type(np.bool_)) # E: Type[ctypes.c_bool] |
| 34 | +reveal_type(np.ctypeslib.as_ctypes_type(np.ubyte)) # E: Type[ctypes.c_ubyte] |
| 35 | +reveal_type(np.ctypeslib.as_ctypes_type(np.ushort)) # E: Type[ctypes.c_ushort] |
| 36 | +reveal_type(np.ctypeslib.as_ctypes_type(np.uintc)) # E: Type[ctypes.c_uint] |
| 37 | +reveal_type(np.ctypeslib.as_ctypes_type(np.uint)) # E: Type[ctypes.c_ulong] |
| 38 | +reveal_type(np.ctypeslib.as_ctypes_type(np.ulonglong)) # E: Type[ctypes.c_ulong] |
| 39 | +reveal_type(np.ctypeslib.as_ctypes_type(np.byte)) # E: Type[ctypes.c_byte] |
| 40 | +reveal_type(np.ctypeslib.as_ctypes_type(np.short)) # E: Type[ctypes.c_short] |
| 41 | +reveal_type(np.ctypeslib.as_ctypes_type(np.intc)) # E: Type[ctypes.c_int] |
| 42 | +reveal_type(np.ctypeslib.as_ctypes_type(np.int_)) # E: Type[ctypes.c_long] |
| 43 | +reveal_type(np.ctypeslib.as_ctypes_type(np.longlong)) # E: Type[ctypes.c_long] |
| 44 | +reveal_type(np.ctypeslib.as_ctypes_type(np.single)) # E: Type[ctypes.c_float] |
| 45 | +reveal_type(np.ctypeslib.as_ctypes_type(np.double)) # E: Type[ctypes.c_double] |
| 46 | +reveal_type(np.ctypeslib.as_ctypes_type(ctypes.c_double)) # E: Type[ctypes.c_double] |
| 47 | +reveal_type(np.ctypeslib.as_ctypes_type("q")) # E: Type[ctypes.c_longlong] |
| 48 | +reveal_type(np.ctypeslib.as_ctypes_type([("i8", np.int64), ("f8", np.float64)])) # E: Type[Any] |
| 49 | +reveal_type(np.ctypeslib.as_ctypes_type("i8")) # E: Type[Any] |
| 50 | +reveal_type(np.ctypeslib.as_ctypes_type("f8")) # E: Type[Any] |
| 51 | + |
| 52 | +reveal_type(np.ctypeslib.as_ctypes(AR_bool.take(0))) # E: ctypes.c_bool |
| 53 | +reveal_type(np.ctypeslib.as_ctypes(AR_ubyte.take(0))) # E: ctypes.c_ubyte |
| 54 | +reveal_type(np.ctypeslib.as_ctypes(AR_ushort.take(0))) # E: ctypes.c_ushort |
| 55 | +reveal_type(np.ctypeslib.as_ctypes(AR_uintc.take(0))) # E: ctypes.c_uint |
| 56 | +reveal_type(np.ctypeslib.as_ctypes(AR_uint.take(0))) # E: ctypes.c_ulong |
| 57 | +reveal_type(np.ctypeslib.as_ctypes(AR_ulonglong.take(0))) # E: ctypes.c_ulong |
| 58 | +reveal_type(np.ctypeslib.as_ctypes(AR_byte.take(0))) # E: ctypes.c_byte |
| 59 | +reveal_type(np.ctypeslib.as_ctypes(AR_short.take(0))) # E: ctypes.c_short |
| 60 | +reveal_type(np.ctypeslib.as_ctypes(AR_intc.take(0))) # E: ctypes.c_int |
| 61 | +reveal_type(np.ctypeslib.as_ctypes(AR_int.take(0))) # E: ctypes.c_long |
| 62 | +reveal_type(np.ctypeslib.as_ctypes(AR_longlong.take(0))) # E: ctypes.c_long |
| 63 | +reveal_type(np.ctypeslib.as_ctypes(AR_single.take(0))) # E: ctypes.c_float |
| 64 | +reveal_type(np.ctypeslib.as_ctypes(AR_double.take(0))) # E: ctypes.c_double |
| 65 | +reveal_type(np.ctypeslib.as_ctypes(AR_void.take(0))) # E: Any |
| 66 | +reveal_type(np.ctypeslib.as_ctypes(AR_bool)) # E: ctypes.Array[ctypes.c_bool] |
| 67 | +reveal_type(np.ctypeslib.as_ctypes(AR_ubyte)) # E: ctypes.Array[ctypes.c_ubyte] |
| 68 | +reveal_type(np.ctypeslib.as_ctypes(AR_ushort)) # E: ctypes.Array[ctypes.c_ushort] |
| 69 | +reveal_type(np.ctypeslib.as_ctypes(AR_uintc)) # E: ctypes.Array[ctypes.c_uint] |
| 70 | +reveal_type(np.ctypeslib.as_ctypes(AR_uint)) # E: ctypes.Array[ctypes.c_ulong] |
| 71 | +reveal_type(np.ctypeslib.as_ctypes(AR_ulonglong)) # E: ctypes.Array[ctypes.c_ulong] |
| 72 | +reveal_type(np.ctypeslib.as_ctypes(AR_byte)) # E: ctypes.Array[ctypes.c_byte] |
| 73 | +reveal_type(np.ctypeslib.as_ctypes(AR_short)) # E: ctypes.Array[ctypes.c_short] |
| 74 | +reveal_type(np.ctypeslib.as_ctypes(AR_intc)) # E: ctypes.Array[ctypes.c_int] |
| 75 | +reveal_type(np.ctypeslib.as_ctypes(AR_int)) # E: ctypes.Array[ctypes.c_long] |
| 76 | +reveal_type(np.ctypeslib.as_ctypes(AR_longlong)) # E: ctypes.Array[ctypes.c_long] |
| 77 | +reveal_type(np.ctypeslib.as_ctypes(AR_single)) # E: ctypes.Array[ctypes.c_float] |
| 78 | +reveal_type(np.ctypeslib.as_ctypes(AR_double)) # E: ctypes.Array[ctypes.c_double] |
| 79 | +reveal_type(np.ctypeslib.as_ctypes(AR_void)) # E: ctypes.Array[Any] |
| 80 | + |
| 81 | +reveal_type(np.ctypeslib.as_array(AR_ubyte)) # E: numpy.ndarray[Any, numpy.dtype[{ubyte}]] |
| 82 | +reveal_type(np.ctypeslib.as_array(1)) # E: numpy.ndarray[Any, numpy.dtype[Any]] |
| 83 | +reveal_type(np.ctypeslib.as_array(pointer)) # E: numpy.ndarray[Any, numpy.dtype[Any]] |
0 commit comments