
    wi\#                        d dl mZ d dlZd dlmZ d dlZd dlmZ d dlm	Z	m
Z
mZ  G d de          Zedk    r ej                     dS dS )	    )annotationsN)TestShapeInferenceHelper)TensorProto)	make_nodemake_tensormake_tensor_value_infoc                  ^    e Zd ZddZddZddZddZddZddZdd	Z	dd
Z
ddZddZdS )TestDataPropagationreturnNonec           	     N   |                      dt          j        dfdt          j        dfgt          ddgdg          t          dddgdg          gg           }|                     |t          dt          j        d	          t          dt          j        d
          gd           d S )Nx)         y)r      r   ShapeshapeExpandzr   )r   r   r   T	data_prop)_make_graphr   INT32r   _assert_inferredr   INT64selfgraphs     o/root/.openclaw/workspace/chatterbox_venv_py311/lib/python3.11/site-packages/onnx/test/data_propagation_test.pytest_expand_symbolic_inputz.TestDataPropagation.test_expand_symbolic_input   s      ;$i038I92UV'C57)44(S'NSE:: 
 
 	&w0A4HH&sK,=yII  	 	
 	
 	
 	
 	
    c                h   |                      dt          j        dfgt          ddgdg          t          ddgdgt	          dt          j        dd	          
          gg           }|                     |t          dt          j        d          t          dt          j        d          gd           d S )Nr   r   r      r   r   ConstantOfShaper   valuer   r   r)   r   Tr   	r   r   FLOATr   r   r   r   r   r   r   s     r"   (test_constantofshape_with_symbolic_shapez<TestDataPropagation.test_constantofshape_with_symbolic_shape#   s      ;$i01'C57)44%IE%g{/@$MM	   
 
 	&w0A4HH&sK,=yII  	 	
 	
 	
 	
 	
r$   c           	         t           j                            d          }|                     |t	          dt
          j        d          t	          dt
          j        d          gd           dS )	z8Infer the shape of z by propagating the value of xshape.z
            <ir_version: 7, opset_import: [ "" : 18]>
            agraph (float[4, 1, 16] x, float[1, 8, 16] y) => () {
                xshape = Shape (x)
                z = Expand (y, xshape)
            }
        xshaper   r   r         Tr   Nonnxparserparse_modelr   r   r   r   r.   r    models     r"   test_model_data_propagationz/TestDataPropagation.test_model_data_propagation:   sx    ''
 
 	&x1BDII&sK,=zJJ  	 	
 	
 	
 	
 	
r$   c           	         t           j                            d          }|                     |t	          dt
          j        d          t	          dt
          j        d          gd           dS )	zTest value-propagation through function calls.
        Underlying core example is same as previous test_model_data_propagation.
        a  
            <ir_version: 7, opset_import: [ "" : 18, "local" : 1 ]>
            agraph (float[4, 1, 16] x, float[1, 8, 16] y) => () {
                xshape = local.GetShape (x)
                z = Expand (y, xshape)
            }
            <domain: "local", opset_import: [ "" : 18 ]>
            GetShape (x) => (shapeval) {
                shapeval = Shape(x)
            }
        r1   r   r   r2   Tr   Nr5   r9   s     r"   test_data_prop_via_functionz/TestDataPropagation.test_data_prop_via_functionN   sz     ''

 
 	&x1BDII&sK,=zJJ  	 	
 	
 	
 	
 	
r$   c                D   t           j                            d          }|                     |t	          dt
          j        d          t	          dt
          j        d          t	          dt
          j        d          t	          dt
          j        d          gd	
           dS )zTest value-propagation handles multiple calls to same function correctly.
        Underlying core example is same as previous test_model_data_propagation.
        a  
            <ir_version: 7, opset_import: [ "" : 18, "local" : 1 ]>
            agraph (float[4, 1, 16] x, float[1, 8, 16] y) => () {
                yshape = local.GetShape (y)
                xshape = local.GetShape (x)
                z = Expand (y, xshape)
                w = Expand (y, yshape)
            }
            <domain: "local", opset_import: [ "" : 18 ]>
            GetShape (x) => (shapeval) {
                shapeval = Shape(x)
            }
        yshaper   r1   r   r2   w)r   r3   r4   Tr   Nr5   r9   s     r"   test_multiple_calls_to_functionz3TestDataPropagation.test_multiple_calls_to_functionh   s     ''
 
 	&x1BDII&x1BDII&sK,=zJJ&sK,=zJJ	  	 		
 		
 		
 		
 		
