
     Ti%              	      "   S SK Jr  S SKJrJrJrJrJr  S SKr	S SK
r
S SKJrJr  S SKJr  \(       a  S SKJr  \" \R&                  R(                  \R&                  R*                  \R&                  R,                  \R&                  R.                  \R&                  R0                  \R&                  R2                  \R&                  R4                  15      r S         SS jjrSS jrS	 rSS
 jr        SS jr SS jr!        SS jr"g)    )annotations)TYPE_CHECKINGAnyCallableOptionalSequenceN)irtensor)_schemas)	converterc                   [        U[        5      (       a?  U(       d8  Uc  [        S5      eU[        ;  a  [        S5      e[        R
                  " X/ S9$ U[        R                  R                  :X  aK  [        U[        R                  5      (       d,  [        R                  " U [        R                  " X" 5       S9S9$ [        R                  R                  XUS9$ )aR  Helper function to create an ONNX AttributeProto.

* Empty lists can be attribute values, provided the attribute type is specified
and is a list type.
* Scalar-values like 1.0 as well as lists like [1, -1] to be specified
when the attribute type is TensorProto by automatically converting the value
into a 0-D or 1-D tensor respectively.
z6Attribute type must be specified for empty list value.z>Empty list value is only allowed for repeated attribute types.)nametypevalue)r   )r   r   )	attr_type)
isinstancelist
ValueError_REPEATED_ATTRIBUTE_TYPESr	   AttrAttributeTypeTENSORonnxTensorProto
AttrTensorr
   convenienceconvert_attribute)keyr   name_generatorr   s       \/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/onnxscript/_internal/autocast.pypyvalue_to_onnx_attributer!   #   s     %uUVV55]^^wwCr::	b&&--	-jHXHX6Y6Y}}#RYYu>CS-TUU~~//i/PP    c                    [        U [        [        [        45      (       a  g[        U [        5      (       a  U (       a  [        U S   5      $ g)zChecks if a runtime parameter value needs to be promoted into an onnxscript value.
