o
    2hd                     @   sp   d dl mZ d dl mZ d dl mZ d dl mZ d dlmZ d dlmZ d dl	m
Z
 edG d	d
 d
e
ZdS )    )activations)constraints)initializers)regularizers)keras_export)	InputSpec)Layerzkeras.layers.PReLUc                       sN   e Zd ZdZ				d fdd	Zdd Zdd	 Z fd
dZdd Z  Z	S )PReLUao  Parametric Rectified Linear Unit activation layer.

    Formula:
    ``` python
    f(x) = alpha * x for x < 0
    f(x) = x for x >= 0
    ```
    where `alpha` is a learned array with the same shape as x.

    Args:
        alpha_initializer: Initializer function for the weights.
        alpha_regularizer: Regularizer for the weights.
        alpha_constraint: Constraint for the weights.
        shared_axes: The axes along which to share learnable parameters for the
            activation function. For example, if the incoming feature maps are
            from a 2D convolution with output shape
            `(batch, height, width, channels)`, and you wish to share parameters
            across space so that each filter only has one set of parameters,
            set `shared_axes=[1, 2]`.
        **kwargs: Base layer keyword arguments, such as `name` and `dtype`.
    ZerosNc                    sv   t  jdi | d| _t|| _t|| _t|| _	|d u r'd | _
d S t|ttfs4|g| _
d S t|| _
d S )NT )super__init__supports_maskingr   getalpha_initializerr   alpha_regularizerr   alpha_constraintshared_axes
isinstancelisttuple)selfr   r   r   r   kwargs	__class__r   ]/var/www/html/chatgem/venv/lib/python3.10/site-packages/keras/src/layers/activations/prelu.pyr   "   s   
zPReLU.__init__c                 C   s   t |dd  }| jd ur| jD ]}d||d < q| j|d| j| j| jd| _i }| jrAtdt|D ]}|| jvr@|| ||< q3t	t||d| _
d S )N   alpha)shapenameinitializerregularizer
constraint)ndimaxes)r   r   
add_weightr   r   r   r   rangelenr   
input_spec)r   input_shapeparam_shapeir$   r   r   r   build6   s$   


zPReLU.buildc                 C   s&   t |}| j t |  }|| S N)r   relur   )r   inputsposnegr   r   r   callJ   s   
z
PReLU.callc                    s<   t   }|t| jt| jt| j	| j
d |S )N)r   r   r   r   )r   
get_configupdater   	serializer   r   r   r   r   r   )r   configr   r   r   r3   O   s   
zPReLU.get_configc                 C   s   |S r-   r   )r   r)   r   r   r   compute_output_shapea   s   zPReLU.compute_output_shape)r
   NNN)
__name__
__module____qualname____doc__r   r,   r2   r3   r7   __classcell__r   r   r   r   r	   
   s    r	   N)	keras.srcr   r   r   r   keras.src.api_exportr   keras.src.layers.input_specr   keras.src.layers.layerr   r	   r   r   r   r   <module>   s    