
    6bi                     P   S r SSKrSSKrSSKJs  Jr  SSKJr  SSK	J
r
  SSKJr  SSKJr  SrSrS	r\\\/r\" S
5       " S S5      5       r\" SS/ S9 " S S\5      5       r\" SS/ S9 " S S\5      5       r\" SS/ S9 " S S\5      5       r\" SS/ S9 " S S\5      5       r\" SS/ S9 " S  S!\5      5       r\" S"S#/ S9 " S$ S%\5      5       r\" S&S'/ S9 " S( S)\5      5       r\" S*S+/ S9 " S, S-\5      5       r\" S.S// S9 " S0 S1\5      5       r\" S2S3/ S9 " S4 S5\5      5       r\" S6S7/ S9 " S8 S9\5      5       r\" S:S;/ S9 " S< S=\5      5       r\" S>S?/ S9 " S@ SA\5      5       r \" SBSC/ S9 " SD SE\5      5       r!\" SFSG/ S9 " SH SI\5      5       r"SJ r#SK r$SL r%SOSM jr&SN r'g)PzKeras initializers.    N)backend)utils)serialization_lib)keras_exportpartition_shapepartition_offsetlayoutzkeras.initializers.Initializerc                   >    \ rS rSrSrS	S jrS r\S 5       rS r	Sr
g)
Initializer#   a  Initializer base class: all TF-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.
    return tf.random.uniform(shape=shape, dtype=dtype)
```

Optionally, you an also implement the method `get_config()` and the class
method `from_config()` in order to support serialization -- just like with
any TF-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 tf.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                     [        S5      e)zReturns a tensor object initialized as specified by the initializer.

Args:
  shape: Shape of the tensor.
  dtype: Optional dtype of the tensor.
  **kwargs: Additional keyword arguments.
z>Initializer subclasses must implement the `__call__()` method.)NotImplementedError)selfshapedtypekwargss       `/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/initializers/initializers.py__call__Initializer.__call__M   s     "L
 	
    c                     0 $ )ztReturns the initializer's configuration as a JSON-serializable dict.

Returns:
    A JSON-serializable Python dict.
 r   s    r   
get_configInitializer.get_configY   s	     	r   c                 6    UR                  SS5        U " S0 UD6$ )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.
r   Nr   )popclsconfigs     r   from_configInitializer.from_configa   s    $ 	

