U
    qh2                     @  sZ   d dl mZ d dlZd dlmZ ddddddZddddd	d
dZG dd deZdS )    )annotationsN)OpRunz
np.ndarray)selfindexreturnc                 C  sB   g }t | |D ]\}}|||d   qtj|| jd|jS )Nr   dtype)zipappendnparrayr   Zreshapeshape)r   r   resab r   I/tmp/pip-unpacked-wheel-xnis5xre/onnx/reference/ops/op_gather_elements.pygather_numpy_2   s    r   int)r   dimr   r   c                 C  s   |j d | |j |d d   }| j d | | j |d d   }||krXtd|dt| d|}t|d|}ztj||dd}W n@ tk
r   t|j dkrt|j dkrt| | Y S  Y nX t|d|S )N   zExcept for dimension z;, all dimensions of index and self should be the same size.r   wrap)mode   )r   
ValueErrorr   Zswapaxeschooselenr   )r   r   r   Zidx_xsection_shapeZself_xsection_shapeZdata_swapedZindex_swapedZgatheredr   r   r   gather_numpy   s      
r   c                   @  s   e Zd ZdddZdS )GatherElementsNc              	   C  sZ   |j dkrtjd|jdfS zt|||fW S  tk
rT   t|||tf Y S X d S )Nr   )r   r   )sizer   emptyr   r   	TypeErrorZastyper   )r   dataindicesZaxisr   r   r   _run(   s    
zGatherElements._run)N)__name__
__module____qualname__r$   r   r   r   r   r   '   s   r   )	
__future__r   Znumpyr   Zonnx.reference.op_runr   r   r   r   r   r   r   r   <module>   s
   