
    ¯wg
                     T   d Z ddlZddlZddlmZmZ ddlmZmZm	Z	m
Z
 ddlmZmZ  ej                  ej                  d      Z ed       e	j"                  d	d	d
d
d      dej$                  fd              Z ed       e	j"                  d	d
d	d	      dej$                  fd              Z ed       e	j"                  d	d
d	d	dd      dej$                  dej*                  j,                  dedej*                  j,                  dej*                  j,                  dedefd              Zy)a  This file exports ONNX ops for opset 16.

Note [ONNX Operators that are added/updated in opset 16]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
https://github.com/onnx/onnx/blob/main/docs/Changelog.md#version-16-of-the-default-onnx-operator-set
New operators:
    GridSample https://github.com/onnx/onnx/pull/3557

Updated operators:
    Identity
    If
    LeakyRelu
    Loop
    PRelu
    RoiAlign
    Scan
    ScatterElements
    ScatterND
    Where
    GreaterOrEqual
    LessOrEqual
    N)GRID_SAMPLE_INTERPOLATION_MODESGRID_SAMPLE_PADDING_MODES)_type_utilserrorssymbolic_helperutils)	jit_utilsregistration   )opsetzaten::grid_samplervibgc                 `   t        j                  |      dk(  rt        j                  d      S t        j                         D ci c]  \  }}||
 c}}|   }t        j                         D ci c]  \  }}||
 c}}|   }	| j                  d||t        |      ||	      S c c}}w c c}}w )N   z#GridSample with 5D volumetric input
GridSample)align_corners_imode_spadding_mode_s)r   _get_tensor_rank_onnx_unsupportedr   itemsr   opint)
r   inputgrid	mode_enumpadding_mode_enumalign_cornerskr   r   r   s
             `/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/torch/onnx/symbolic_opset16.pygrid_samplerr#   -   s     ''.!3001VWW>DDFGtq!adG	RF'@'F'F'HItq!adIN 44M*%   	 HIs   B$0B*zaten::scatter_addc           	      d   t         j                  j                  |t         j                  j                        }t	        j
                  |      }t	        j
                  |      }t        |      t        |      k7  rt	        j                  dd| d| d      S ||k7  sd |v rY| j                  d|      }| j                  dt        j                  dgt        |      z              }	| j                  d	||	|      }t	        j                  |      }t	        j                  |      r| j                  d
||||d      S t         j                  j                  |      |k7  r?| j                  d|t         j                  j                  |      j                               }| j                  d
||||d      S )Nscatter_addz	`index` (z0) should have the same dimensionality as `src` ()ShapeConstantr   value_tSliceScatterElementsaddaxis_ireduction_sCast)to_i)r   JitScalarType
from_value	UNDEFINEDr   _get_tensor_sizeslen_unimplementedr   torchtensor_maybe_get_scalar	_is_value	onnx_type)
r   selfdimindexsrcsrc_type	src_sizesindex_sizesadjusted_shapestartss
             r"   r%   r%   H   s    ((33[&&00H  11#6I!33E:K
9~[))--}$TU^T__`a
 	
 K4;#6gu-j%,,sS=M7M*NOdd7C8

+
+C
0C  %tt%tUCQVtWW $$//5A$$ ..99$?IIK  C tt  
 	
    zaten::scatter_reducesr>   r?   r@   rA   reduceinclude_selfc                    |dk(  rt        j                  d      |st        j                  d      dddddd	}||   }| j                  d
| j                  d|            }	| j                  d|	| j                  dt        j                  dt        j
                                    }
t        j                  | d|
dd      \  }\  }}}|j                  dt        j                  dgt        j
                              }|j                  d||      }t        j                  |j                  |       |j                  d||      }t        j                  |j                  |       |j                  d||      }t        j                  |j                  |       |j                  d|      }t        j                  |j                  |       |j                  d|      }t        j                  |j                  |       |j                  d|      }t        j                  |j                  |        | j                  dg|||d}t        j                  | d|
dd      \  }\  }}}|j                  d|      }t        j                  |j                  |       |j                  d|      }t        j                  |j                  |       |j                         j                         }|S )Nmeanz7ONNX does not support mean reduction for scatter_reducez;ONNX does not support include_self=False for scatter_reducenoner-   mulminmax)rL   sumprodaminamaxSizer'   Equalr(   r   )dtyper)   If      )n_blocksoutputsReshapeIdentityr,   r.      Squeeze)r   OnnxExporterErrorr   r9   r:   int64r	   add_op_with_blocksr   _add_output_to_blockblocknodeoutput)r   r>   r?   r@   rA   rI   rJ   reduce_modeonnx_reduce	self_rankself_rank_is_zeroif_op
if_contextelse_context_neg_1self_reshapeindex_reshapesrc_reshapeself_identityindex_identityesrc_identityresultresult_squeezedresult_identityresult_finals                             r"   scatter_reducer|   w   s    &&E
 	
 &&I
 	

 K f%KVQTT'401I ADDU\\!5;;5WDX ,5+G+G	4"Q,(E%Jq MM*ellB4u{{.SMTE==D%8L	z//>MM)UE:M	z//?--	36K	z//= OOJ5M	|11=A"ooj%8O	|11?C??:s3L	|11<@QTT#QeQC[QF ,5+G+G	4"Q,(E%Jq !mmIv6O	z//A"ooj&9O	|11?C::<&&(LrG   )__doc__	functoolsr9   torch.nn.functionalr   r   
torch.onnxr   r   r   r   torch.onnx._internalr	   r
   partialonnx_symbolic_onnx_symbolic
parse_argsGraphContextr#   r%   _CValuer   strboolr|    rG   r"   <module>r      si  6   C B 8 #""<#=#=RH
 $%Cc34 5 &2 #$Cc3/*
9)) *
 0 %*
Z &'Cc3S9@@
((..@ 
@ 88>>	@
 
@ @ @ : (@rG   