id-G(ddlmZddlmZmZmZmZmZmZddl m Z ddl m Z ddl mZddlmZerdd lmZmZmZmZmZmZdd lmZdd lZdd lZGd d eZGddeZGddeZGddeZdddVdZ dddWd"Z!dXd#Z"dd$dYd&Z#dZd'Z$dXd(Z%dXd)Z&d[d*Z'dd+d,d\d0Z(d]d2Z)d d3d^d6Z*dXd7Z+d[d8Z,d d3d^d9Z-d:d;d_d>Z.d`d?Z/d@Z0d[dAZ1dBdCdadEZ2dbdGZ3ddHdcdKZ4dd dLdddOZ5dddWdPZ6d dddQdedTZ7gdUZ8d S)f) annotations)_floating_dtypes_numeric_dtypesfloat32float64 complex64 complex128)reshape)Array)normalize_axis_tuple) TYPE_CHECKING)LiteralOptionalSequenceTupleUnionDtype) NamedTupleNc$eZdZUded<ded<dS) EighResultr eigenvalues eigenvectorsN__name__ __module__ __qualname____annotations__K/opt/cloudlinux/venv/lib/python3.11/site-packages/numpy/array_api/linalg.pyrrs*r!rc$eZdZUded<ded<dS)QRResultr QRNrr r!r"r$r$s" HHH HHHHHr!r$c$eZdZUded<ded<dS) SlogdetResultr sign logabsdetNrr r!r"r(r(!s'KKKr!r(c.eZdZUded<ded<ded<dS) SVDResultr USVhNrr r!r"r,r,%s+ HHH HHH IIIIIr!r,F)upperxr r0boolreturnc|jtvrtdtj|j}|rtj|j Stj|S)z Array API compatible wrapper for :py:func:`np.linalg.cholesky `. See its docstring for more information. z2Only floating-point dtypes are allowed in cholesky) dtyper TypeErrornplinalgcholesky_arrayr _newmT)r1r0Ls r"r9r9,s_ w&&&LMMM 18$$A  z!}} :a==r!axisx1x2r@intcp|jtvs|jtvrtd|j|jkrt d|jdkrt d|j|dkrt dt jtj |j |j |S)zz Array API compatible wrapper for :py:func:`np.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 1zcross() dimension must equal 3r?) r5rr6shape ValueErrorndimr r;r7crossr:)rArBr@s r"rIrI<s  x&&"(/*I*IBCCC x28=>>> w!||JKKK x~9::: :bhry")$??? @ @@r!c|jtvrtdtjt j|jS)z Array API compatible wrapper for :py:func:`np.linalg.det `. See its docstring for more information. z-Only floating-point dtypes are allowed in det) r5rr6r r;r7r8detr:r1s r"rKrKNsA w&&&GHHH :bimmAH-- . ..r!)offsetrMc`tjtj|j|ddS)z Array API compatible wrapper for :py:func:`np.diagonal `. See its docstring for more information. r>)rMaxis1axis2)r r;r7diagonalr:)r1rMs r"rRrR[s) :bk!(62NNN O OOr!c|jtvrtdtt t jtj |j S)z Array API compatible wrapper for :py:func:`np.linalg.eigh `. See its docstring for more information. z.Only floating-point dtypes are allowed in eigh) r5rr6rmapr r;r7r8eighr:rLs r"rUrUfsJ w&&&HIII s5:ry~~ah'?'?@@ AAr!c|jtvrtdtjt j|jS)z Array API compatible wrapper for :py:func:`np.linalg.eigvalsh `. See its docstring for more information. z2Only floating-point dtypes are allowed in eigvalsh) r5rr6r r;r7r8eigvalshr:rLs r"rWrWvsC w&&&LMMM :bi((22 3 33r!c|jtvrtdtjt j|jS)z Array API compatible wrapper for :py:func:`np.linalg.inv `. See its docstring for more information. z-Only floating-point dtypes are allowed in inv) r5rr6r r;r7r8invr:rLs r"rYrYsA w&&&GHHH :bimmAH-- . ..r!c|jtvs|jtvrtdtjt j|j|jS)z| Array API compatible wrapper for :py:func:`np.matmul `. See its docstring for more information. z)Only numeric dtypes are allowed in matmul)r5rr6r r;r7matmulr:rArBs r"r[r[sL x&&"(/*I*ICDDD :bi 2955 6 66r!fro)keepdimsordr^r_2Optional[Union[int, float, Literal['fro', 'nuc']]]c|jtvrtdtjt j|jd||S) Array API compatible wrapper for :py:func:`np.linalg.norm `. See its docstring for more information. z5Only floating-point dtypes are allowed in matrix_norm)rOr>r@r^r_) r5rr6r r;r7r8normr:)r1r^r_s r" matrix_normresJ w&&&OPPP :binnQXHxUXnYY Z ZZr!nc|jtvrtdtjt j|j|S)z Array API compatible wrapper for :py:func:`np.matrix_power `. See its docstring for more information. zMOnly floating-point dtypes are allowed for the first argument of matrix_power) r5rr6r r;r7r8 matrix_powerr:)r1rfs r"rhrhsG w&&&ghhh :bi,,QXq99 : ::r!)rtolriOptional[Union[float, Array]]cZ|jdkrtjdtj|jd}|T|ddt |jd dztj|j j z}nZt|tr|j}|ddtj |d tjfz}tjtj||kd S) z Array API compatible wrapper for :py:func:`np.matrix_rank `. See its docstring for more information. r zA1-dimensional array given. Array must be at least two-dimensionalF compute_uvNr>T)r@r^rO.r?)rHr7r8 LinAlgErrorsvdr:maxrFfinfor5eps isinstancer asarraynewaxisr; count_nonzero)r1rir.tols r" matrix_rankrxs vzzi##$ghhh ah5 11A |eede++c!'"##,.?.??"(17BSBSBWW dE " " ;Deede++BJt,<,rO)rHrGr r;r7swapaxesr:rLs r"matrix_transposer{s<vzzPQQQ :bk!(B33 4 44r!c|jtvs|jtvrtd|jdks |jdkrt dt jtj|j |j S)zz Array API compatible wrapper for :py:func:`np.outer `. See its docstring for more information. z(Only numeric dtypes are allowed in outerrz/The input arrays to outer must be 1-dimensional) r5rr6rHrGr r;r7outerr:r\s r"r}r}sr x&&"(/*I*IBCCC w!||rw!||JKKK :bhry")44 5 55r!c&|jtvrtd|;t|jddt j|jjz}tj t j |j |S)z Array API compatible wrapper for :py:func:`np.linalg.pinv `. See its docstring for more information. z.Only floating-point dtypes are allowed in pinvNrO)rcond) r5rr6rprFr7rqrrr r;r8pinvr:)r1ris r"rrsw w&&&HIII |17233<  28AG#4#4#88 :binnQXTn:: ; ;;r!reducedmoderLiteral['reduced', 'complete']c |jtvrtdtt t jtj |j |S)z Array API compatible wrapper for :py:func:`np.linalg.qr `. See its docstring for more information. z,Only floating-point dtypes are allowed in qrr) r5rr6r$rTr r;r7r8qrr:)r1rs r"rrsN w&&&FGGG SRY\\!(\%F%FGG HHr!c|jtvrtdtt t jtj |j S)z Array API compatible wrapper for :py:func:`np.linalg.slogdet `. See its docstring for more information. z1Only floating-point dtypes are allowed in slogdet) r5rr6r(rTr r;r7r8slogdetr:rLs r"rrsL w&&&KLLL #ej")*;*;AH*E*EFF GGr!czddlm}m}m}m}m}m}m}ddlm } ||\}} ||||||\}} |||\} } |j dkr| j }n| j }|| rdnd}||}|||||}| | | d S) Nr ) _makearray_assert_stacked_2d_assert_stacked_square _commonType isComplexTypeget_linalg_error_extobj_raise_linalgerror_singular) _umath_linalgrzDD->Dzdd->d) signatureextobjF)copy) linalg.linalgrrrrrrrr8rrHsolve1solveastype)abrrrrrrrr_wraptresult_tgufuncrrrs r"_solver+sK>>>>>>>>>>>>>>>>>>'&&&&& :a==DAqq1jmmGAt+a##KAx v{{%$)=++8I $ $%@ A AFq!y888A 4.. / //r!c|jtvs|jtvrtdtjt |j|jS)z Array API compatible wrapper for :py:func:`np.linalg.solve `. See its docstring for more information. z/Only floating-point dtypes are allowed in solve)r5rr6r r;rr:r\s r"rrFsL x'''28;K+K+KIJJJ :fRY 22 3 33r!T full_matricesrc |jtvrtdtt t jtj |j |S)z Array API compatible wrapper for :py:func:`np.linalg.svd `. See its docstring for more information. z-Only floating-point dtypes are allowed in svdr) r5rr6r,rTr r;r7r8ror:)r1rs r"roroSsN w&&&GHHH c%*bimmAHMm&Z&Z[[ \\r!Union[Array, Tuple[Array, ...]]c|jtvrtdtjt j|jdS)Nz1Only floating-point dtypes are allowed in svdvalsFrl) r5rr6r r;r7r8ror:rLs r"svdvalsrdsCw&&&KLLL :bimmAHm?? @ @@r!axesr/Union[int, Tuple[Sequence[int], Sequence[int]]]c|jtvs|jtvrtdtjt j|j|j|S)Nz,Only numeric dtypes are allowed in tensordotr)r5rr6r r;r7 tensordotr:)rArBrs r"rrlsQ x&&"(/*I*IFGGG :bl29bidCCC D DDr!)rMr5r5Optional[Dtype]c "|jtvrtd|/|jtkrt}n|jt krt }tjtj tj |j |dd|S)zz Array API compatible wrapper for :py:func:`np.trace `. See its docstring for more information. z(Only numeric dtypes are allowed in traceNrOr>)rMrPrQr5) r5rr6rrr r r r;r7rttracer:)r1rMr5s r"rrus  wo%%BCCC } 7g  EE W ! !E :bj!(6SU]b!c!c!cdd e eer!cR|jtvs|jtvrtdt|j|j}d||jz zt |jz}d||jz zt |jz}||||krtdtj |j |j \}}tj ||d}tj ||d}|ddddf|dz}tj |dS)Nz)Only numeric dtypes are allowed in vecdot)rz6x1 and x2 must have the same size along the given axisr>.).N).rr)r5rr6rprHtuplerFrGr7broadcast_arraysr:moveaxisr r;) rArBr@rHx1_shapex2_shapex1_x2_ress r"vecdotrs  x&&"(/*I*ICDDD rw DTBG^$uRX6HTBG^$uRX6H~$''QRRR"29bi88HC +c4 $ $C +c4 $ $C c4l c)n ,C :c)n % %%r!rc%Optional[Union[int, Tuple[int, ...]]]Optional[Union[int, float]]c8 |jtvrtd|j |  d}nt |t rt||j t fdt jD}||z}tj | tj fd|Dtg fd|DR d}n|}tjtj ||}|rft'|j}t|t|jn||j}|D]} d || <t|t |}|S) rbz.Only floating-point dtypes are allowed in normNrc3$K|] }|v|V dS)Nr ).0inormalized_axiss r" zvector_norm..s-JJ1/1I1IQ1I1I1I1IJJr!c*g|]}j|Sr rFrrrs r" zvector_norm..s///Qagaj///r!)r5c*g|]}j|Sr rrs r"rzvector_norm..s>X>X>Xaqwqz>X>X>Xr!)r@r_r)r5rr6r:ravelrsrrrHranger7 transposer prodrCr r;r8rdlistrF) r1r@r^r__axisrestnewshaperrFrrrs @@r" vector_normrs w&&&HIII A | GGII D% /tQV<<JJJJaf JJJJJ$; LH % % - - W////$///s ; ; ; Y>X>X>X>XSW>X>X>X Y Y [ [ *RY^^AEs^;; < rs""""""-,,,,, ////// JIIIIIIIIIIIIIIII     z   J ,1       35AAAAAA$ / / / /,-PPPPPP B B B B 4 4 4 4 / / / / 7 7 7 7(27rw [ [ [ [ [ [ ; ; ; ;GK::::::05555 6666$@D<<<<<<"?H I I I I I I H H H H00006 4 4 4 4/3 ] ] ] ] ] ]"AAAAcdEEEEEE)*Dffffff*46&&&&&&,OSejPQ++++++Z F F Fr!