7D!}V}r   c                     [        U SS5      (       a>  [        U SS 5      c/  [        R                  " SU R                  R                   S35        g g SU l        g )N_usedFseedzThe initializer z is unseeded and being called multiple times, which will return identical values each time (even if the initializer is unseeded). Please update your code to provide a seed to the initializer, or avoid using the same initializer instance more than once.T)getattrwarningswarn	__class____name__r$   r   s    r   _warn_reuseInitializer._warn_reusev   sW    4%((tVT*2&t~~'>'>&? @/ / 3 DJr   )r$   N)r*   
__module____qualname____firstlineno____doc__r   r   classmethodr!   r+   __static_attributes__r   r   r   r   r   #   s+    &P

  (r   r   zkeras.initializers.Zeroszkeras.initializers.zeros)v1c                   "    \ rS rSrSrSS jrSrg)Zeros   a  Initializer that generates tensors initialized to 0.

Also available via the shortcut function `tf.keras.initializers.zeros`.

Examples:

>>> # Standalone usage:
>>> initializer = tf.keras.initializers.Zeros()
>>> values = initializer(shape=(2, 2))

>>> # Usage in a TF-Keras layer:
>>> initializer = tf.keras.initializers.Zeros()
>>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)
Nc                    [        U R                  R                  U5        [        U5      nUR                  (       a  U[
        R                  :X  a  [        SU S35      e[        U;   a	  U[           nUR                  SS5      nU(       a$  [        R                  " [
        R                  XAUS9$ [
        R                  " X5      $ a  Returns a tensor object initialized as specified by the initializer.

Args:
    shape: Shape of the tensor.
    dtype: Optional dtype of the tensor. Only numeric or boolean dtypes
        are supported. If not specified, `keras.backend.floatx()` is
        used, which defaults to `float32` unless you configured it
        otherwise (via `keras.backend.set_floatx(float_dtype)`).
    **kwargs: Additional keyword arguments.
z'Expected numeric or boolean dtype, got .r	   Nr   r   )_validate_kwargsr)   r*   
_get_dtypeis_numpy_compatibletfstring
ValueError_PARTITION_SHAPEr   r   call_with_layoutzerosr   r   r   r   r	   s        r   r   Zeros.__call__   s     	00&95!((ERYY,>FugQOPPv%+,EHd+))&U  xx%%r   r   r-   r*   r.   r/   r0   r1   r   r3   r   r   r   r6   r6      s    &r   r6   zkeras.initializers.Oneszkeras.initializers.onesc                   "    \ rS rSrSrSS jrSrg)Ones   a  Initializer that generates tensors initialized to 1.

Also available via the shortcut function `tf.keras.initializers.ones`.

Examples:

>>> # Standalone usage:
>>> initializer = tf.keras.initializers.Ones()
>>> values = initializer(shape=(2, 2))

>>> # Usage in a TF-Keras layer:
>>> initializer = tf.keras.initializers.Ones()
>>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)
Nc                    [        U R                  R                  U5        [        U5      nUR                  (       a  U[
        R                  :X  a  [        SU S35      e[        U;   a	  U[           nUR                  SS5      nU(       a$  [        R                  " [
        R                  XAUS9$ [
        R                  " X5      $ r9   )r<   r)   r*   r=   r>   r?   r@   rA   rB   r   r   rC   onesrE   s        r   r   Ones.__call__   s     	00&95!((ERYY,>FugQOPPv%+,EHd+))E  wwu$$r   r   r-   rG   r   r   r   rI   rI      s    %r   rI   zkeras.initializers.Constantzkeras.initializers.constantc                   B    \ rS rSrSrS	S jrS
S jrS r\S 5       r	Sr
g)Constant   aJ  Initializer that generates tensors with constant values.

Also available via the shortcut function `tf.keras.initializers.constant`.

Only scalar values are allowed.
The constant value provided must be convertible to the dtype requested
when calling the initializer.

Examples:

>>> # Standalone usage:
>>> initializer = tf.keras.initializers.Constant(3.)
>>> values = initializer(shape=(2, 2))

>>> # Usage in a TF-Keras layer:
>>> initializer = tf.keras.initializers.Constant(3.)
>>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

Args:
    value: A Python scalar.
c                     Xl         g r-   value)r   rS   s     r   __init__Constant.__init__   s    
r   Nc                 ^   [        U R                  R                  U5        [        U5      n[        U;   a	  U[           nUR                  SS5      nU(       a.  [        R                  " [        R                  X@R                  XS9$ [        R                  " U R                  [        U5      US9$ )ao  Returns a tensor object initialized to `self.value`.

Args:
    shape: Shape of the tensor.
    dtype: Optional dtype of the tensor. If not specified,
        `keras.backend.floatx()` is used,
        which defaults to `float32` unless you configured it
        otherwise (via `keras.backend.set_floatx(float_dtype)`).
        **kwargs: Additional keyword arguments.
r	   Nr;   )r   r   )r<   r)   r*   r=   rB   r   r   rC   r?   constantrS   rE   s        r   r   Constant.__call__   s     	00&95!v%+,EHd+))VZZu  {{4::Z->eLLr   c                     SU R                   0$ )NrS   rR   r   s    r   r   Constant.get_config  s    $$r   c                     UR                  SS 5        SU;   a4  [        US   [        5      (       a  [        R                  " US   5      US'   U " S0 UD6$ )Nr   rS   r   )r   
isinstancedictr   deserialize_keras_objectr   s     r   r!   Constant.from_config  sR    

7D!f&/400"3"L"L7O#w }V}r   rR   )r   r-   )r*   r.   r/   r0   r1   rT   r   r   r2   r!   r3   r   r   r   rO   rO      s+    ,M,%  r   rO   z keras.initializers.RandomUniformz!keras.initializers.random_uniformc                   2    \ rS rSrSrSS jrS	S jrS rSrg)
RandomUniformi  a  Initializer that generates tensors with a uniform distribution.

Also available via the shortcut function
`tf.keras.initializers.random_uniform`.

Examples:

>>> # Standalone usage:
>>> initializer = tf.keras.initializers.RandomUniform(minval=0., maxval=1.)
>>> values = initializer(shape=(2, 2))

>>> # Usage in a TF-Keras layer:
>>> initializer = tf.keras.initializers.RandomUniform(minval=0., maxval=1.)
>>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

Args:
  minval: A python scalar or a scalar tensor. Lower bound of the range of
    random values to generate (inclusive).
  maxval: A python scalar or a scalar tensor. Upper bound of the range of
    random values to generate (exclusive).
  seed: A Python integer. Used to make the behavior of the initializer
    deterministic. Note that a seeded initializer will produce the same
    random values across multiple calls.
Nc                 \    Xl         X l        X0l        [        R                  " USS9U l        g N	statelessrng_type)minvalmaxvalr%   r   RandomGenerator_random_generator)r   rg   rh   r%   s       r   rT   RandomUniform.__init__9  s)    	!(!8!8;"
r   c           	         [        U R                  R                  U5        [        U5      nUR                  (       d   UR
                  (       d  [        SU S35      e[        U;   a	  U[           nUR                  [        S5      nUc  U R                  5         U(       a  [        U5      OSnUR                  SS5      nU(       aN  [        5         [        R                  " U R                   R"                  UUU R$                  U R&                  UU5      $ U R                   R#                  XR$                  U R&                  X%5      $ )a  Returns a tensor object initialized as specified by the initializer.

Args:
  shape: Shape of the tensor.
  dtype: Optional dtype of the tensor. Only floating point and integer
  types are supported. If not specified,
    `tf.keras.backend.floatx()` is used,
   which default to `float32` unless you configured it otherwise
   (via `tf.keras.backend.set_floatx(float_dtype)`).
  **kwargs: Additional keyword arguments.
z%Expected float or integer dtype, got r:   Nr	   )r<   r)   r*   r=   is_floating
is_integerrA   rB   get_PARTITION_OFFSETr+   hashr   _ensure_keras_seededr   rC   rj   random_uniformrg   rh   r   r   r   r   r   noncer	   s          r   r   RandomUniform.__call__A  s    	00&95!  )9)9DUG1MNNv%+,E!::&7># *:%&Hd+ "))&&55  %%44;;U
 	
r   c                 J    U R                   U R                  U R                  S.$ )Nrg   rh   r%   rx   r   s    r   r   RandomUniform.get_configi  s    ++diiPPr   )rj   rh   rg   r%   )g皙?Nr-   	r*   r.   r/   r0   r1   rT   r   r   r3   r   r   r   ra   ra     s    2
&
PQr   ra   zkeras.initializers.RandomNormalz keras.initializers.random_normalc                   2    \ rS rSrSrSS jrS	S jrS rSrg)
RandomNormalim  aQ  Initializer that generates tensors with a normal distribution.

Also available via the shortcut function
`tf.keras.initializers.random_normal`.

Examples:

>>> # Standalone usage:
>>> initializer = tf.keras.initializers.RandomNormal(mean=0., stddev=1.)
>>> values = initializer(shape=(2, 2))

>>> # Usage in a TF-Keras layer:
>>> initializer = tf.keras.initializers.RandomNormal(mean=0., stddev=1.)
>>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

Args:
  mean: a python scalar or a scalar tensor. Mean of the random values to
    generate.
  stddev: a python scalar or a scalar tensor. Standard deviation of the
    random values to generate.
  seed: A Python integer. Used to make the behavior of the initializer
    deterministic. Note that a seeded initializer will produce the same
    random values across multiple calls.
Nc                 \    Xl         X l        X0l        [        R                  " USS9U l        g rc   meanstddevr%   r   ri   rj   r   r   r   r%   s       r   rT   RandomNormal.__init__  )    		!(!8!8;"
r   c           	      :   [        U R                  R                  U5        [        [	        U5      5      n[
        U;   a	  U[
           nUR                  [        S5      nUc  U R                  5         U(       a  [        U5      OSnUR                  SS5      nU(       aN  [        5         [        R                  " U R                  R                  UUU R                   U R"                  UU5      $ U R                  R                  XR                   U R"                  X%5      $ )a  Returns a tensor object initialized to random normal values.

Args:
  shape: Shape of the tensor.
  dtype: Optional dtype of the tensor. Only floating point types are
    supported. If not specified, `tf.keras.backend.floatx()` is used,
    which default to `float32` unless you configured it otherwise (via
    `tf.keras.backend.set_floatx(float_dtype)`)
  **kwargs: Additional keyword arguments.
Nr	   )r<   r)   r*   _assert_float_dtyper=   rB   ro   rp   r+   rq   r   rr   r   rC   rj   random_normalr   r   rt   s          r   r   RandomNormal.__call__  s     	00&9#Ju$56v%+,E!::&7># *:%&Hd+ "))&&44		  %%3399dkk5
 	
r   c                 J    U R                   U R                  U R                  S.$ Nr   r   r%   r   r   s    r   r   RandomNormal.get_config      		T[[$))LLr   rj   r   r%   r           rz   Nr-   r{   r   r   r   r}   r}   m  s    2
#
JMr   r}   z"keras.initializers.TruncatedNormalz#keras.initializers.truncated_normalc                   2    \ rS rSrSrSS jrS	S jrS rSrg)
TruncatedNormali  a,  Initializer that generates a truncated normal distribution.

Also available via the shortcut function
`tf.keras.initializers.truncated_normal`.

The values generated are similar to values from a
`tf.keras.initializers.RandomNormal` initializer except that values more
than two standard deviations from the mean are
discarded and re-drawn.

Examples:

>>> # Standalone usage:
>>> initializer = tf.keras.initializers.TruncatedNormal(mean=0., stddev=1.)
>>> values = initializer(shape=(2, 2))

>>> # Usage in a TF-Keras layer:
>>> initializer = tf.keras.initializers.TruncatedNormal(mean=0., stddev=1.)
>>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

Args:
  mean: a python scalar or a scalar tensor. Mean of the random values
    to generate.
  stddev: a python scalar or a scalar tensor. Standard deviation of the
    random values to generate before truncation.
  seed: A Python integer. Used to make the behavior of the initializer
    deterministic. Note that a seeded initializer will produce the same
    random values across multiple calls.
Nc                 \    Xl         X l        X0l        [        R                  " USS9U l        g rc   r   r   s       r   rT   TruncatedNormal.__init__  r   r   c           	         [        U R                  R                  U5        [        [	        U5      5      n[
        U;   a	  U[
           nUR                  [        S5      nUc  U R                  5         U(       a  [        U5      OSnUR                  SS5      nU(       as  U R                  R                  U R                  l        [        5         [        R                   " U R                  R"                  UUU R$                  U R&                  UU5      $ U R                  R#                  XR$                  U R&                  X%5      $ )a  Returns a tensor initialized to random normal values (truncated).

Args:
  shape: Shape of the tensor.
  dtype: Optional dtype of the tensor. Only floating point types are
    supported. If not specified, `tf.keras.backend.floatx()` is used,
    which default to `float32` unless you configured it otherwise (via
    `tf.keras.backend.set_floatx(float_dtype)`)
  **kwargs: Additional keyword arguments.
Nr	   )r<   r)   r*   r   r=   rB   ro   rp   r+   rq   r   rj   RNG_STATEFUL	_rng_typerr   r   rC   truncated_normalr   r   rt   s          r   r   TruncatedNormal.__call__  s    	00&9#Ju$56v%+,E!::&7># *:%&Hd+ &&33 "", !"))&&77		  %%6699dkk5
 	
r   c                 J    U R                   U R                  U R                  S.$ r   r   r   s    r   r   TruncatedNormal.get_config  r   r   r   r   r-   r{   r   r   r   r   r     s    <
(
TMr   r   z"keras.initializers.VarianceScalingz#keras.initializers.variance_scalingc                   @    \ rS rSrSr    S	S jrS
S jrS rS rSr	g)VarianceScalingi  a  Initializer that adapts its scale to the shape of its input tensors.

Also available via the shortcut function
`tf.keras.initializers.variance_scaling`.

With `distribution="truncated_normal" or "untruncated_normal"`, samples are
drawn from a truncated/untruncated normal distribution with a mean of zero
and a standard deviation (after truncation, if used) `stddev = sqrt(scale /
n)`, where `n` is:

- number of input units in the weight tensor, if `mode="fan_in"`
- number of output units, if `mode="fan_out"`
- average of the numbers of input and output units, if `mode="fan_avg"`

With `distribution="uniform"`, samples are drawn from a uniform distribution
within `[-limit, limit]`, where `limit = sqrt(3 * scale / n)`.

Examples:

>>> # Standalone usage:
>>> initializer = tf.keras.initializers.VarianceScaling(
... scale=0.1, mode='fan_in', distribution='uniform')
>>> values = initializer(shape=(2, 2))

>>> # Usage in a TF-Keras layer:
>>> initializer = tf.keras.initializers.VarianceScaling(
... scale=0.1, mode='fan_in', distribution='uniform')
>>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

Args:
    scale: Scaling factor (positive float).
    mode: One of `"fan_in"`, `"fan_out"`, `"fan_avg"`.
    distribution: Random distribution to use. One of `"truncated_normal"`,
        `"untruncated_normal"`, or `"uniform"`.
    seed: A Python integer. Used to make the behavior of the initializer
        deterministic. Note that a seeded initializer will produce the same
        random values across multiple calls.
Nc                 .   US::  a  [        SU S35      e1 SknX%;  a  [        SU SU S35      eUR                  5       nUS:X  a  Sn1 S	knX6;  a  [        S
U SU S35      eXl        X l        X0l        X@l        [        R                  " USS9U l        g )Nr   z0`scale` must be positive float. Received: scale=r:   >   fan_infan_avgfan_outzInvalid `mode` argument: z. Please use one of the normalr   >   uniformr   untruncated_normalz!Invalid `distribution` argument: z.Allowed distributions: rd   re   )	rA   lowerscalemodedistributionr%   r   ri   rj   )r   r   r   r   r%   allowed_modesallowed_distributionss          r   rT   VarianceScaling.__init__B  s     C<B5'K  9$+D6 2))6q:  $))+8#-L!

 43L> B**?)@C  
	(	!(!8!8;"
r   c                    [        U R                  R                  U5        [        [	        U5      5      n[
        U;   a	  U[
           nUR                  [        S5      nUc  U R                  5         U(       a  [        U5      OSnUR                  SS5      nU(       a,  [        5         [        R                  " U R                  UUUUS9$ U R                  XUS9$ )a  Returns a tensor object initialized as specified by the initializer.

Args:
  shape: Shape of the tensor.
  dtype: Optional dtype of the tensor. Only floating point types are
    supported. If not specified, `tf.keras.backend.floatx()` is used,
    which default to `float32` unless you configured it otherwise (via
    `tf.keras.backend.set_floatx(float_dtype)`)
  **kwargs: Additional keyword arguments.
Nr	   )r   r   ru   )r<   r)   r*   r   r=   rB   ro   rp   r+   rq   r   rr   r   rC   _generate_init_valrt   s          r   r   VarianceScaling.__call__i  s     	00&9#Ju$56v%+,E!::&7># *:%&Hd+ "))''  &&Uu&MMr   c                 `   U R                   n[        U5      u  pVU R                  S:X  a  U[        SU5      -  nO4U R                  S:X  a  U[        SU5      -  nOU[        SXV-   S-  5      -  nU R                  S:X  a7  [
        R                  " U5      S-  nU R                  R                  USXrU5      $ U R                  S:X  a4  [
        R                  " U5      nU R                  R                  USXrU5      $ [
        R                  " S	U-  5      nU R                  R                  X* XU5      $ )
Nr         ?r          @r   g۶%?r   r   g      @)r   _compute_fansr   maxr   mathsqrtrj   r   r   rs   )	r   r   r   ru   r   r   r   r   limits	            r   r   "VarianceScaling._generate_init_val  s(   

'.99 Sf%%EYY)#Sg&&ESv/3677E 22 YYu%(;;F))::sF5  "66YYu%F))77sF5  IIcEk*E))88vuU r   c                 `    U R                   U R                  U R                  U R                  S.$ )Nr   r   r   r%   r   r   s    r   r   VarianceScaling.get_config  s*    ZZII --II	
 	
r   )rj   r   r   r   r%   )r   r   r   Nr-   
r*   r.   r/   r0   r1   rT   r   r   r   r3   r   r   r   r   r     s-    %R '%
NNB6
r   r   zkeras.initializers.Orthogonalzkeras.initializers.orthogonalc                   8    \ rS rSrSrS	S jrS
S jrS rS rSr	g)
Orthogonali  aV  Initializer that generates an orthogonal matrix.

Also available via the shortcut function `tf.keras.initializers.orthogonal`.

If the shape of the tensor to initialize is two-dimensional, it is
initialized with an orthogonal matrix obtained from the QR decomposition of
a matrix of random numbers drawn from a normal distribution. If the matrix
has fewer rows than columns then the output will have orthogonal rows.
Otherwise, the output will have orthogonal columns.

If the shape of the tensor to initialize is more than two-dimensional,
a matrix of shape `(shape[0] * ... * shape[n - 2], shape[n - 1])`
is initialized, where `n` is the length of the shape vector.
The matrix is subsequently reshaped to give a tensor of the desired shape.

Examples:

>>> # Standalone usage:
>>> initializer = tf.keras.initializers.Orthogonal()
>>> values = initializer(shape=(2, 2))

>>> # Usage in a TF-Keras layer:
>>> initializer = tf.keras.initializers.Orthogonal()
>>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

Args:
  gain: multiplicative factor to apply to the orthogonal matrix
  seed: A Python integer. Used to make the behavior of the initializer
    deterministic. Note that a seeded initializer will produce the same
    random values across multiple calls.

References:
  - [Saxe et al., 2014](https://openreview.net/forum?id=_wzZwKpTDF_9C)
Nc                 P    Xl         X l        [        R                  " USS9U l        g rc   )gainr%   r   ri   rj   )r   r   r%   s      r   rT   Orthogonal.__init__  s$    		!(!8!8;"
r   c                    [        U R                  R                  USS9  [        [	        U5      5      n[        U5      S:  a  [        SU S[        U5       S35      eU R                  5         UR                  SS5      nU(       a*  [        5         [        R                  " U R                  XAUS	9$ U R                  X5      $ )
a  Returns a tensor object initialized to an orthogonal matrix.

Args:
  shape: Shape of the tensor.
  dtype: Optional dtype of the tensor. Only floating point types are
    supported. If not specified, `tf.keras.backend.floatx()` is used,
   which default to `float32` unless you configured it otherwise
   (via `tf.keras.backend.set_floatx(float_dtype)`)
  **kwargs: Additional keyword arguments.
Fsupport_partition   zKThe tensor to initialize must be at least two-dimensional. Received: shape=	 of rank r:   r	   Nr;   )r<   r)   r*   r   r=   lenrA   r+   r   rr   r   rC   r   rE   s        r   r   Orthogonal.__call__  s     	NN##Vu	
 $Ju$56u:>yUA7 
 	Hd+ "))''E  &&u44r   c                    SnUS S  H  nX4-  nM	     US   n[        XS5      [        XS5      4nU R                  R                  XbS9n[        R
                  R                  USS9u  p[        R
                  R                  U	5      n
U[        R                  " U
5      -  nX5:  a  [        R
                  R                  U5      nU R                  [        R                  " X5      -  $ )N   r   F)full_matrices)r   minrj   r   r?   linalgqrtensor_diag_partsignmatrix_transposer   reshape)r   r   r   num_rowsdimnum_cols
flat_shapeaqrds              r   r   Orthogonal._generate_init_val  s     ":COH 9(-s8/FG
 ""000Iyy||AU|3II&&q)	RWWQZ		**1-Ayy2::a///r   c                 4    U R                   U R                  S.$ )Nr   r%   r   r   s    r   r   Orthogonal.get_config  s    		49955r   )rj   r   r%   )r   Nr-   r   r   r   r   r   r     s    !F
5>0(6r   r   zkeras.initializers.Identityzkeras.initializers.identityc                   8    \ rS rSrSrS	S jrS
S jrS rS rSr	g)Identityi  a  Initializer that generates the identity matrix.

Also available via the shortcut function `tf.keras.initializers.identity`.

Only usable for generating 2D matrices.

Examples:

>>> # Standalone usage:
>>> initializer = tf.keras.initializers.Identity()
>>> values = initializer(shape=(2, 2))

>>> # Usage in a TF-Keras layer:
>>> initializer = tf.keras.initializers.Identity()
>>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

Args:
  gain: Multiplicative factor to apply to the identity matrix.
c                     Xl         g r-   r   )r   r   s     r   rT   Identity.__init__+  s    	r   Nc                 P   [        U R                  R                  USS9  [        [	        U5      5      n[        U5      S:w  a  [        SU S[        U5       S35      eUR                  SS5      nU(       a   [        R                  " U R                  XAUS	9$ U R                  X5      $ )
a  Returns a tensor object initialized to a 2D identity matrix.

Args:
  shape: Shape of the tensor. It should have exactly rank 2.
  dtype: Optional dtype of the tensor. Only floating point types are
   supported. If not specified, `tf.keras.backend.floatx()` is used,
   which default to `float32` unless you configured it otherwise
   (via `tf.keras.backend.set_floatx(float_dtype)`)
  **kwargs: Additional keyword arguments.
Fr   r   zNIdentity matrix initializer can only be used for 2D matrices. Received: shape=r   r:   r	   Nr;   )r<   r)   r*   r   r=   r   rA   r   r   rC   r   rE   s        r   r   Identity.__call__.  s     	NN##Vu	
 $Ju$56u:?##('3u:,aA  Hd+))''E  &&u44r   c                 L    [         R                  " USU06nU R                  U-  $ )Nr   )r?   eyer   )r   r   r   initializers       r   r   Identity._generate_init_valI  s$    ffe151yy;&&r   c                     SU R                   0$ )Nr   r   r   s    r   r   Identity.get_configM      		""r   r   )r   r-   r   r   r   r   r   r     s    (56'#r   r   z keras.initializers.GlorotUniformz!keras.initializers.glorot_uniformc                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )GlorotUniformiQ  a  The Glorot uniform initializer, also called Xavier uniform initializer.

Also available via the shortcut function
`tf.keras.initializers.glorot_uniform`.

Draws samples from a uniform distribution within `[-limit, limit]`, where
`limit = sqrt(6 / (fan_in + fan_out))` (`fan_in` is the number of input
units in the weight tensor and `fan_out` is the number of output units).

Examples:

>>> # Standalone usage:
>>> initializer = tf.keras.initializers.GlorotUniform()
>>> values = initializer(shape=(2, 2))

>>> # Usage in a TF-Keras layer:
>>> initializer = tf.keras.initializers.GlorotUniform()
>>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

Args:
  seed: A Python integer. Used to make the behavior of the initializer
    deterministic. Note that a seeded initializer will not produce the same
    random values across multiple calls, but multiple initializers will
    produce the same sequence when constructed with the same seed value.

References:
  - [Glorot et al., 2010](http://proceedings.mlr.press/v9/glorot10a.html)
c                 &   > [         TU ]  SSSUS9  g )Nr   r   r   r   superrT   r   r%   r)   s     r   rT   GlorotUniform.__init__t  s    IID 	 	
r   c                     SU R                   0$ Nr%   r%   r   s    r   r   GlorotUniform.get_configy  r   r   r   r-   	r*   r.   r/   r0   r1   rT   r   r3   __classcell__r)   s   @r   r   r   Q  s    :

# #r   r   zkeras.initializers.GlorotNormalz keras.initializers.glorot_normalc                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )GlorotNormali}  a+  The Glorot normal initializer, also called Xavier normal initializer.

Also available via the shortcut function
`tf.keras.initializers.glorot_normal`.

Draws samples from a truncated normal distribution centered on 0 with
`stddev = sqrt(2 / (fan_in + fan_out))` where `fan_in` is the number of
input units in the weight tensor and `fan_out` is the number of output units
in the weight tensor.

Examples:

>>> # Standalone usage:
>>> initializer = tf.keras.initializers.GlorotNormal()
>>> values = initializer(shape=(2, 2))

>>> # Usage in a TF-Keras layer:
>>> initializer = tf.keras.initializers.GlorotNormal()
>>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

Args:
  seed: A Python integer. Used to make the behavior of the initializer
    deterministic. Note that a seeded initializer will not produce the same
    random values across multiple calls, but multiple initializers will
    produce the same sequence when constructed with the same seed value.

References:
  - [Glorot et al., 2010](http://proceedings.mlr.press/v9/glorot10a.html)
c                 &   > [         TU ]  SSSUS9  g )Nr   r   r   r   r   r   s     r   rT   GlorotNormal.__init__  s!    +	 	 	
r   c                     SU R                   0$ r   r   r   s    r   r   GlorotNormal.get_config  r   r   r   r-   r   r   s   @r   r   r   }  s    <
# #r   r   zkeras.initializers.LecunNormalzkeras.initializers.lecun_normalc                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )LecunNormali  aR  Lecun normal initializer.

 Also available via the shortcut function
`tf.keras.initializers.lecun_normal`.

Initializers allow you to pre-specify an initialization strategy, encoded in
the Initializer object, without knowing the shape and dtype of the variable
being initialized.

Draws samples from a truncated normal distribution centered on 0 with
`stddev = sqrt(1 / fan_in)` where `fan_in` is the number of input units in
the weight tensor.

Examples:

>>> # Standalone usage:
>>> initializer = tf.keras.initializers.LecunNormal()
>>> values = initializer(shape=(2, 2))

>>> # Usage in a TF-Keras layer:
>>> initializer = tf.keras.initializers.LecunNormal()
>>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

Args:
  seed: A Python integer. Used to make the behavior of the initializer
    deterministic. Note that a seeded initializer will not produce the same
    random values across multiple calls, but multiple initializers will
    produce the same sequence when constructed with the same seed value.

References:
  - [Klambauer et al., 2017](https://arxiv.org/abs/1706.02515)
c                 &   > [         TU ]  SSSUS9  g )Nr   r   r   r   r   r   s     r   rT   LecunNormal.__init__      H3ED 	 	
r   c                     SU R                   0$ r   r   r   s    r   r   LecunNormal.get_config  r   r   r   r-   r   r   s   @r   r  r    s    B

# #r   r  zkeras.initializers.LecunUniformz keras.initializers.lecun_uniformc                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )LecunUniformi  a  Lecun uniform initializer.

 Also available via the shortcut function
`tf.keras.initializers.lecun_uniform`.

Draws samples from a uniform distribution within `[-limit, limit]`, where
`limit = sqrt(3 / fan_in)` (`fan_in` is the number of input units in the
weight tensor).

Examples:

>>> # Standalone usage:
>>> initializer = tf.keras.initializers.LecunUniform()
>>> values = initializer(shape=(2, 2))

>>> # Usage in a TF-Keras layer:
>>> initializer = tf.keras.initializers.LecunUniform()
>>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

Args:
  seed: A Python integer. Used to make the behavior of the initializer
    deterministic. Note that a seeded initializer will not produce the same
    random values across multiple calls, but multiple initializers will
    produce the same sequence when constructed with the same seed value.

References:
  - [Klambauer et al., 2017](https://arxiv.org/abs/1706.02515)
c                 &   > [         TU ]  SSSUS9  g )Nr   r   r   r   r   r   s     r   rT   LecunUniform.__init__      H94 	 	
r   c                     SU R                   0$ r   r   r   s    r   r   LecunUniform.get_config  r   r   r   r-   r   r   s   @r   r
  r
        :

# #r   r
  zkeras.initializers.HeNormalzkeras.initializers.he_normalc                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )HeNormali  a  He normal initializer.

 Also available via the shortcut function
`tf.keras.initializers.he_normal`.

It draws samples from a truncated normal distribution centered on 0 with
`stddev = sqrt(2 / fan_in)` where `fan_in` is the number of input units in
the weight tensor.

Examples:

>>> # Standalone usage:
>>> initializer = tf.keras.initializers.HeNormal()
>>> values = initializer(shape=(2, 2))

>>> # Usage in a TF-Keras layer:
>>> initializer = tf.keras.initializers.HeNormal()
>>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

Args:
  seed: A Python integer. Used to make the behavior of the initializer
    deterministic. Note that a seeded initializer will not produce the same
    random values across multiple calls, but multiple initializers will
    produce the same sequence when constructed with the same seed value.

References:
  - [He et al., 2015](https://arxiv.org/abs/1502.01852)
c                 &   > [         TU ]  SSSUS9  g )Nr   r   r   r   r   r   s     r   rT   HeNormal.__init__$  r  r   c                     SU R                   0$ r   r   r   s    r   r   HeNormal.get_config)  r   r   r   r-   r   r   s   @r   r  r    r  r   r  zkeras.initializers.HeUniformzkeras.initializers.he_uniformc                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )	HeUniformi-  a  He uniform variance scaling initializer.

 Also available via the shortcut function
`tf.keras.initializers.he_uniform`.

Draws samples from a uniform distribution within `[-limit, limit]`, where
`limit = sqrt(6 / fan_in)` (`fan_in` is the number of input units in the
weight tensor).

Examples:

>>> # Standalone usage:
>>> initializer = tf.keras.initializers.HeUniform()
>>> values = initializer(shape=(2, 2))

>>> # Usage in a TF-Keras layer:
>>> initializer = tf.keras.initializers.HeUniform()
>>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

Args:
  seed: A Python integer. Used to make the behavior of the initializer
    deterministic. Note that a seeded initializer will not produce the same
    random values across multiple calls, but multiple initializers will
    produce the same sequence when constructed with the same seed value.

References:
  - [He et al., 2015](https://arxiv.org/abs/1502.01852)
c                 &   > [         TU ]  SSSUS9  g )Nr   r   r   r   r   r   s     r   rT   HeUniform.__init__N  r  r   c                     SU R                   0$ r   r   r   s    r   r   HeUniform.get_configS  r   r   r   r-   r   r   s   @r   r  r  -  r  r   r  c                 ^    U c  [         R                  " 5       n [        R                  " U 5      $ r-   )r   floatxr?   as_dtyper   s    r   r=   r=   W  s"    } ;;ur   c                 r    [         R                  " U 5      n U R                  (       d  [        SU  S35      eU $ )zValidate and return floating point type based on `dtype`.

`dtype` must be a floating point type.

Args:
  dtype: The data type to validate.

Returns:
  Validated type.

Raises:
  ValueError: if `dtype` is not a floating point type.
z"Expected floating point type, got r:   )r?   r  rm   rA   r   s    r   r   r   ]  s5     KKE=eWAFGGLr   c                     [        U 5      S:  a  S=pOR[        U 5      S:X  a  U S   =pO<[        U 5      S:X  a  U S   nU S   nO"SnU SS  H  nX4-  nM	     U S   U-  nU S   U-  n[        U5      [        U5      4$ )zComputes the number of input and output units for a weight shape.

Args:
  shape: Integer shape tuple or TF tensor shape.

Returns:
  A tuple of integer scalars (fan_in, fan_out).
r   r   r   Nr   )r   int)r   r   r   receptive_field_sizer   s        r   r   r   q  s     5zA~	Uq 8#	Uqq(  !":C '  r11)22v;G$$r   c                     U Vs/ s H  o3[         ;  d  M  UPM     nnU(       a  [        SU S[          S35      eU(       d#  [        U;   d
  [        U;   a  [	        U  S35      eg g s  snf )NzUnknown keyword arguments: z. Allowed keyword arguments: r:   z9 initializer doesn't support partition-related arguments.)_ALLOWED_INITIALIZER_KWARGS	TypeErrorrB   rp   rA   )cls_namer   r   kinvalid_kwargss        r   r<   r<     s    !'PA4O+OaNP).)9 :""=!>aA
 	
 F"&76&Aj + +
 	
 'B  Qs
   A&A&c                  Z    [        [        R                  SS5      (       d  [        S5      eg)zMake sure the keras.backend global seed generator is set.

This is important for DTensor use case to ensure that each client are
initialized with same seed for tf.random.Generator, so that the value
created are in sync among all the clients.
	generatorNzWhen using DTensor APIs, you need to set the global seed before using any TF-Keras initializers. Please make sure to call `tf.keras.utils.set_random_seed()` in your code.)r&   r   _SEED_GENERATORrA   r   r   r   rr   rr     s1     7**K>>G
 	
 ?r   )T)(r1   r   r'   tensorflow.compat.v2compatv2r?   tf_keras.srcr   tf_keras.src.dtensorr   tf_keras.src.savingr    tensorflow.python.util.tf_exportr   rB   rp   _LAYOUTr&  r   r6   rI   rO   ra   r}   r   r   r   r   r   r   r  r
  r  r  r=   r   r   r<   rr   r   r   r   <module>r6     s       ! !   & 1 :$ & 
/1BGL  ./^ ^ 0^B (*DL&&K && M&&R ')BrJ&%; &% K&%R !#@R;{ ;;| &'	
KQK KQ
KQ\ %'IbHM; HMHMV ()	
RMk RM
RMj ()	
Q
k Q

Q
h #%D_6 _6_6D !#@R8#{ 8#8#v &'	
$#O $#
$#N %'Ib(#? (#(#V $&GB(#/ (#(#V %'Ib$#? $#$#N !#Ab$# $#$#N "$C$# $#$#N(%6
 
r   