U
    rh                     @  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ddddd	Z	G d
d deZ
dS )    )annotationsN)Base)expectz
np.ndarrayint)dataindices
batch_dimsreturnc                 C  s>  t | j}|jd |kstg }d}t|D ]"}||j|  ||j| 9 }q,|jd || krx|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|S )N   r   dtype)lenshapeAssertionError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   H/tmp/pip-unpacked-wheel-xnis5xre/onnx/backend/test/case/node/gathernd.pygather_nd_impl   s.    
	r   c                   @  sB   e Zd ZeddddZeddddZeddddZd	S )
GatherNDNone)r	   c                  C  s   t jjdddgdgd} tjddgdd	ggtjd
}tjddgddggtjd
}t||d}tjdd	gtjd
}t||st	t
| ||g|gdd d S )Nr   r   r   outputinputsoutputsr   r         r   Ztest_gathernd_example_int32r   r   nameonnxhelper	make_noder   arrayZint32int64r   array_equalr   r   noder   r   r   Zexpected_outputr   r   r   export_int32>   s     zGatherND.export_int32c                  C  s   t jjdddgdgd} tjddgdd	ggd
dgddgggtjd}tjddggddgggtjd}t||d}tjdd	ggd
dgggtjd}t||st	t
| ||g|gdd d S )Nr   r   r   r   r   r   r   r    r!               r   Ztest_gathernd_example_float32r"   )r%   r&   r'   r   r(   Zfloat32r)   r   r*   r   r   r+   r   r   r   export_float32R   s     ,  zGatherND.export_float32c                  C  s   t jjdddgdgdd} tjddgdd	ggd
dgddgggtjd}tjdgdggtjd}t||d}tjdd	gd
dggtjd}t||st	t
| ||g|gdd d S )Nr   r   r   r   r   )r   r   r   r   r    r!   r.   r/   r0   r1   r   Z&test_gathernd_example_int32_batch_dim1r"   r$   r+   r   r   r   export_int32_batchdim_1f   s"    ,z GatherND.export_int32_batchdim_1N)__name__
__module____qualname__staticmethodr-   r2   r3   r   r   r   r   r   =   s   r   )
__future__r   Znumpyr   r%   Zonnx.backend.test.case.baser   Zonnx.backend.test.case.noder   r   r   r   r   r   r   <module>   s   0