o
    ·2úhH
  ã                   @   s*   d dl mZ eddgƒG dd„ dƒƒZdS )é    )Úkeras_exportzkeras.Initializerzkeras.initializers.Initializerc                   @   s6   e Zd ZdZddd„Zdd„ Zedd„ ƒZd	d
„ ZdS )ÚInitializera<  Initializer base class: all Keras initializers inherit from this class.

    Initializers should implement a `__call__()` method with the following
    signature:

    ```python
    def __call__(self, shape, dtype=None, **kwargs):
        # returns a tensor of shape `shape` and dtype `dtype`
        # containing values drawn from a distribution of your choice.
    ```

    Optionally, you can also implement the method `get_config()` and the class
    method `from_config` in order to support serialization, just like with
    any Keras object.

    Here's a simple example: a random normal initializer.

    ```python
    class ExampleRandomNormal(Initializer):
        def __init__(self, mean, stddev):
            self.mean = mean
            self.stddev = stddev

        def __call__(self, shape, dtype=None, **kwargs):
            return keras.random.normal(
                shape, mean=self.mean, stddev=self.stddev, dtype=dtype
            )

        def get_config(self):  # To support serialization
            return {"mean": self.mean, "stddev": self.stddev}
    ```

    Note that we don't have to implement `from_config()` in the example above
    since the constructor arguments of the class the keys in the config returned
    by `get_config()` are the same. In this case, the default `from_config()`
    works fine.
    Nc                 C   s   t dƒ‚)zµReturns a tensor object initialized as specified by the initializer.

        Args:
            shape: Shape of the tensor.
            dtype: Optional dtype of the tensor.
        z>Initializer subclasses must implement the `__call__()` method.)ÚNotImplementedError)ÚselfÚshapeÚdtype© r   ú]/var/www/html/chatgem/venv/lib/python3.10/site-packages/keras/src/initializers/initializer.pyÚ__call__,   s   ÿzInitializer.__call__c                 C   s   i S )zŒReturns the initializer's configuration as a JSON-serializable dict.

        Returns:
            A JSON-serializable Python dict.
        r   ©r   r   r   r	   Ú
get_config7   s   zInitializer.get_configc                 C   s   | di |¤ŽS )a’  Instantiates an initializer from a configuration dictionary.

        Example:

        ```python
        initializer = RandomUniform(-1, 1)
        config = initializer.get_config()
        initializer = RandomUniform.from_config(config)
        ```

        Args:
            config: A Python dictionary, the output of `get_config()`.

        Returns:
            An `Initializer` instance.
        Nr   r   )ÚclsÚconfigr   r   r	   Úfrom_config?   s   zInitializer.from_configc                 C   s   | j  |  ¡ ¡S ©N)Ú	__class__r   r   r   r   r   r	   ÚcloneS   s   zInitializer.cloner   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   Úclassmethodr   r   r   r   r   r	   r      s    
&
r   N)Úkeras.src.api_exportr   r   r   r   r   r	   Ú<module>   s    
