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data
np.ndarrayindices
batch_dimsintreturnc                 C  s@  t | j}|jd |ksJ g }d}t|D ]}||j|  ||j| 9 }q|jd || kr<|t|j|d  n|t|j|d  t| j||jd  d   }g }||d|jd }	| |f| j|d   }
t|	jd D ]}t|	jd D ]}t|	| | }||
|g|R   q~qutj|| j	d|S )N   r   dtype)
lenshaperangeappendlistreshapetuplenpasarrayr   )r   r   r   	data_rankbatch_dims_shapebatch_dims_sizeioutput_shapeoutput_data_bufferreshaped_indicesreshaped_data	batch_dim	outer_dimgather_index r#   a/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/onnx/backend/test/case/node/gathernd.pygather_nd_impl   s0   
	r%   c                   @  s6   e Zd Zed
ddZed
ddZed
ddZd	S )GatherNDr
   Nonec                  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||s@J t	| ||g|gdd d S )Nr&   r   r   outputinputsoutputsr   r         r   test_gathernd_example_int32r*   r+   name
onnxhelper	make_noder   arrayint32int64r%   array_equalr   noder   r   r(   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||sPJ t	| ||g|gdd d S )Nr&   r   r   r(   r)   r   r   r,   r-               r   test_gathernd_example_float32r/   )
r2   r3   r4   r   r5   float32r7   r%   r8   r   r9   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||sKJ t	| ||g|gdd d S )Nr&   r   r   r(   r   )r*   r+   r   r   r,   r-   r=   r>   r?   r@   r   &test_gathernd_example_int32_batch_dim1r/   r1   r9   r#   r#   r$   export_int32_batchdim_1f   s"   ,
z GatherND.export_int32_batchdim_1N)r
   r'   )__name__
__module____qualname__staticmethodr<   rC   rE   r#   r#   r#   r$   r&   =   s    r&   )r   r   r   r   r   r	   r
   r   )
__future__r   numpyr   r2   onnx.backend.test.case.baser   onnx.backend.test.case.noder   r%   r&   r#   r#   r#   r$   <module>   s   
0