1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
U
O±d¡(ã    @s:ddlmZddlmZmZmZmZmZerTddlm    Z    m
Z
m Z m Z m Z ddlmZddlmZddlZdd    „Zdddd
œd d d dddœdd„ZdKdddœdddd d ddœdd„Zdddœdd d ddœdd„Zdddœdd d ddœdd„ZdLdddd œd!d"d!d d dd#œd$d%„Zd&dd'œd(d)„Zdddœddd d dd*œd+d,„Zdddœddd d dd-œd.d/„Zddd0d1œd!ddd d d2dd3œd4d5„Zd6d7œdd8d9d:œd;d<„Zdddœdd d ddœd=d>„Zdddœdd d ddœd?d@„Z ddAœdd!ddBœdCdD„Z!ddAœdd!ddBœdEdF„Z"dddœdd d ddœdGdH„Z#dddœdd d ddœdIdJ„Z$dS)Mé)Ú annotations)Ú TYPE_CHECKINGÚListÚOptionalÚTupleÚUnioné)ÚArrayÚDeviceÚDtypeÚNestedSequenceÚSupportsBufferProtocol)ÚSequence)Ú _all_dtypesNcCs(dtD]}||krdSqtdƒ‚dS)N)Nz)dtype must be one of the supported dtypes)rÚ
ValueError)ÚdtypeÚd©rúZd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\numpy/array_api/_creation_functions.pyÚ_check_valid_dtypes r)rÚdeviceÚcopyzZUnion[Array, bool, int, float, NestedSequence[bool | int | float], SupportsBufferProtocol]zOptional[Dtype]zOptional[Device]z#Optional[Union[bool, np._CopyMode]]r    )ÚobjrrrÚreturncCsÐddlm}t|ƒ|dkr*td|›ƒ‚|dtjjfkrBtdƒ‚t||ƒrŽ|dk    rb|j    |krbd}|dtjj
fkrŠ|  tj |j d|d    ¡S|S|dkr¸t|tƒr¸|d
ks°|d kr¸td ƒ‚tj||d }|  |¡S)z~
    Array API compatible wrapper for :py:func:`np.asarray <numpy.asarray>`.
 
    See its docstring for more information.
    r©r    ©ÚcpuNúUnsupported device Fz!copy=False is not yet implementedNT)rrllûÿÿÿz&Integer out of bounds for array dtypes©r)Ú _array_objectr    rrÚnpZ    _CopyModeZ    IF_NEEDEDÚNotImplementedErrorÚ
isinstancerZALWAYSÚ_newÚarrayÚ_arrayÚintÚ OverflowErrorÚasarray)rrrrr    Úresrrrr(s  
"r()rrzOptional[Union[int, float]]zUnion[int, float])ÚstopÚstepÚstartrrrcCsBddlm}t|ƒ|dkr*td|›ƒ‚| tj||||d¡S)z|
    Array API compatible wrapper for :py:func:`np.arange <numpy.arange>`.
 
    See its docstring for more information.
    rrrr)r*r+r)rr    rrr#r Úarange)r,r*r+rrr    rrrr-Ks
 r-zUnion[int, Tuple[int, ...]])ÚshaperrrcCs>ddlm}t|ƒ|dkr*td|›ƒ‚| tj||d¡S)zz
    Array API compatible wrapper for :py:func:`np.empty <numpy.empty>`.
 
    See its docstring for more information.
    rrrrr)rr    rrr#r Úempty©r.rrr    rrrr/as
r/)ÚxrrrcCs@ddlm}t|ƒ|dkr*td|›ƒ‚| tj|j|d¡S)z„
    Array API compatible wrapper for :py:func:`np.empty_like <numpy.empty_like>`.
 
    See its docstring for more information.
    rrrrr)rr    rrr#r Ú
empty_liker%©r1rrr    rrrr2ts
 r2)Úkrrr&z Optional[int])Ún_rowsÚn_colsr4rrrcCsBddlm}t|ƒ|dkr*td|›ƒ‚| tj||||d¡S)zv
    Array API compatible wrapper for :py:func:`np.eye <numpy.eye>`.
 
    See its docstring for more information.
    rrrr)ÚMr4r)rr    rrr#r Úeye)r5r6r4rrr    rrrr8„s
 r8Úobject)r1rcCsddlm}| t |¡¡S)Nrr)rr    r#r Ú from_dlpack)r1r    rrrr:šs r:)r.Ú