r$   c                6   |                      dt          j        dfdt          j        dfgt          ddgdg          t          ddgdg          t          dddgd	g          t          d
d	gdgt	          dt          j        dd                    gg           }|                     |t          dt          j        d          t          dt          j        d          t          d	t          j        d          t          dt          j        d          gd           d S )Nr   r&   r   )r   r   r   r   r1   r?   Addzshaper(   r   r)   r*   r+   r,   r   )r      r3   Tr   r-   r   s     r"   test_shape_arithmeticz)TestDataPropagation.test_shape_arithmetic   s*     ;$i038I92UV'C58*55'C58*55%(H!5zBB%JE%g{/@$MM	  	
 
 
 	&x1BDII&x1BDII&x1BDII&sK,=yII	  	 		
 		
 		
 		
 		
r$   c                6   |                      dt          j        dfdt          j        dfgt          ddgdg          t          ddgdg          t          dddgd	g          t          d
d	gdgt	          dt          j        dd                    gg           }|                     |t          dt          j        d          t          dt          j        d          t          d	t          j        d          t          dt          j        d          gd           d S )Nr   r&   r   r   r   r1   r?   rC   rD   r(   r   r)   r*   r+   r,   )rE      r3   Tr   r-   r   s     r"   $test_shape_arithmetic_with_broadcastz8TestDataPropagation.test_shape_arithmetic_with_broadcast   s*     ;$i038I42PQ'C58*55'C58*55%(H!5zBB%JE%g{/@$MM	  	
 
 
 	&x1BDII&x1BDII&x1BDII&sK,=yII	  	 		
 		
 		
 		
 		
r$   c                6   |                      dt          j        dfdt          j        dfgt          ddgdg          t          ddgdg          t          dddgd	g          t          d
d	gdgt	          dt          j        dd                    gg           }|                     |t          dt          j        d          t          dt          j        d          t          d	t          j        d          t          dt          j        d          gd           d S )Nr    r   r   r   r1   r?   rC   rD   r(   r   r)   r*   r+   r,   )r   Tr   r-   r   s     r"   )test_shape_arithmetic_with_zero_broadcastz=TestDataPropagation.test_shape_arithmetic_with_zero_broadcast   s*     ;$b)C1BD+IJ'C58*55'C58*55%(H!5zBB%JE%g{/@$MM	  	
 
 
 	&x1BDII&x1BDII&x1BDII&sK,=rBB	  	 		
 		
 		
 		
 		
r$   c                   t           j                            d          }t           j                            |ddd          }|j        j        d         }|                     |j        j	        j
        j        d         j        d           dS )zZTest that a Concat with an empty tensor as input is handled correctly by data-propagation.z
            <ir_version: 7, opset_import: [ "" : 17]>
            agraph (float[256] y) => (float[N] z)
            <float[0] x = {}>
            {
                z = Concat <axis=0> (x, y)
            }
        Tr      Nr6   r7   r8   shape_inferenceinfer_shapesr!   outputassertEqualtypetensor_typer   dim	dim_valuer    r:   inferred_modelrR   s       r"   test_empty_tensorz%TestDataPropagation.test_empty_tensor   s{    ''	
 	
 -::5$dSS%,Q/06:1=GMMMMMr$   c                   t           j                            d          }t           j                            |ddd          }|j        j        d         }|                     |j        j	        j
        j        d         j        d           dS )zTest that a Concat with an empty tensor as input is handled correctly by data-propagation.
        This time with a negative axis.
        z
            <ir_version: 7, opset_import: [ "" : 17]>
            agraph (float[256] y) => (float[N] z)
            <float[0] x = {}>
            {
                z = Concat <axis=-1> (x, y)
            }
        Tr   rN   NrO   rX   s       r"   test_empty_tensor_negative_axisz3TestDataPropagation.test_empty_tensor_negative_axis   s}     ''	
 	
 -::5$dSS%,Q/06:1=GMMMMMr$   N)r   r   )__name__
__module____qualname__r#   r/   r;   r=   rA   rF   rI   rL   rZ   r\   rK   r$   r"   r
   r
      s        
 
 
 
$
 
 
 
.
 
 
 
(
 
 
 
4
 
 
 
<
 
 
 
6
 
 
 
6
 
 
 
6N N N N N N N N N Nr$   r
   __main__)
__future__r   unittestshape_inference_testr   onnx.parserr6   r   onnx.helperr   r   r   r
   r]   mainrK   r$   r"   <module>rg      s   
 # " " " " "  9 9 9 9 9 9           F F F F F F F F F FgN gN gN gN gN2 gN gN gNT zHMOOOOO r$   