U
    qh                     @  sH   d dl mZ d dlZd dlmZ ddddddd	ZG d
d deZdS )    )annotationsN)OpRunz
np.ndarrayintztuple[np.ndarray])dataindices
batch_dimsreturnc                 C  s.  t | j}g }d}t|D ]"}||j|  ||j| 9 }q|jd || krf|t|j|d  n0|t|j|d  t| j||jd  d   }g }||d|jd }	| |f| j|d   }
t|	jd D ]<}t|	jd D ](}t|	| | }||
|f|  qqtj|| j	d|fS )N   r   )dtype)
lenshaperangeappendlistZreshapetuplenpZasarrayr   )r   r   r   Z	data_rankZbatch_dims_shapeZbatch_dims_sizeiZoutput_shapeZoutput_data_bufferZreshaped_indicesZreshaped_dataZ	batch_dimZ	outer_dimZgather_index r   B/tmp/pip-unpacked-wheel-xnis5xre/onnx/reference/ops/op_gathernd.py_gather_nd_impl   s,    
	r   c                   @  s   e Zd ZdddZdS )GatherNDNc                 C  s   t |||S )N)r   )selfr   r   r   r   r   r   _run9   s    zGatherND._run)N)__name__
__module____qualname__r   r   r   r   r   r   8   s   r   )
__future__r   Znumpyr   Zonnx.reference.op_runr   r   r   r   r   r   r   <module>   s   -