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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
U
O±d‚Gã@sðddlmZddlmZmZddlmZddlmZddl    m
Z
ddl m Z e rldd    l mZmZmZmZmZdd
l mZdd lZdd lZGd d „d eƒZGdd„deƒZGdd„deƒZGdd„deƒZddœddddœdd„Zddœdddddœdd „Zddd!œd"d#„Zdd$œdddd%œd&d'„Zdd d!œd(d)„Zddd!œd*d+„Z ddd!œd,d-„Z!dddd.œd/d0„Z"dd1d2œddd3dd4œd5d6„Z#dddd7œd8d9„Z$d d:œdd;dd<œd=d>„Z%ddd!œd?d@„Z&dddd.œdAdB„Z'd d:œdd;dd<œdCdD„Z(dEdFœddGddHœdIdJ„Z)ddd!œdKdL„Z*dMdN„Z+dddd.œdOdP„Z,dQdRœddddSœdTdU„Z-ddVd!œdWdX„Z.ddYœdddZdd[œd\d]„Z/dd$œdddd%œd^d_„Z0ddœdddddœd`da„Z1d dddbœddcdddddeœdfdg„Z2dd d#d'd)d+d-d0d6d9d>d@dBdDdJdLdPdUdXd]d_dadggZ3d S)hé)Ú annotationsé)Ú_floating_dtypesÚ_numeric_dtypes)Úreshape)ÚArrayé)Únormalize_axis_tuple)Ú TYPE_CHECKING)ÚLiteralÚOptionalÚSequenceÚTupleÚUnion)Ú
NamedTupleNc@seZdZUded<ded<dS)Ú
EighResultrZ eigenvaluesZ eigenvectorsN©Ú__name__Ú
__module__Ú __qualname__Ú__annotations__©rrúMd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\numpy/array_api/linalg.pyrs
rc@seZdZUded<ded<dS)ÚQRResultrÚQÚRNrrrrrrs
rc@seZdZUded<ded<dS)Ú SlogdetResultrÚsignZ    logabsdetNrrrrrrs
rc@s&eZdZUded<ded<ded<dS)Ú    SVDResultrÚUÚSZVhNrrrrrrs
rF)ÚupperrÚbool)Úxr!ÚreturncCs:|jtkrtdƒ‚tj |j¡}|r0t |¡j    St |¡S)zŽ
    Array API compatible wrapper for :py:func:`np.linalg.cholesky <numpy.linalg.cholesky>`.
 
    See its docstring for more information.
    z2Only floating-point dtypes are allowed in cholesky)
ÚdtyperÚ    TypeErrorÚnpÚlinalgÚcholeskyÚ_arrayrÚ_newZmT)r#r!ÚLrrrr)%s 
 r)éÿÿÿÿ©ÚaxisÚint)Úx1Úx2r/r$cCsr|jtks|jtkrtdƒ‚|j|jkr0tdƒ‚|jdkrBtdƒ‚|j|dkrXtdƒ‚t tj    |j
|j
|d¡S)zz
    Array API compatible wrapper for :py:func:`np.cross <numpy.cross>`.
 
    See its docstring for more information.
    z(Only numeric dtypes are allowed in crossz"x1 and x2 must have the same shaperz/cross() requires arrays of dimension at least 1ézcross() dimension must equal 3r.) r%rr&ÚshapeÚ
ValueErrorÚndimrr+r'Úcrossr*)r1r2r/rrrr75s 
r7)r#r$cCs&|jtkrtdƒ‚t tj |j¡¡S)z„
    Array API compatible wrapper for :py:func:`np.linalg.det <numpy.linalg.det>`.
 
    See its docstring for more information.
    z-Only floating-point dtypes are allowed in det)    r%rr&rr+r'r(Údetr*©r#rrrr8Gs
r8)Úoffset)r#r:r$cCst tj|j|ddd¡S)z€
    Array API compatible wrapper for :py:func:`np.diagonal <numpy.diagonal>`.
 
    See its docstring for more information.
    éþÿÿÿr-©r:Zaxis1Zaxis2)rr+r'Údiagonalr*©r#r:rrrr=Tsr=cCs,|jtkrtdƒ‚tttjtj     |j
¡ƒŽS)z†
    Array API compatible wrapper for :py:func:`np.linalg.eigh <numpy.linalg.eigh>`.
 
    See its docstring for more information.
    z.Only floating-point dtypes are allowed in eigh) r%rr&rÚmaprr+r'r(Úeighr*r9rrrr@_s
r@cCs&|jtkrtdƒ‚t tj |j¡¡S)zŽ
    Array API compatible wrapper for :py:func:`np.linalg.eigvalsh <numpy.linalg.eigvalsh>`.
 
    See its docstring for more information.
    z2Only floating-point dtypes are allowed in eigvalsh)    r%rr&rr+r'r(Úeigvalshr*r9rrrrAos
