
    sg9                     ~   d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	m
Z
mZ  ej                  d      Zej                  eeeef   Zej                  eef   Z ej                  d      Z ej                  d      Z ej                  d	      Z ej                  d
      Z ej                  d      Z ej                  d      Z	 ddlmZ d"dZd"dZd"dZd"dZ d"dZ!d"dZ"d Z#d"dZ$d"dZ%d"dZ&d"dZ'eee e!ee%e&e%e"e$e#e'dZ(d Z)d#dZ*d Z+edfdZ,d"dd d!Z-y# e$ r  ej                  d      ZY kw xY w)$zZ "Normalize" arguments: convert array_likes to tensors, dtypes to torch dtypes and so on.
    )annotationsN   )_dtypes_dtypes_impl_util	ArrayLike	DTypeLikeAxisLikeNDArrayCastingModesKeepDimsOutArray)NotImplementedTyper   c                2    ddl m}  ||       j                  S )Nr   )asarray)_ndarrayr   tensor)xparmr   s      O/var/www/html/venv/lib/python3.12/site-packages/torch/_numpy/_normalizations.pynormalize_array_liker   .   s    !1:    c                H    t        j                  |       r| S t        | |      S N)r   is_scalar_or_symbolicr   r   r   s     r   normalize_array_like_or_scalarr   4   s"    ))!,4((r   c                     | y t        | |      S r   )r   r   s     r   'normalize_optional_array_like_or_scalarr   :   s    y)!T22r   c                "    | d S t        | |      S r   r   r   s     r   normalize_optional_array_liker"   @   s     94?"6q$"??r   c                &    t        d | D              S )Nc              3  2   K   | ]  }t        |        y wr   r!   ).0values     r   	<genexpr>z+normalize_seq_array_like.<locals>.<genexpr>G   s     <%e,<   )tupler   s     r   normalize_seq_array_liker*   F   s    <!<<<r   c                P    d }| !t        j                  |       } | j                  }|S r   )r   dtypetorch_dtype)r,   r   r-   s      r   normalize_dtyper.   J   s,    Ke$''r   c                T    | |j                   k7  rt        d|j                   d      y )N'z' parameter is not supported.)defaultNotImplementedErrornameargr   s     r   normalize_not_implementedr6   S   s,    
dll!Adii[0M"NOO r   c                T    ddl m} t        | |      rt        j                  |       } | S Nr   ndarray)r   r:   
isinstanceoperatorindexr5   r   r:   s      r   normalize_axis_liker?   X   s"    !#wnnS!Jr   c                x    | | S ddl m} t        | |      st        d|j                   d      | j
                  S Nr   r9   r0   z' must be an array)r   r:   r;   	TypeErrorr3   r   r>   s      r   normalize_ndarrayrC   `   s<    
{
!c7#!DII;&89::::r   c                    | | S ddl m} t        | t        j                        r ||       } t        | |      st        d|j                   d      | S rA   )r   r:   r;   torchTensorrB   r3   r>   s      r   normalize_outarrayrG   l   sP    
{
! #u||$clc7#!DII;&89::Jr   c                ,    | dvrt        d|  d      | S )N)noequivsafe	same_kindunsafezMcasting must be one of 'no', 'equiv', 'safe', 'same_kind', or 'unsafe' (got 'z'))
ValueErrorr4   s     r   normalize_castingrO   |   s.    
@@[\_[``bc
 	
 Jr   )r   ArrayLikeOrScalarzOptional[ArrayLike]zSequence[ArrayLike]zOptional[ArrayLikeOrScalar]zOptional[NDArray]zOptional[OutArray]r   zOptional[DTypeLike]r
   r   zOptional[CastingModes]c                \    t         j                  |j                  d      }|r	 || |      S | S )z,Normalize arg if a normalizer is registered.N)normalizersget
annotation)r5   r   
normalizers      r   maybe_normalizerV      s*    $7J$.:c4 7C7r   Fc                   | |S t        |t        j                        r|j                  | j                  k7  r_|j	                         dk(  xr | j
                  dk(  }r|r|j                         }n&t        d| j                   d|j                   d      | j                  j                  |       | S t        |t        t        f      r$ t        |      fdt        | |      D              S t        )Nr   r   z'Bad size of the out array: out.shape = z while result.shape = .c              3  >   K   | ]  \  }}t        ||        y wr   )maybe_copy_to)r%   orpromote_scalar_results      r   r'   z maybe_copy_to.<locals>.<genexpr>   s$      