This is the runtime-equivalent of the promotion of literal constants into ONNX values
in the static converter.
Tr   F)r   boolintfloatr   _promotablexs    r    r'   r'   B   s>    
 !dC'((!Tq 1Q4  r"   c                x   [        U [        5      (       a  [        R                  $ [        U [        5      (       a  [        R
                  $ [        U [        5      (       a  [        R                  $ [        U [        5      (       a   U (       a  [        U S   5      $ [        S5      e[        S[        U 5       35      e)zReturn np.dtype to use when converting a python value to an onnxscript tensor.
Note that int constants are treated as int64, as that is the common type in ONNX
for shape/index values.
r   z+Cannot determine target type for empty listzValue of unexpected type )r   r$   npbool_r%   int64r&   float32r   
_get_dtyper   	TypeErrorr   )pyvalues    r    r/   r/   P   s    
 '4  xx	GS	!	!xx	GU	#	#zz	GT	"	" gaj))FGG
/W?
@@r"   c                    [        U 5      (       a6  Uc  [        U 5      n[        R                  " [        R
                  " XS95      $ U $ )zPromotes python values into onnxscript tensors.
The optional argument dtype specifies the desired np.dtype of the tensor,
used only when a non-standard onnxscript-value is promoted into one.
)dtype)r'   r/   r
   Tensorr+   array)r1   r3   s     r    cast_pyvalue_to_os_tensorr6   d   s;    
 7=w'E}}RXXg;<<Nr"   c           
     ^  ^ Uc  [        U4S jU 5       5      $ UR                  n0 n/ n[        U5       H  u  pxU[        U5      :  a  XG   n	OdUS   R                  (       a,  US   n	U	R
                  (       d  UR                  US45        MX  O$[        S[        U5       S[        U5       S35      eU	R                  R                  n
SU
;  a  U " U5      nUb  XU
'   UR                  X45        M     U VV
s/ s H  u  pT" XR                  U
5      5      PM     nnn
[        U5      $ s  sn
nf )a  Uses schema specification to support a limited form of auto-casting.

* Scalars are promoted to tensors.
* Further. they are cast to the required type when used in ops with other
tensor inputs that are required to be of same type.
Thus, in "A+1" or "Add(A, 1)", the value 1 will be converted to the same
type as A.

This is used by the converter in a static-mode, as well as by the eager-mode
execution in a dynamic-mode.
Nc              3  6   >#    U  H  nT" US 5      v   M     g 7fN ).0r)   casts     r    	<genexpr>cast_inputs.<locals>.<genexpr>   s     1DqT!T]]Ds   zNumber of actual parameters z% exceeds number of formal parameters .()tupleinputs	enumeratelenvariadichomogeneousappendr   type_constraintr   get)get_type_infor<   op_signatureargsexpected_inputstype_bindingsargs_typevarsir)   expectedtypevartypeinfo	cast_argss    `           r    cast_inputsrV   p   sG   "  1D111 #))O 46M57M$s?##&)HR ))&r*H''$$aY/ ( .s4yk :77:?7K6LAO  **//g$Q'H#)1g&a\*'  ( HUU}a**734}IU Vs   8#D)c                *    S n[        U[        X5      $ )z.Used for autocast during eager-mode execution.c                \    [        U [        R                  5      (       a  U R                  $ S $ r9   )r   r
   r4   r3   r(   s    r    rK   *dynamic_cast_inputs.<locals>.get_type_info   s!    $Q66qww@D@r"   )rV   r6   )rL   rM   rK   s      r    dynamic_cast_inputsrZ      s    A }&?TTr"   c                <   ^  SU 4S jjnSU 4S jjn[        X4X5      $ )zUsed for autocast during script-translation.
This is meant to transform expressions like "Add(X, 1)" to "Add(X, CastLike(1, X))"
Polymorphic constants (like 0 and 1) are cast to the type of other operands as needed.
c                R   > U b   TR                  U R                  5      (       a  S$ U $ )zReturns x back if x can serve as the target-type for a cast (as the second
argument of CastLike) and None otherwise. In the expression "Add(X, 1), 1 is
castable, while X can serve as the target-type.
N)is_castabler   )r)   
converter_s    r    rK   )static_cast_inputs.<locals>.get_type_info   s(    
 yJ$:$:166$B$BtIIr"   c                   > U c  g TR                  U R                  5      (       a6  Ub3  TR                  U R                   S35      nTR                  U/SX/5      $ U $ )N_castCastLike)r]   r   generate_unique_nameemit1)r)   yx_castr^   s      r    	cast_like%static_cast_inputs.<locals>.cast_like   s]    9!!!&&))am44xu5EFF##VHj1&AAr"   )r)   Optional[ir.Value]returnri   )r)   ri   re   ri   rj   zOptional[str])rV   )r^   rL   rM   rK   rg   s   `    r    static_cast_inputsrk      s    J }DDr"   r9   )
r   strr   r   r   zCallable[[], str]r   zir.AttributeType | Nonerj   zir.Attr)rj   r$   )rK   zCallable[[Any], Any]r<   zCallable[[Any, Any], Any]rL   z_schemas.OpSignature | Nonerj   ztuple[Any, ...])rL   z_schemas.OpSignature)r^   zconverter.ConverterrL   zOptional[_schemas.OpSignature]rM   zSequence[Optional[ir.Value]]rj   ztuple[str, ...])#
__future__r   typingr   r   r   r   r   numpyr+   r   
onnxscriptr	   r
   onnxscript.irr   onnxscript._internalr   	frozensetr   FLOATSINTSSTRINGSTENSORSGRAPHSSPARSE_TENSORSTYPE_PROTOSr   r!   r'   r/   r6   rV   rZ   rk   r:   r"   r    <module>r{      sI   # C C   ! ". &


  
  

''
$$
 " *.	Q	QQ &Q '	Q
 Q>A(	4'4
#4 .4
 4nUE#E0E 'E 	Er"   