o
    si                     @   s   d dl mZ d dlZd dlmZ ddlmZ G dd dejZdd	 Zd
d Z	dd Z
dd Zdd Zd ddZdd Zdd Zdd Zdd Zdd Zdd ZdS )!    )partialN)nn   )
complex_nnc                       s$   e Zd Z fddZdd Z  ZS )Swishc                    s   t t|   d S N)superr   __init__)self	__class__ O/home/ubuntu/.local/lib/python3.10/site-packages/asteroid/masknn/activations.pyr	      s   zSwish.__init__c                 C   s   |t | S r   )torchsigmoid)r
   xr   r   r   forward   s   zSwish.forward)__name__
__module____qualname__r	   r   __classcell__r   r   r   r   r      s    r   c                   C      t  S r   )r   Identityr   r   r   r   linear      r   c                   C   r   r   )r   ReLUr   r   r   r   relu   r   r   c                   C   r   r   )r   PReLUr   r   r   r   prelu   r   r   c                   C   r   r   )r   	LeakyReLUr   r   r   r   
leaky_relu   r   r    c                   C   r   r   )r   Sigmoidr   r   r   r   r      r   r   c                 C   s   t j| dS )Ndim)r   Softmaxr"   r   r   r   softmax#   s   r%   c                   C   r   r   )r   Tanhr   r   r   r   tanh'   r   r'   c                   C   r   r   )r   GELUr   r   r   r   gelu+   r   r)   c                   C   s   t  S r   )r   r   r   r   r   swish/   s   r*   c                 C   sL   | j t  v s| j  t  v rtd| j  dt | j | i dS )zRegister a custom activation, gettable with `activation.get`.

    Args:
        custom_act: Custom activation function to register.

    zActivation z% already exists. Choose another name.N)r   globalskeyslower
ValueErrorupdate)
custom_actr   r   r   register_activation3   s   $r1   c                 C   sZ   | du rdS t | r| S t| tr%t | }|du r#tdt|  |S tdt|  )a  Returns an activation function from a string. Returns its input if it
    is callable (already an activation for example).

    Args:
        identifier (str or Callable or None): the activation identifier.

    Returns:
        :class:`nn.Module` or None
    Nz+Could not interpret activation identifier: )callable
isinstancestrr+   getr.   )
identifierclsr   r   r   r5   ?   s   

r5   c                 C   s    t | }|du r
dS ttj|S )zWLike `.get` but returns a complex activation created with `asteroid.complex_nn.OnReIm`.N)r5   r   r   OnReIm)r6   
activationr   r   r   get_complexV   s   r:   r   )	functoolsr   r   r    r   Moduler   r   r   r   r    r   r%   r'   r)   r*   r1   r5   r:   r   r   r   r   <module>   s"    