fill_valuerrrcCspddlm}t|ƒ|dkr*td|›ƒ‚t||ƒrD|jdkrD|j}tj|||d}|j    t
krft dƒ‚|  |¡S)zx
    Array API compatible wrapper for :py:func:`np.full <numpy.full>`.
 
    See its docstring for more information.
    rrrrrrzInvalid input to full) rr    rrr"Úndimr%r ÚfullrrÚ    TypeErrorr#)r.r;rrr    r)rrrr= s 
r=)r;r1rrrcCsXddlm}t|ƒ|dkr*td|›ƒ‚tj|j||d}|jtkrNt    dƒ‚| 
|¡S)z‚
    Array API compatible wrapper for :py:func:`np.full_like <numpy.full_like>`.
 
    See its docstring for more information.
    rrrrrzInvalid input to full_like) rr    rrr Ú    full_liker%rrr>r#)r1r;rrr    r)rrrr?»s 
r?T)rrÚendpointÚbool)Únumr,r*rrr@rc    CsDddlm}t|ƒ|dkr*td|›ƒ‚| tj|||||d¡S)z€
    Array API compatible wrapper for :py:func:`np.linspace <numpy.linspace>`.
 
    See its docstring for more information.
    rrrr)rr@)rr    rrr#r Úlinspace)r,r*rBrrr@r    rrrrCÕs
 rCZxy)ÚindexingÚstrz List[Array])ÚarraysrDrcsRddlm‰tdd„|Dƒƒdkr*tdƒ‚‡fdd„tjdd„|Dƒd    |iŽDƒS)
    Array API compatible wrapper for :py:func:`np.meshgrid <numpy.meshgrid>`.
 
    See its docstring for more information.
    rrcSsh|]
}|j’qSrr©Ú.0ÚarrrÚ    <setcomp>÷szmeshgrid.<locals>.<setcomp>z,meshgrid inputs must all have the same dtypecsg|]}ˆ |¡‘qSr)r#)rHr$rrrÚ
<listcomp>úsÿzmeshgrid.<locals>.<listcomp>cSsg|]
}|j‘qSr)r%rGrrrrKüsrD)rr    Úlenrr Úmeshgrid)rDrFrrrrMìs  
þrMcCs>ddlm}t|ƒ|dkr*td|›ƒ‚| tj||d¡S)zx
    Array API compatible wrapper for :py:func:`np.ones <numpy.ones>`.
 
    See its docstring for more information.
    rrrrr)rr    rrr#r Úonesr0rrrrNs
rNcCs@ddlm}t|ƒ|dkr*td|›ƒ‚| tj|j|d¡S)z‚
    Array API compatible wrapper for :py:func:`np.ones_like <numpy.ones_like>`.
 
    See its docstring for more information.
    rrrrr)rr    rrr#r Ú    ones_liker%r3rrrrOs
 rO©r4)r1r4rcCs4ddlm}|jdkrtdƒ‚| tj|j|d¡S)zx
    Array API compatible wrapper for :py:func:`np.tril <numpy.tril>`.
 
    See its docstring for more information.
    rréz)x must be at least 2-dimensional for trilrP)rr    r<rr#r Útrilr%©r1r4r    rrrrR#s 
rRcCs4ddlm}|jdkrtdƒ‚| tj|j|d¡S)zx
    Array API compatible wrapper for :py:func:`np.triu <numpy.triu>`.
 
    See its docstring for more information.
    rrrQz)x must be at least 2-dimensional for triurP)rr    r<rr#r Útriur%rSrrrrT1s 
rTcCs>ddlm}t|ƒ|dkr*td|›ƒ‚| tj||d¡S)zz
    Array API compatible wrapper for :py:func:`np.zeros <numpy.zeros>`.
 
    See its docstring for more information.
    rrrrr)rr    rrr#r Úzerosr0rrrrU?s
rUcCs@ddlm}t|ƒ|dkr*td|›ƒ‚| tj|j|d¡S)z„
    Array API compatible wrapper for :py:func:`np.zeros_like <numpy.zeros_like>`.
 
    See its docstring for more information.
    rrrrr)rr    rrr#r Ú
zeros_liker%r3rrrrVRs
 rV)Nr)N)%Ú
__future__rÚtypingrrrrrÚ_typingr    r
r r r Úcollections.abcrZ_dtypesrÚnumpyr rr(r-r/r2r8r:r=r?rCrMrNrOrRrTrUrVrrrrÚ<module>sn   ó/üùüÿþù
û ú øüÿüÿ