
     Ti                        S SK Jr  S SKrS SKJrJr  S SKrS SKrS SK	r
S SKJr      S                 SS jjrS rS rSS jrS	 rS
 rg)    )annotationsN)OptionalSequence)tensorc                d  ^	 [         R                  " 5       m	U T	l        UT	l        T	R                  R                  U5        [         R                  R                  T	l        U	4S jnU" SU5        Ub  U" S[        U5      5        Ub  U" S[        U5      5        Ub	  U" SU5        Ub	  U" SU5        T	$ )a,  Create a TensorProto referencing externally stored tensor-data.

Args:
    name: name of the tensor
    data_type: data type of tensor element
    dims: shape of the tensor
    location: location of the external file (relative path)
    offset: offset in the file where the tensor-data starts
    length: number of bytes containing the data
    checksum: SHA1 digest of the file
    basepath: basepath combined with location to form the full path

Returns:
    TensorProto

See https://github.com/onnx/onnx/blob/main/docs/ExternalData.md for more details.
c                f   > TR                   R                  5       nXl        [        U5      Ul        g )N)external_dataaddkeystrvalue)kventrytensor_protos      Y/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/onnxscript/_internal/utils.pyr
   external_tensor.<locals>.add0   s'    **..0	!f    locationoffsetlengthchecksumbasepath)	onnxTensorProtoname	data_typedimsextendEXTERNALdata_locationint)
r   r   r   r   r   r   r   r   r
   r   s
            @r   external_tensorr#      s    6 ##%LL&LT"!%!1!1!:!:L
 
HHc&k"Hc&k"J!J!r   c                   [        U [        R                  [        R                  45      (       aT  [
        R                  R                  U R                  5      nU R                  n[
        R                  R                  X5      $ [        U [        5      (       a8  [
        R                  R                  [
        R                  R                  / 5      $ [        U [        [        R                  45      (       a8  [
        R                  R                  [
        R                  R                   / 5      $ [        U ["        5      (       a  [%        U 5      S:  a+  [
        R                  R'                  [)        U S   5      5      $ [
        R                  R'                  [
        R                  R                  [
        R                  R                   S5      5      $ [        U [*        R,                  5      (       a_  [        R.                  " U 5      n[
        R                  R                  UR                  5      n[
        R                  R                  U/ 5      $ [1        S[3        U 5       S35      e)z'Return the ONNX type of a python-value.r   NValue of type $ is invalid as an ONNX input/output.)
isinstancenpndarrayr   Tensorr   helpernp_dtype_to_tensor_dtypedtypeshapemake_tensor_type_protor"   r   INT32floatfloat32FLOATlistlenmake_sequence_type_protovalue_to_type_protonumbersNumberarray
ValueErrortype)val	elem_typer.   nparrays       r   r7   r7   A   s   #

FMM233KK88C			{{11)CC#s{{11$2B2B2H2H"MM#rzz*++{{11$2B2B2H2H"MM#ts8a<;;778KCPQF8STT {{33KK..t/?/?/E/EtL
 	
 #w~~&&((3-KK88G	{{11)R@@
~d3i[0TU
VVr   c                t   [        U [        R                  [        R                  45      (       aM  [
        R                  R                  U R                  5      nU R                  n[        R                  " U5      U4$ [        U [        5      (       a4  [
        R                  R                  n/ n[        R                  " U5      U4$ [        U [        [        R                   45      (       a4  [
        R                  R"                  n/ n[        R                  " U5      U4$ [        U [$        5      (       a{  ['        U 5      S:  a(  [)        U S   5      u  p2[        R*                  " U5      U4$ [        R*                  " [        R                  " [
        R                  R"                  5      5      S4$ [        U [,        R.                  5      (       aW  [        R0                  " U 5      n[
        R                  R                  UR                  5      n[        R                  " U5      / 4$ [3        SW" U 5       S35      e)4Return an ir.Value representation of a python-value.r   Nr%   r&   )r'   r(   r)   r   r*   r   r+   r,   r-   r.   ir
TensorTyper"   r   r0   r1   r2   r3   r4   r5   value_to_typeSequenceTyper8   r9   r:   r;   )r=   r>   r.   r<   r?   s        r   rD   rD   [   s   #

FMM233KK88C			i(%00	C		$$**	i(%00	C%,	-	-$$**	i(%00	C		s8a<'A/KD??4(%// r}}T-=-=-C-CDEtKK#w~~&&((3-KK88G	}}Y'++
~d3i[0TU
VVr   c                F    [        U5      u  p#[        R                  " XUS9$ )rA   )r   r<   r.   )rD   rB   Value)r   r=   r<   r.   s       r   value_to_ir_valuerH   x   s    $KD8866r   c           
         U  VVs/ s H3  u  pUc  M
  [         R                  R                  U[        U5      5      PM5     snn$ s  snnf )z^Create a list of ValueInfoProto from a list of (name, value) pairs,
skipping any None values.
)r   r+   make_value_infor7   name_valuesr   r=   s      r   values_to_value_infosrM   ~   sH     '&KT 	D##D*=c*BC&  s
   	A-Ac                X    U  VVs/ s H  u  pUc  M
  [        X5      PM     snn$ s  snnf )zXCreate a list of ir.Value from a list of (name, value) pairs,
skipping any None values.
)rH   rK   s      r   values_to_ir_valuesrO      s*     =H[K[d3(d(K[[[s   	&&)NNNN)r   r   r   r"   r   zSequence[int]r   r   r   Optional[int]r   rP   r   Optional[str]r   rQ   returnzonnx.TensorProto)r   r   rR   zir.Value)
__future__r   r8   typingr   r   numpyr(   r   onnx_irrB   
onnxscriptr   r#   r7   rD   rH   rM   rO    r   r   <module>rY      s    #  %     ! ""/
// / 	/
 / / / / /dW4W:7\r   