;?1aM!Q 56
s   )r;   rE   rF   shapenumelndimsqueezerN   r   copy_r)   listtypezipAssertionError)outresultr]   can_fits     ` r   rZ   rZ      s    
{	FELL	)<<399$lln);chh!mG$) =cii[,V\\N!=  	

 
	FUDM	*tF| 
CFsFCS
 
 	
 r   c                    ddl m} t        | t        j                        r ||       S t        | t
        t        f      r t        |       d | D              } | S )Nr   r9   c              3  2   K   | ]  }t        |        y wr   )wrap_tensors)r%   r   s     r   r'   zwrap_tensors.<locals>.<genexpr>   s     >!l1o>r(   )r   r:   r;   rE   rF   r)   rc   rd   )rh   r:   s     r   rl   rl      sF    !&%,,'v	FUDM	*f>v>>Mr   c                N    |r || j                               S ddlm}  ||       S r8   )itemr   r:   )valuespy_typereturn_scalarr:   s       r   array_or_scalarrr      s#    v{{}%%%vr   )r]   c               &    fd}| |S  ||       S )Nc                F     t        j                          fd       }|S )Nc            
        t        j                        }|j                  }t        t	        |j                                     }|j                  t         j                  j                  k(  r| D cg c]  }t        ||       } }nGt        d t        | |j                               D              | t        |j                               d  z   } |j                         D ci c]  \  }}|||v rt        |||         n| }}} | i |}d }d|v rw|d   j                  dk(  re |j                  | i |j                   }|j#                  dd      r7| d   }	|j#                  d      }
t%        j&                  ||
|	j(                        }d|v r<| |j                  | i |j                   }|j#                  d      }t+        ||      }t-        |      }|S c c}w c c}}w )Nc              3  :   K   | ]  \  }}t        ||        y wr   )rV   )r%   r5   r   s      r   r'   zHnormalizer.<locals>.normalizer_inner.<locals>.wrapped.<locals>.<genexpr>   s#      %C (T2s   keepdimsr   Fr   axisrg   )inspect	signature
parametersnextiterro   kind	ParameterVAR_POSITIONALrV   r)   re   lenitemsrT   bind	argumentsrS   r   apply_keepdimsr`   rZ   rl   )argskwdssigparamsfirst_paramr5   r3   rh   
bound_argsr   rx   rg   funcr]   s               r   wrappedz5normalizer.<locals>.normalizer_inner.<locals>.wrapped   s   ##D)C^^FtFMMO45K 7#4#4#C#CCEIJc[9JJ  ),T6==?)C  3v}}/12	3  "&D# DFNoc6$<8PSSD 
 4(4(F JV#z(:(E(E(S%SXXt4t4>>
>>*e4 "!WF%>>&1D"11&$LF %!)4!84!8!B!BJ nnU+&sF4IJ!&)FMO Ks   0G  G)	functoolswraps)r   r   r]   s   ` r   normalizer_innerz$normalizer.<locals>.normalizer_inner   s&    		.	 
.	` r    )_funcr]   r   s    ` r   rU   rU      s!    2h }&&r   r   )F).__doc__
__future__r   r   ry   r<   typingrE    r   r   r   TypeVarr   UnionintfloatcomplexboolScalarrP   r	   r
   r   r   r   r   r   ImportErrorr   r   r   r"   r*   r.   r6   r?   rC   rG   rO   rR   rV   rZ   rl   rr   rU   r   r   r   <module>r      sz   "      * * FNN;'		c5'4/	0LLF!23 FNN;'	6>>*%
&..
#v~~n-6>>*% 6>>*%>)
)3@=P
	  &783#J*, *#3/ 80 %* 8'E 8'C  >'(<=>s   
D" "D<;D<