o
    wi                     @  sR   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dZ	G dd	 d	eZ
dS )    )annotationsN)Base)expect        c                   s   | j  |d u rtt }n	 fdd|D }t|}|d |jkr&tdg }t D ]	}|ddgg7 }q,t|D ]}|| }	|	dk rH |	 }	|| |||  g||	< q:|dkrdtj| |||d}
|
S tj| ||d}
|
S )	Nc                   s    g | ]}|d kr
|n|  qS )r    ).0axis
input_rankr   \/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/onnx/backend/test/case/node/pad.py
<listcomp>   s     zpad_impl.<locals>.<listcomp>   z9The number of elements in raw_pads should be 2 * num_axesr   constant)	pad_widthmodeconstant_values)r   r   )ndimlistrangelensize
ValueErrornppad)dataraw_padsr   r   axesnum_axesr   _ir   yr   r	   r   pad_impl   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 )PadreturnNonec                  C  s~   t jjdg ddgdd} tjdddd	tj}tg d
tj	}td}t
||dd}t| |||g|gdd d S )Nr"   )xpadsvaluer    r   inputsoutputsr               )r   r   r+   r,   r   r   r   r-   333333?test_constant_padr)   r*   nameonnxhelper	make_noder   randomrandnastypefloat32arrayint64r!   r   )noder%   r&   r'   r    r   r   r   export_constant_pad6   s   
zPad.export_constant_padc                  C  s   dD ]<} t jjdddgdg| d}tjddd	d
tj}tg dtj	}t
||| }t|||g|gd|  dd qd S )N)edgereflectwrapr"   r%   r&   r    r(   r+   r,   r-   r.   )r   r   r+   r+   r   r   r+   r+   test__padr1   )r4   r5   r6   r   r7   r8   r9   int32r;   r<   r!   r   )r   r=   r%   r&   r    r   r   r   #export_reflection_edge_and_wrap_padD   s    z'Pad.export_reflection_edge_and_wrap_padc                  C  s   t jjdg ddgdd} tjdddd	tj}tg d
tj	}td}tjddgtj	d}t
||ddddg}t| ||||g|gdd d S )Nr"   r%   r&   r'   r   r    r   r(   r+   r,   r-   r.   r   r,   r   r-   r/   dtypetest_constant_pad_axesr1   r3   r=   r%   r&   r'   r   r    r   r   r   export_constant_pad_axesR   ,   


zPad.export_constant_pad_axesc                  C  s   t jjdg ddgdd} tjdddd	tj}tg d
tj	}td}tjddgtj	d}t
||ddddg}t| ||||g|gdd d S )Nr"   rF   r    r   r(   r+   r,   r-   r.   rG   r/   rH   test_constant_pad_negative_axesr1   r3   rK   r   r   r   !export_constant_pad_negative_axesl   rM   z%Pad.export_constant_pad_negative_axesN)r#   r$   )__name__
__module____qualname__staticmethodr>   rE   rL   rQ   r   r   r   r   r"   5   s    r"   )r   N)
__future__r   numpyr   r4   onnx.backend.test.case.baser   onnx.backend.test.case.noder   r!   r"   r   r   r   r   <module>   s   
(