Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
scalars.pyi87 linesDownload Raw Back to fail
1import numpy as np
2
3f2: np.float16
4f8: np.float64
5c8: np.complex64
6
7# Construction
8
9np.float32(3j)  # type: ignore[arg-type]
10
11# Technically the following examples are valid NumPy code. But they
12# are not considered a best practice, and people who wish to use the
13# stubs should instead do
14#
15# np.array([1.0, 0.0, 0.0], dtype=np.float32)
16# np.array([], dtype=np.complex64)
17#
18# See e.g. the discussion on the mailing list
19#
20# https://mail.python.org/pipermail/numpy-discussion/2020-April/080566.html
21#
22# and the issue
23#
24# https://github.com/numpy/numpy-stubs/issues/41
25#
26# for more context.
27np.float32([1.0, 0.0, 0.0])  # type: ignore[arg-type]
28np.complex64([])  # type: ignore[call-overload]
29
30# TODO: protocols (can't check for non-existent protocols w/ __getattr__)
31
32np.datetime64(0)  # type: ignore[call-overload]
33
34class A:
35    def __float__(self) -> float: ...
36
37np.int8(A())  # type: ignore[arg-type]
38np.int16(A())  # type: ignore[arg-type]
39np.int32(A())  # type: ignore[arg-type]
40np.int64(A())  # type: ignore[arg-type]
41np.uint8(A())  # type: ignore[arg-type]
42np.uint16(A())  # type: ignore[arg-type]
43np.uint32(A())  # type: ignore[arg-type]
44np.uint64(A())  # type: ignore[arg-type]
45
46np.void("test")  # type: ignore[call-overload]
47np.void("test", dtype=None)  # type: ignore[call-overload]
48
49np.generic(1)  # type: ignore[abstract]
50np.number(1)  # type: ignore[abstract]
51np.integer(1)  # type: ignore[abstract]
52np.inexact(1)  # type: ignore[abstract]
53np.character("test")  # type: ignore[abstract]
54np.flexible(b"test")  # type: ignore[abstract]
55
56np.float64(value=0.0)  # type: ignore[call-arg]
57np.int64(value=0)  # type: ignore[call-arg]
58np.uint64(value=0)  # type: ignore[call-arg]
59np.complex128(value=0.0j)  # type: ignore[call-overload]
60np.str_(value="bob")  # type: ignore[call-overload]
61np.bytes_(value=b"test")  # type: ignore[call-overload]
62np.void(value=b"test")  # type: ignore[call-overload]
63np.bool(value=True)  # type: ignore[call-overload]
64np.datetime64(value="2019")  # type: ignore[call-overload]
65np.timedelta64(value=0)  # type: ignore[call-overload]
66
67np.bytes_(b"hello", encoding="utf-8")  # type: ignore[call-overload]
68np.str_("hello", encoding="utf-8")  # type: ignore[call-overload]
69
70f8.item(1)  # type: ignore[call-overload]
71f8.item((0, 1))  # type: ignore[arg-type]
72f8.squeeze(axis=1)  # type: ignore[arg-type]
73f8.squeeze(axis=(0, 1))  # type: ignore[arg-type]
74f8.transpose(1)  # type: ignore[arg-type]
75
76def func(a: np.float32) -> None: ...
77
78func(f2)  # type: ignore[arg-type]
79func(f8)  # type: ignore[arg-type]
80
81c8.__getnewargs__()  # type: ignore[attr-defined]
82f2.__getnewargs__()  # type: ignore[attr-defined]
83f2.hex()  # type: ignore[attr-defined]
84np.float16.fromhex("0x0.0p+0")  # type: ignore[attr-defined]
85f2.__trunc__()  # type: ignore[attr-defined]
86f2.__getformat__("float")  # type: ignore[attr-defined]
87 
codekingpro/portable-devtools · Team Ai