U
    qh+                     @  sl   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 deZedkrhe  dS )	    )annotationsN)TestShapeInferenceHelper)TensorProto)	make_nodemake_tensormake_tensor_value_infoc                   @  sR   e Zd ZddddZddddZddddZddd	d
ZddddZdS )TestDataPropagationNone)returnc                 C  sl   |  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 }| j|tdtjd	tdtjd
gdd d S )Nx)         y)r      r   ShapeshapeZExpandzr   )r   r   r   TZ	data_prop)_make_graphr   INT32r   _assert_inferredr   INT64selfgraph r   C/tmp/pip-unpacked-wheel-xnis5xre/onnx/test/data_propagation_test.pytest_expand_symbolic_input   s    z.TestDataPropagation.test_expand_symbolic_inputc                 C  sp   |  dtjdfgtddgdgtddgdgtdtjdd	d
gg }| j|tdtjdtdtjdgdd d S )Nr   )r   r      r   r   ZConstantOfShaper   value)r   )r   )r!   r   Tr   )	r   r   FLOATr   r   r   r   r   r   r   r   r   r   (test_constantofshape_with_symbolic_shape$   s&    	z<TestDataPropagation.test_constantofshape_with_symbolic_shapec                 C  s8   t jd}| j|tdtjdtdtjdgd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parserZparse_modelr   r   r   r   r"   r   modelr   r   r   test_model_data_propagation;   s    	z/TestDataPropagation.test_model_data_propagationc                 C  s8   t jd}| j|tdtjdtdtjdgd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)
            }
        r$   r   r   r%   Tr   Nr(   r+   r   r   r   test_data_prop_via_functionO   s    z/TestDataPropagation.test_data_prop_via_functionc              	   C  sP   t jd}| j|tdtjdtdtjdtdtjdtdtjdgd	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)
            }
        Zyshaper   r$   r   r%   w)r   r&   r'   Tr   Nr(   r+   r   r   r   test_multiple_calls_to_functioni   s    z3TestDataPropagation.test_multiple_calls_to_functionN)__name__
__module____qualname__r   r#   r-   r.   r0   r   r   r   r   r      s
   r   __main__)
__future__r   ZunittestZshape_inference_testr   Zonnx.parserr)   r   Zonnx.helperr   r   r   r   r1   mainr   r   r   r   <module>   s   w