U
    rh                     @  sX   d dl mZ d dlZd dlZd dlmZ d dlmZ dej	fddZ
G dd	 d	eZdS )
    )annotationsN)Base)expectc           
      C  s   t | }t|j}t |}|dk r2||d 7 }|jd| }|j|| }t |dt| |j dt|  }	t t |||d|}t j|	|k|dS )z/Compute one hot from indices at a specific axisr      )r   dtype)r   )npZasarraylenshapeZarangeZreshapemod)
indicesdepthaxisr   valuesZrankZdepth_rangeZlsrstargets r   F/tmp/pip-unpacked-wheel-xnis5xre/onnx/backend/test/case/node/onehot.pyone_hot   s    


 r   c                   @  sT   e Zd ZeddddZeddddZeddddZeddd	d
ZdS )OneHotNone)returnc                  C  s   d} d}t j}tjjddddgdgd}t jd	d
dgt jd}t d}t j|| g|d}t|||d}|| |  | }t	||||g|gdd d S )N      r   r   r   r   y)inputsoutputsr         r      Ztest_onehot_without_axisr   r   name)
r	   Zint32onnxhelper	make_nodearrayint64float32r   r   )on_value	off_valueoutput_typenoder   r   r   r   r   r   r   export_without_axis   s&      
zOneHot.export_without_axisc            	      C  s   d} d}d}t j}tjjddddgdg| d}t jdd	gd
dggt jd}t d}t j||g|d}t||| |d}|||  | }t||||g|gdd d S )Nr      r   r   r   r   r   r   r   r   	   r      r   
   r   r   Ztest_onehot_with_axisr!   r	   r(   r#   r$   r%   r&   r   r   	Z	axisValuer)   r*   r+   r,   r   r   r   r   r   r   r   export_with_axis2   s*    
zOneHot.export_with_axisc            	      C  s   d} d}d}t j}tjjddddgdg| d}t jd	d
dgt jd}t d}t j||g|d}t||| |d}|||  | }t||||g|gdd d S )Nr   r.   r   r   r   r   r   r/   r   iir   r2   r3   Ztest_onehot_negative_indicesr!   )	r	   r(   r#   r$   r%   r&   r'   r   r   r5   r   r   r   export_with_negative_indicesJ   s*    
z#OneHot.export_with_negative_indicesc            	      C  s   d} d}d}t j}tjjddddgdg| d	}t jdd
gddggt jd}t d}t j||g|d}t||| |d}|||  | }t||||g|gdd d S )Nr.   r   r   r   r   r   r   r/   r0   r   r1   r   r2   r3   Ztest_onehot_with_negative_axisr!   r4   r5   r   r   r   export_with_negative_axish   s*    
z OneHot.export_with_negative_axisN)__name__
__module____qualname__staticmethodr-   r6   r7   r9   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   r   <module>   s   