
    2Vh                     t   d dl Z d dl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 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 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 d dlmZ d dlmZ ee
eee	eeeeeeeeeeeehZ e D  ci c]  } | jB                  |  c} Z"e"jG                  e D  ci c]  }  e| jB                        |  c}        e"jG                  eeee	eeed        ed      d        Z$ ed      dd       Z% ed      d        Z&yc c} w c c} w )     N)backend)ops)keras_export)STFT)Constant)Identity)Ones)Zeros)Initializer)GlorotNormal)GlorotUniform)HeNormal)	HeUniform)LecunNormal)LecunUniform)
Orthogonal)RandomNormal)RandomUniform)TruncatedNormal)VarianceScaling)serialization_lib)to_snake_case)IdentityInitializernormaloneSTFTInitializerOrthogonalInitializeruniformzerozkeras.initializers.serializec                 ,    t        j                  |       S )z7Returns the initializer configuration as a Python dict.)r   serialize_keras_object)initializers    O/home/dcms/DCMS/lib/python3.12/site-packages/keras/src/initializers/__init__.py	serializer$   B   s     33K@@    zkeras.initializers.deserializec                 :    t        j                  | t        |      S )z9Returns a Keras initializer object via its configuration.)module_objectscustom_objects)r   deserialize_keras_objectALL_OBJECTS_DICT)configr(   s     r#   deserializer,   H   s      55'% r%   zkeras.initializers.getc                      yt         t              rt               }ntt         t              rt               i d}t        |      }nJt	        j
                         s*t         t        j                  t        j                  f      r	d fd	}|}n }t        |      rt        j                  |      r |       }|S t        d        )a  Retrieves a Keras initializer object via an identifier.

    The `identifier` may be the string name of a initializers function or class
    (case-sensitively).

    >>> identifier = 'Ones'
    >>> keras.initializers.get(identifier)
    <...keras.initializers.initializers.Ones...>

    You can also specify `config` of the initializer to this function by passing
    dict containing `class_name` and `config` as an identifier. Also note that
    the `class_name` must map to a `Initializer` class.

    >>> cfg = {'class_name': 'Ones', 'config': {}}
    >>> keras.initializers.get(cfg)
    <...keras.initializers.initializers.Ones...>

    In the case that the `identifier` is a class, this method will return a new
    instance of the class by its constructor.

    You may also pass a callable function with a signature that includes `shape`
    and `dtype=None` as an identifier.

    >>> fn = lambda shape, dtype=None: ops.ones(shape, dtype)
    >>> keras.initializers.get(fn)
    <function <lambda> at ...>

    Alternatively, you can pass a backend tensor or numpy array as the
    `identifier` to define the initializer values directly. Note that when
    calling the initializer, the specified `shape` argument must be the same as
    the shape of the tensor.

    >>> tensor = ops.ones(shape=(5, 5))
    >>> keras.initializers.get(tensor)
    <function get.<locals>.initialize_fn at ...>

    Args:
        identifier: A string, dict, callable function, or tensor specifying
            the initializer. If a string, it should be the name of an
            initializer. If a dict, it should contain the configuration of an
            initializer. Callable functions or predefined tensors are also
            accepted.

    Returns:
        Initializer instance base on the input identifier.
    N)
class_namer+   c                     t        j                  |      }t        j                  |       t        j                  j                        k7  rt	        dj                   d|        t        j                  |      S )NzExpected `shape` to be z2 for direct tensor as initializer. Received shape=)r   standardize_dtypestandardize_shapeshape
ValueErrorr   cast)r2   dtype
identifiers     r#   initialize_fnzget.<locals>.initialize_fn   s}    --e4E((/73L3L  4  !-j.>.>-? @==BGE  88J..r%   z,Could not interpret initializer identifier: N)
isinstancedictr,   strr   	is_tensornpgenericndarraycallableinspectisclassr3   )r6   objr+   r7   s   `   r#   getrD   R   s    ` *d#*%	J	$ #J2>&!	z	"jRZZ,'		/ }??3%C
::,G
 	
r%   r8   )'rA   numpyr=   	keras.srcr   r   keras.src.api_exportr   ,keras.src.initializers.constant_initializersr   r   r   r	   r
   "keras.src.initializers.initializerr   *keras.src.initializers.random_initializersr   r   r   r   r   r   r   r   r   r   r   keras.src.savingr   keras.src.utils.namingr   ALL_OBJECTS__name__r*   updater$   r,   rD   )clss   0r#   <module>rQ      sT       - = A A = > : C D ? @ B C A C D F F . 0 	#( 2==#CLL#%=    1<=#]3<< #%=   '!+ 
 ,-A .A
 ./ 0 &'P
 (P
G >=s   $D0
D5