o
    *j                     @   s   d dl Zd dlZd dlm  mZ dd ZdddZddd	Z	dd
dZ
edkryeddgddggZeddgddggZe	eeZe	edZde
ed  Zee ee ee eeZeeZeeg ddZeeej dS dS )    Nc                    st   t |ttfr, fdd|D }t|dd}t j}|D ]}||d qt |S t |tr6 	|S t
d)z/ Implement multi-dimension unsqueeze function. c                    s*   g | ]}|d kr
|n|t  j d qS )r      )lenshape).0diminput n/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/modelscope/models/nlp/space/modules/functions.py
<listcomp>   s    zunsqueeze.<locals>.<listcomp>T)reverser   z/Warning: type(dims) must in (list, tuple, int)!)
isinstancelisttuplesortedr   inserttorchZreshapeint	unsqueeze
ValueError)r   dimsr   r   r	   r   r
   r      s   



r   r   绽|=c                 C   sF   t tjj| j }dt |t ||   }| | }t|| S )z$ Basic implement of gumbel_softmax. g        )	r   tensornprandomZrandr   logFZsoftmax)r   tauepsUZgumbelyr	   r	   r
   gumbel_softmax   s   r!   c                 C   sP   |du rd}t | tjr|  } t |tjr| }t| ||}t|S )z+ Implement equal in dygraph mode. (paddle) NZfloat32)r   r   ZTensornumpyr   equalZastyper   )xr    dtypeoutr	   r	   r
   r#   !   s   
r#   c                 C   s   dt | || S )z/ Implement not_equal in dygraph mode. (paddle) r   )r#   )r$   r    r%   r	   r	   r
   	not_equal-   s   r'   __main__      )r   r   r   )r   )r   r   )N)r"   r   r   Ztorch.nn.functionalnnZ
functionalr   r   r!   r#   r'   __name__r   abcc1floatdprintefgr   r	   r	   r	   r
   <module>   s*   





