o
    soiH                     @  s\   d dl mZ d dlZd dlZd dlmZ d dlmZ d dl	m
Z
 dd ZG dd	 d	eZdS )
    )annotationsN)Base)expect)_rms_normalizationc                 C  s$   t | }|dk r|| }| |d  S )Nr   )len)x_shapeaxisrank r
   `/home/ubuntu/.local/lib/python3.10/site-packages/onnx/backend/test/case/node/rmsnormalization.pycalculate_normalized_shape   s   r   c                   @  sD   e Zd ZedddZedddZedddZedd	d
ZdS )RMSNormalizationreturnNonec                    sZ   t jddddt j d fd	d
} tt jD ]}| | | |t j  qd S )N            r   intr   r   c                      t  j| }tjj| tj}t || d}tj	j
dddgdg| d}| dk r/d|   }nd	|  }t| |g|g|d
 d S )Nr   r   XWYinputsoutputsr   r   (test_rms_normalization_4d_axis_negative_test_rms_normalization_4d_axisr   r   namer   shapenprandomrandnastypefloat32r   onnxhelper	make_noder   r   normalized_shaper   r   noder    r   r
   r   case      
z%RMSNormalization.export.<locals>.caser   r   r   r   r#   r$   r%   r&   r'   ranger   r"   r/   ir
   r.   r   export   s   zRMSNormalization.exportc                  C  sv   t jddddt j} t| jd}t jj| t j}t| |}tj	j
dddgd	gd
}t|| |g|gdd d S )Nr   r   r   r   r   r   r   r   )r   r   #test_rms_normalization_default_axisr   )r#   r$   r%   r&   r'   r   r"   r   r(   r)   r*   r   )r   r,   r   r   r-   r
   r
   r   export_default_axis1   s   

z$RMSNormalization.export_default_axisc                    sV   t jddt j d	 fdd} tt jD ]}| | | |t j  qd S )
Nr   r   r   r   r   r   c                   r   )Nr   r   r   r   r   r   r   (test_rms_normalization_2d_axis_negative_test_rms_normalization_2d_axisr   r!   r+   r.   r
   r   r/   M   r0   z'RMSNormalization.export2d.<locals>.caser1   r2   r4   r
   r.   r   export2dI   s   zRMSNormalization.export2dc                    s^   dt jdddt j d fd	d
} tt jD ]}| | | |t j  qd S )Ng?r   r   r   r   r   r   r   c                   s   t  j| }tjj| tj}t || d}tj	j
dddgdg| d}| dk r2d|   d	}nd
|  d	}t| |g|g|d d S )N)r   epsilonr   r   r   r   )r   r   r   r=   r   (test_rms_normalization_3d_axis_negative__epsilontest_rms_normalization_3d_axisr   r!   r+   r   r=   r
   r   r/   i   s   z/RMSNormalization.export3d_epsilon.<locals>.caser1   r2   r4   r
   rA   r   export3d_epsilond   s   z!RMSNormalization.export3d_epsilonN)r   r   )__name__
__module____qualname__staticmethodr6   r9   r<   rB   r
   r
   r
   r   r      s    r   )
__future__r   numpyr#   r(   onnx.backend.test.case.baser   onnx.backend.test.case.noder   'onnx.reference.ops.op_rms_normalizationr   r   r   r
   r
   r
   r   <module>   s   