
    
Ng                        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                            dd          Zej                            dd          Zej                            dd          Zej                            dd          Zej                            d	d          Z e
            Z G d
 de          Zedk    r e j                     dS dS )    N)Sequence)TestShapeInferenceHelper)AttributeProto	TypeProto            
   c            	           e Zd Zdedee         dee         dee         fdZdedee         dee         fdZd Z	d Z
d	 Zd
S )TestFunctionInferencefunction_textinput_types
attributesexpected_output_typesc                 >   t           j                            |          }t           j                            |||          }|                     t          |          t          |                     t          ||          D ]\  }}|                     ||           d S N)	onnxparserparse_functionshape_inferenceinfer_function_output_typesassertEquallenzip_compare_value_infos)	selfr   r   r   r   functionresultexpectedactuals	            ]/var/www/html/ai-engine/env/lib/python3.11/site-packages/onnx/test/function_inference_test.py_checkzTestFunctionInference._check   s     ;--m<<%AAk:
 
 	233S[[AAA #$96 B B 	8 	8Hf%%h7777	8 	8    c                     t           j                            |          fd}|                     t           j        j        |           d S )Nc                  J    t           j                                        d S r   )r   r   r   )r   r   r   s   r"   invoke_inferencez<TestFunctionInference._check_fails.<locals>.invoke_inference/   s/     <<+z    r$   )r   r   r   assertRaisesr   InferenceError)r   r   r   r   r'   r   s     `` @r"   _check_failsz"TestFunctionInference._check_fails'   sd     ;--m<<	 	 	 	 	 	 	
 	$.=?OPPPPPr$   c                     d}|                      |t          t          gg t          g           |                      |t          t          gg t          g           |                     |t          t          gg            d S )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_basic6   sl     	D;4b;-HHHD;4b;-HHH$k :B?????r$   c                    d}t           j                            dd          }|                     |t          g|gt
          g           t           j                            dd          }|                     |t          g|gt          g           d S )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   r/   dtype_6dtype_10s       r"   test_fi_attributez'TestFunctionInference.test_fi_attributeB   s{     +,,Wa88D;-'[MBBB;--gr::D;-(m_EEEEEr$   c                    d}|                      |t          gg t          g           |                      |t          t          gg t          g           d}|                      |t          t          t          gg t          g           |                      |t          t          t          gg t          g           |                      |t          t          t          gg t          g           d}|                      |t          t          t          gg t          g           |                     |t          t          t          gg            d S )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_inputO   s    	D;-k];;;D;12}EEE 	D;Z@"zlSSSD;[A2}UUUD;X>[MRRR 	D;+>[MRRR 	$h
 CRHHHHHr$   N)__name__
__module____qualname__strr   r   r   r#   r*   r0   r8   r=    r$   r"   r   r      s        88 i(8 ^,	8
  (	28 8 8 8QQ i(Q ^,	Q Q Q Q
@ 
@ 
@F F F"I "I "I "I "Ir$   r   __main__)unittesttypingr   shape_inference_testr   r   onnx.helperonnx.parseronnx.shape_inferencer   r   r3   make_tensor_type_protor,   r<   r;   r-   r5   r:   r   r>   mainrB   r$   r"   <module>rL      sY          9 9 9 9 9 9              * * * * * * * *k00D99k00D99[//488
k00D99222t<<9;;ZI ZI ZI ZI ZI4 ZI ZI ZIz zHMOOOOO r$   