
    bIg                       d dl mZ d dlZd dlm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mZmZ ej                  j                  dd      Zej                  j                  dd      Zej                  j                  dd      Zej                  j                  d	d      Zej                  j                  d
d      Z e       Z G d de      Zedk(  r ej.                          yy)    )annotationsN)Sequence)TestShapeInferenceHelper)AttributeProto	TypeProto            
   c                  J    e Zd Z	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZd Zd Zd Zy)	TestFunctionInferencec                   t         j                  j                  |      }t         j                  j	                  |||      }| j                  t        |      t        |             t        ||      D ]  \  }}| j                  ||        y N)	onnxparserparse_functionshape_inferenceinfer_function_output_typesassertEquallenzip_compare_value_infos)	selffunction_textinput_types
attributesexpected_output_typesfunctionresultexpectedactuals	            ^/var/www/html/answerous/venv/lib/python3.12/site-packages/onnx/test/function_inference_test.py_checkzTestFunctionInference._check   s}     ;;--m<%%AAk:
 	23S[A #$96 B 	8Hf%%h7	8    c                    t         j                  j                  |      fd}| j                  t         j                  j
                  |       y )Nc                 H    t         j                  j                          y r   )r   r   r   )r   r   r   s   r#   invoke_inferencez<TestFunctionInference._check_fails.<locals>.invoke_inference1   s      <<+zr%   )r   r   r   assertRaisesr   InferenceError)r   r   r   r   r(   r   s     `` @r#   _check_failsz"TestFunctionInference._check_fails)   s=     ;;--m<	
 	$..==?OPr%   c                    d}| j                  |t        t        gg t        g       | j                  |t        t        gg t        g       | j                  |t        t        gg        y )Nz
            <opset_import: [ "" : 18 ], domain: "local">
            f (y, z) => (w) {
                x = Add(y, z)
                w = Mul(x, y)
            }
        )r$   float_type_int32_type_r+   r   codes     r#   test_fi_basicz#TestFunctionInference.test_fi_basic8   sT     	D;4b;-HD;4b;-H$k :B?r%   c                   d}t         j                  j                  dd      }| j                  |t        g|gt
        g       t         j                  j                  dd      }| j                  |t        g|gt        g       y )Nz
            <opset_import: [ "" : 18 ], domain: "local">
            CastTo <dtype> (x) => (y) {
                y = Cast <to : int = @dtype> (x)
            }
        dtyper   r   )r   helpermake_attributer$   r-   r.   float16_type_)r   r0   dtype_6dtype_10s       r#   test_fi_attributez'TestFunctionInference.test_fi_attributeD   sg     ++,,Wa8D;-'[MB;;--gr:D;-(m_Er%   c                   d}| j                  |t        gg t        g       | j                  |t        t        gg t        g       d}| j                  |t        t        t        gg t        g       | j                  |t        t        t        gg t        g       | j                  |t        t        t        gg t        g       d}| j                  |t        t        t        gg t        g       | j                  |t        t        t        gg        y )Nz
            <opset_import: [ "" : 18 ], domain: "local">
            DoReduce (x, axes) => (y) {
                y = ReduceMax (x, axes)
            }
        z
            <opset_import: [ "" : 18 ], domain: "local">
            Quantize (x, scale, zero_point) => (y) {
                y = QuantizeLinear (x, scale, zero_point)
            }
        z
            <opset_import: [ "" : 18 ], domain: "local">
            DoClip (x, min, max) => (y) {
                y = Clip (x, min, max)
            }
        )r$   r-   no_type_
int8_type_uint8_type_r+   r/   s     r#   test_fi_optional_inputz,TestFunctionInference.test_fi_optional_inputQ   s     	D;-k];D;12}E 	D;Z@"zlSD;[A2}UD;X>[MR 	D;+>[MR 	$h
 CRHr%   N)r   strr   Sequence[TypeProto]r   Sequence[AttributeProto]r   r@   )r   r?   r   r@   r   rA   )__name__
__module____qualname__r$   r+   r1   r9   r>    r%   r#   r   r      sd    88 )8 -	8
  38QQ )Q -	Q
@F"Ir%   r   __main__)
__future__r   unittesttypingr   shape_inference_testr   r   onnx.helperonnx.parseronnx.shape_inferencer   r   r4   make_tensor_type_protor-   r=   r<   r.   r6   r;   r   rB   mainrE   r%   r#   <module>rP      s    #   9     *kk00D9kk00D9[[//48
kk00D9222t<;ZI4 ZIz zHMMO r%   