rAcCs&|jtkrtdƒ‚t tj |j¡¡S)z„
    Array API compatible wrapper for :py:func:`np.linalg.inv <numpy.linalg.inv>`.
 
    See its docstring for more information.
    z-Only floating-point dtypes are allowed in inv)    r%rr&rr+r'r(Úinvr*r9rrrrB|s
rB)r1r2r$cCs2|jtks|jtkrtdƒ‚t t |j|j¡¡S)z|
    Array API compatible wrapper for :py:func:`np.matmul <numpy.matmul>`.
 
    See its docstring for more information.
    z)Only numeric dtypes are allowed in matmul)r%rr&rr+r'Úmatmulr*©r1r2rrrrC‹srCZfro)ÚkeepdimsÚordz4Optional[Union[int, float, Literal[('fro', 'nuc')]]])r#rErFr$cCs.|jtkrtdƒ‚t tjj|jd||d¡S)ú†
    Array API compatible wrapper for :py:func:`np.linalg.norm <numpy.linalg.norm>`.
 
    See its docstring for more information.
    z5Only floating-point dtypes are allowed in matrix_norm)r;r-©r/rErF)    r%rr&rr+r'r(Únormr*)r#rErFrrrÚ matrix_normŸs
rJ)r#Únr$cCs(|jtkrtdƒ‚t tj |j|¡¡S)zˆ
    Array API compatible wrapper for :py:func:`np.matrix_power <numpy.matrix_power>`.
 
    See its docstring for more information.
    zMOnly floating-point dtypes are allowed for the first argument of matrix_power)    r%rr&rr+r'r(Ú matrix_powerr*)r#rKrrrrL­s
rL)ÚrtolzOptional[Union[float, Array]])r#rMr$cCsª|jdkrtj d¡‚tjj|jdd}|dkr`|jdddt|jd    d…ƒt |j    ¡j
}n2t |t ƒrp|j}|jdddt  |¡d
tjf}t  tj||kdd ¡S) z†
    Array API compatible wrapper for :py:func:`np.matrix_rank <numpy.matrix_rank>`.
 
    See its docstring for more information.
    rzA1-dimensional array given. Array must be at least two-dimensionalF©Z
compute_uvNr-T)r/rEr;.r.)r6r'r(Z LinAlgErrorÚsvdr*Úmaxr4Úfinfor%ÚepsÚ
isinstancerÚasarrayZnewaxisr+Z count_nonzero)r#rMr ZtolrrrÚ matrix_rank¼s
 0
"rUcCs(|jdkrtdƒ‚t t |jdd¡¡S)Nrz5x must be at least 2-dimensional for matrix_transposer-r;)r6r5rr+r'Zswapaxesr*r9rrrÚmatrix_transposeÔs
rVcCsN|jtks|jtkrtdƒ‚|jdks0|jdkr8tdƒ‚t t |j    |j    ¡¡S)zz
    Array API compatible wrapper for :py:func:`np.outer <numpy.outer>`.
 
    See its docstring for more information.
    z(Only numeric dtypes are allowed in outerrz/The input arrays to outer must be 1-dimensional)
r%rr&r6r5rr+r'Úouterr*rDrrrrWÚs
rWcCsR|jtkrtdƒ‚|dkr:t|jdd…ƒt |j¡j}t     tj
j |j |d¡S)z†
    Array API compatible wrapper for :py:func:`np.linalg.pinv <numpy.linalg.pinv>`.
 
    See its docstring for more information.
    z.Only floating-point dtypes are allowed in pinvNr;)Zrcond) r%rr&rPr4r'rQrRrr+r(Úpinvr*)r#rMrrrrXìs
 
 rXZreduced©Úmodez Literal[('reduced', 'complete')])r#rZr$cCs0|jtkrtdƒ‚tttjtjj    |j
|dƒŽS)z‚
    Array API compatible wrapper for :py:func:`np.linalg.qr <numpy.linalg.qr>`.
 
    See its docstring for more information.
    z,Only floating-point dtypes are allowed in qrrY) r%rr&rr?rr+r'r(Úqrr*)r#rZrrrr[ýs
r[cCs,|jtkrtdƒ‚tttjtj     |j
¡ƒŽS)zŒ
    Array API compatible wrapper for :py:func:`np.linalg.slogdet <numpy.linalg.slogdet>`.
 
    See its docstring for more information.
    z1Only floating-point dtypes are allowed in slogdet) r%rr&rr?rr+r'r(Úslogdetr*r9rrrr\ s
r\cCs¸ddlm}m}m}m}m}m}m}ddlm    }    ||ƒ\}}
||ƒ||ƒ||ƒ\}} |||ƒ\} } |j
dkrx|    j }n|    j }|| ƒrŠdnd}||ƒ}|||||d}| |j | dd    ƒS)
Nr)Ú
_makearrayÚ_assert_stacked_2dÚ_assert_stacked_squareÚ _commonTypeÚ isComplexTypeÚget_linalg_error_extobjÚ_raise_linalgerror_singular)Ú _umath_linalgrzDD->Dzdd->d)Ú    signatureÚextobjF)Úcopy)Z linalg.linalgr]r^r_r`rarbrcr(rdr6Zsolve1ÚsolveZastype)ÚaÚbr]r^r_r`rarbrcrdÚ_ÚwrapÚtZresult_tZgufuncrerfÚrrrrÚ_solve$s$   
rocCs0|jtks|jtkrtdƒ‚t t|j|jƒ¡S)zˆ
    Array API compatible wrapper for :py:func:`np.linalg.solve <numpy.linalg.solve>`.
 
    See its docstring for more information.
    z/Only floating-point dtypes are allowed in solve)r%rr&rr+ror*rDrrrrh?srhT©Ú full_matrices)r#rqr$cCs0|jtkrtdƒ‚tttjtjj    |j
|dƒŽS)z„
    Array API compatible wrapper for :py:func:`np.linalg.svd <numpy.linalg.svd>`.
 
    See its docstring for more information.
    z-Only floating-point dtypes are allowed in svdrp) r%rr&rr?rr+r'r(rOr*)r#rqrrrrOLs
rOzUnion[Array, Tuple[Array, ...]]cCs*|jtkrtdƒ‚t tjj|jdd¡S)Nz1Only floating-point dtypes are allowed in svdvalsFrN)    r%rr&rr+r'r(rOr*r9rrrÚsvdvals]s
rr©Úaxesz/Union[int, Tuple[Sequence[int], Sequence[int]]])r1r2rtr$cCs6|jtks|jtkrtdƒ‚t tj|j|j|d¡S)Nz,Only numeric dtypes are allowed in tensordotrs)r%rr&rr+r'Ú    tensordotr*)r1r2rtrrrruesruc
Cs2|jtkrtdƒ‚t t tj|j|ddd¡¡S)zz
    Array API compatible wrapper for :py:func:`np.trace <numpy.trace>`.
 
    See its docstring for more information.
    z(Only numeric dtypes are allowed in tracer;r-r<)    r%rr&rr+r'rTÚtracer*r>rrrrvns
rvc    CsÊ|jtks|jtkrtdƒ‚t|j|jƒ}d||jt|jƒ}d||jt|jƒ}||||krrtdƒ‚t     |j
|j
¡\}}t  ||d¡}t  ||d¡}|dddd…f|d}t   |d¡S)Nz)Only numeric dtypes are allowed in vecdot)rz6x1 and x2 must have the same size along the given axisr-.).N).rr)r%rr&rPr6Útupler4r5r'Zbroadcast_arraysr*Zmoveaxisrr+)    r1r2r/r6Zx1_shapeZx2_shapeZx1_Zx2_ÚresrrrÚvecdot{sryrHz%Optional[Union[int, Tuple[int, ...]]]zOptional[Union[int, float]])r#r/rErFr$c
s|jtkrtdƒ‚|j‰|dkr.ˆ ¡‰d}n‚t|tƒr¬t||jƒ‰t‡fdd„t    ˆjƒDƒƒ}||}t
  ˆ|¡  t
j ‡fdd„|Dƒtdf‡fdd„|Dƒ˜¡‰d}n|}t t
jjˆ||d    ¡}|rt|jƒ}t|dkrìt    |jƒn||jƒ}|D] }    d
||    <qút |t|ƒƒ}|S) rGz.Only floating-point dtypes are allowed in normNrc3s|]}|ˆkr|VqdS)Nr©Ú.0Úi)Únormalized_axisrrÚ    <genexpr>©szvector_norm.<locals>.<genexpr>csg|]}ˆj|‘qSr)r4rz)rirrÚ
<listcomp>¬szvector_norm.<locals>.<listcomp>)r%)r/rFr)r%rr&r*ZravelrSrwr    r6Úranger'Z    transposerÚprodr0rr+r(rIÚlistr4)
r#r/rErFZ_axisÚrestZnewshaperxr4r|r)rir}rÚ vector_norm‘s.
 
  .ÿ
 
r„)4Ú
__future__rZ_dtypesrrZ_manipulation_functionsrZ _array_objectrZ core.numericr    Útypingr
Ú_typingr r r rrrZ numpy.linalgÚnumpyr'rrrrr)r7r8r=r@rArBrCrJrLrUrVrWrXr[r\rorhrOrrrurvryr„Ú__all__rrrrÚ<module>sN                -