
    Vpfc                       d Z ddlmZ ddlmZ ddlZddlZddlmZmZm	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mZ ddlmZ  ed          ZeZeZeZeZeZeej         G d de	                                  Z eej!        fdCd            Z"eej!        fdCd            Z#eej!        fdDd            Z$edej!        fdEd            Z%edej!        fdFd!            Z&edej!        d"d#fdGd&            Z'e	 	 	 dHdId0            Z(dJd1Z)dKd2Z*ed'd(d)ej!        fdLd7            Z+ed'd(d)ej!        fdMd8            Z,e,Z-ed'd(d)ej!        fdMd9            Z.e.Z/ed'd(d)ej!        fdMd:            Z0ed'd(d)ej!        fdMd;            Z1ed'd(d)ej!        fdMd<            Z2e2Z3ed'd(d)ej!        fdMd=            Z4e4Z5ed>d(ej!        fdNdA            Z6ed>d(ej!        fdNdB            Z7dS )Oza
Common neural network layer initializers, consistent with definitions
used in Keras and Sonnet.
    )annotations)SequenceN)AnyLiteralProtocol)lax)random)core)dtypes)Array	ArrayLike)
set_modulezjax.nn.initializersc                  4    e Zd Zeej        fdd	            Zd
S )InitializerkeyKeyArrayshape
core.ShapedtypeDTypeLikeInexactreturnr   c                    t           N)NotImplementedErrorr   r   r   s      X/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/_src/nn/initializers.py__call__zInitializer.__call__2   s
         Nr   r   r   r   r   r   r   r   )__name__
__module____qualname__staticmethodjnpfloat_r    r   r   r   r   /   s@          *-    <  r   r   r   r   r   r   r   r   r   r   c                P    t          j        |t          j        |                    S )a  An initializer that returns a constant array full of zeros.

  The ``key`` argument is ignored.

  >>> import jax, jax.numpy as jnp
  >>> jax.nn.initializers.zeros(jax.random.key(42), (2, 3), jnp.float32)
  Array([[0., 0., 0.],
         [0., 0., 0.]], dtype=float32)
  )r$   zerosr   canonicalize_dtyper   s      r   r(   r(   8   s!     
5&3E::	;	;;r   c                P    t          j        |t          j        |                    S )a  An initializer that returns a constant array full of ones.

  The ``key`` argument is ignored.

  >>> import jax, jax.numpy as jnp
  >>> jax.nn.initializers.ones(jax.random.key(42), (3, 2), jnp.float32)
  Array([[1., 1.],
         [1., 1.],
         [1., 1.]], dtype=float32)
  )r$   onesr   r)   r   s      r   r+   r+   G   s!     
%2599	:	::r   valuer   c                     |fd
 fd	}|S )a  Builds an initializer that returns arrays full of a constant ``value``.

  Args:
    value: the constant value with which to fill the initializer.
    dtype: optional; the initializer's default dtype.

  >>> import jax, jax.numpy as jnp
  >>> initializer = jax.nn.initializers.constant(-7)
  >>> initializer(jax.random.key(42), (2, 3), jnp.float32)
  Array([[-7., -7., -7.],
         [-7., -7., -7.]], dtype=float32)
  r   r   r   r   r   r   r   r   c                Z    t          j        |          }t          j        ||          S )Nr   )r   r)   r$   full)r   r   r   r,   s      r   initzconstant.<locals>.initg   s,     %e,,E8E5....r   r   r&   )r,   r   r1   s   `  r   constantr2   W   s2    $ &+/ / / / / / /
 
+r   g{Gz?scaleRealNumericc                     |fd
 fd	}|S )aY  Builds an initializer that returns real uniformly-distributed random arrays.

  Args:
    scale: optional; the upper bound of the random distribution.
    dtype: optional; the initializer's default dtype.

  Returns:
    An initializer that returns arrays whose values are uniformly distributed in
    the range ``[0, scale)``.

  >>> import jax, jax.numpy as jnp
  >>> initializer = jax.nn.initializers.uniform(10.0)
  >>> initializer(jax.random.key(42), (2, 3), jnp.float32)  # doctest: +SKIP
  Array([[7.298188 , 8.691938 , 8.7230015],
         [2.0818567, 1.8662417, 5.5022564]], dtype=float32)
  r   r   r   r   r   r   r   r   c                    t          j        |          }t          j        | ||          t	          j        |          z  S r   )r   r)   r	   uniformr$   array)r   r   r   r3   s      r   r1   zuniform.<locals>.init   s:     %e,,E>#ue,,sy/F/FFFr   r   r&   )r3   r   r1   s   `  r   r7   r7   n   9    * &+G G G G G G G
 
+r   stddevc                     |fd
 fd	}|S )ax  Builds an initializer that returns real normally-distributed random arrays.

  Args:
    stddev: optional; the standard deviation of the distribution.
    dtype: optional; the initializer's default dtype.

  Returns:
    An initializer that returns arrays whose values are normally distributed
    with mean ``0`` and standard deviation ``stddev``.

  >>> import jax, jax.numpy as jnp
  >>> initializer = jax.nn.initializers.normal(5.0)
  >>> initializer(jax.random.key(42), (2, 3), jnp.float32)  # doctest: +SKIP
  Array([[ 3.0613258 ,  5.6129413 ,  5.6866574 ],
         [-4.063663  , -4.4520254 ,  0.63115686]], dtype=float32)
  r   r   r   r   r   r   r   r   c                    t          j        |          }t          j        | ||          t	          j        |          z  S r   )r   r)   r	   normalr$   r8   )r   r   r   r:   s      r   r1   znormal.<locals>.init   s:     %e,,E=eU++ci.F.FFFr   r   r&   )r:   r   r1   s   `  r   r=   r=      r9   r   g              @lowerupperc                      |fd
 fd	}|S )a  Builds an initializer that returns truncated-normal random arrays.

  Args:
    stddev: optional; the standard deviation of the untruncated distribution.
      Note that this function does not apply the stddev correction as is done in
      the variancescaling initializers, and users are expected to apply this
      correction themselves via the stddev arg if they wish to employ it.
    dtype: optional; the initializer's default dtype.
    lower: Float representing the lower bound for truncation. Applied before
      the output is multiplied by the stddev.
    upper: Float representing the upper bound for truncation. Applied before
      the output is multiplied by the stddev.

  Returns:
    An initializer that returns arrays whose values follow the truncated normal
    distribution with mean ``0`` and standard deviation ``stddev``, and range
    :math:`\rm{lower * stddev} < x < \rm{upper * stddev}`.

  >>> import jax, jax.numpy as jnp
  >>> initializer = jax.nn.initializers.truncated_normal(5.0)
  >>> initializer(jax.random.PRNGKey(42), (2, 3), jnp.float32)  # doctest: +SKIP
  Array([[ 2.9047365,  5.2338114,  5.29852  ],
         [-3.836303 , -4.192359 ,  0.6022964]], dtype=float32)
  r   r   r   r   r   r   r   r   c                    t          j        |          }t          j        | ||          t	          j        |          z  S r   )r   r)   r	   truncated_normalr$   r8   )r   r   r   r?   r:   r@   s      r   r1   ztruncated_normal.<locals>.init   sK     %e,,E"UE5%) )+.9VU+C+CD Dr   r   r&   )r:   r   r?   r@   r1   s   ` `` r   rC   rC      sH    @ &+D D D D D D D D D 
+r   r&   Sequence[int]in_axisint | Sequence[int]out_axis
batch_axistuple[float, float]c                4    t                     dk    r t          dt                      d          t          |t                    r	 |         }n t	          j         fd|D                       }t          |t                    r	 |         }n t	          j         fd|D                       }t          |t                    r	 |         }n t	          j         fd|D                       }t	          j                   |z  |z  |z  }||z  }||z  }	||	fS )z
  Compute effective input and output sizes for a linear or convolutional layer.

  Axes not in in_axis, out_axis, or batch_axis are assumed to constitute the
  "receptive field" of a convolution (kernel spatial dimensions).
     z*Can't compute input and output sizes of a z1-dimensional weights tensor. Must be at least 2D.c                     g | ]
}|         S r&   r&   .0ir   s     r   
<listcomp>z!_compute_fans.<locals>.<listcomp>   s    333aq333r   c                     g | ]
}|         S r&   r&   rO   s     r   rR   z!_compute_fans.<locals>.<listcomp>   s    555q%(555r   c                     g | ]
}|         S r&   r&   rO   s     r   rR   z!_compute_fans.<locals>.<listcomp>   s    999E!H999r   )len
ValueError
isinstanceintmathprod)
r   rG   rI   rJ   in_sizeout_size
batch_sizereceptive_field_sizefan_infan_outs
   `         r   _compute_fansra      sN    	ZZ1__
 I#e** I I I J J J  5GnGGi3333733344G# 7XHHy5555H55566H
C   ;z"JJ9999j999::J5))G3h>K))&++'	r   c                   t          j        |           \  }}t          j        d|          j        j        }t          j        |          }t          j	        dt          j
        |||          z                                |          }dt          j        z  t          j
        |||                              |          z  }|t          j        d|z            z  S )zj
  Sample uniform random values within a disk on the complex plane,
  with zero mean and unit variance.
  r                    ?)r	   splitnpr8   realr   r   to_complex_dtyper$   sqrtr7   astypepiexp)r   r   r   key_r	key_theta
real_dtyperthetas           r   _complex_uniformrr      s     \#&&%x5!!&,*

!*
-
-%	hq6>%
;;;<<CCEJJ!
cf*v~i
CCJJ5QQ
Q%	
SWR%Z  	  r   c                @   t          j        |           \  }}t          j        d|          j        j        }t          j        |          }dt          j	        t          j        |dz   |                    z
  t          j
        |||                              |          z  }t          j        t          j        d|z
                       }dt          j        z  t          j
        |||                              |          z  }	|t          j	        d|	z            z  S )z
  Sample random values from a centered normal distribution on the complex plane,
  whose modulus is truncated to `upper`, and the variance before the truncation
  is one.
  r   rM   rc   rd   )r	   re   rf   r8   rg   r   r   rh   r$   rl   r7   rj   ri   logrk   )
r   r@   r   r   rm   rn   ro   trp   rq   s
             r   _complex_truncated_normalrv      s     \#&&%x5!!&,*

!*
-
-%	CGCI
mU33444	uj	1	1	8	8	?	?@!	hA!
cf*v~i
CCJJ5QQ
Q%	
SWR%Z  	  r   mode;Literal['fan_in'] | Literal['fan_out'] | Literal['fan_avg']distributionDLiteral['truncated_normal'] | Literal['normal'] | Literal['uniform']c                ,     |fd
 fd	}|S )a  
  Initializer that adapts its scale to the shape of the weights tensor.

  With ``distribution="truncated_normal"`` or ``distribution="normal"``, samples
  are drawn from a (truncated) normal distribution with a mean of zero
  and a standard deviation (after truncation, if applicable) of
  :math:`\sqrt{\frac{scale}{n}}`, where `n` is:

  * the number of input units in the weights tensor, if ``mode="fan_in"``,
  * the number of output units, if ``mode="fan_out"``, or
  * the average of the numbers of input and output units, if ``mode="fan_avg"``.

  This initializer can be configured with ``in_axis``, ``out_axis``, and
  ``batch_axis`` to work with general convolutional or dense layers; axes that
  are not in any of those arguments are assumed to be the "receptive field"
  (convolution kernel spatial axes).

  With ``distribution="truncated_normal"``, the absolute values of the samples
  are truncated at 2 standard deviations before scaling.

  With ``distribution="uniform"``, samples are drawn from:

  * a uniform interval, if `dtype` is real, or
  * a uniform disk, if `dtype` is complex,

  with a mean of zero and a standard deviation of :math:`\sqrt{\frac{scale}{n}}`
  where `n` is defined above.

  Args:
    scale: scaling factor (positive float).
    mode: one of ``"fan_in"``, ``"fan_out"``, and ``"fan_avg"``.
    distribution: random distribution to use. One of ``"truncated_normal"``,
      ``"normal"`` and ``"uniform"``.
    in_axis: axis or sequence of axes of the input dimension in the weights
      array.
    out_axis: axis or sequence of axes of the output dimension in the weights
      array.
    batch_axis: axis or sequence of axes in the weight array that should be
      ignored.
    dtype: the dtype of the weights.
  r   r   r   r   r   r   r   r   c                   t          j        |          }t          j        |          }t	          |
          \  }}dk    r|}n*dk    r|}n!dk    r	||z   dz  }nt          d           t          j        |z  |          }	dk    rt          j        |t          j	                  rEt          j
        |          t          j        d|          z  }t          j        | d	d||          |z  S t          j
        |          t          j        d
|          z  }t          | d||          |z  S 	dk    r+t          j        | ||          t          j
        |          z  S 	dk    rtt          j        |t          j	                  r/t          j        | ||d          t          j
        d|z            z  S t!          | ||          t          j
        |          z  S t          d	           )Nr_   r`   fan_avgrc   z/invalid mode for variance scaling initializer: r/   rC   g۶%?rD   gVr?r=   r7   rE      z7invalid distribution for variance scaling initializer: )r
   canonicalize_shaper   r)   ra   rV   r$   r8   
issubdtypefloatingri   r	   rC   rv   r=   r7   rr   )r   r   r   r_   r`   denominatorvariancer:   rJ   ry   rG   rw   rI   r3   s           r   r1   zvariance_scaling.<locals>.init=  s    #E**E%e,,E#E7HjIIOFGxv			'KK			6G+;q*@KK@$@@B B By,E:::H)))	s|	,	, H(##ci0BE&J&JJ&sB5%@@6II (##ci0BE&J&JJ(a>>GG		!	!]3u--0B0BBB		"	"	s|	,	, H~c5%44sxH7M7MMMUE22SXh5G5GGG_Q]__```r   r   r&   )r3   rw   ry   rG   rI   rJ   r   r1   s   ``````  r   variance_scalingr     s^    n &+a a a a a a a a a a a aB 
+r   c           	     .    t          ddd| |||          S )a  Builds a Glorot uniform initializer (aka Xavier uniform initializer).

  A `Glorot uniform initializer`_ is a specialization of
  :func:`jax.nn.initializers.variance_scaling` where ``scale = 1.0``,
  ``mode="fan_avg"``, and ``distribution="uniform"``.

  Args:
    in_axis: axis or sequence of axes of the input dimension in the weights
      array.
    out_axis: axis or sequence of axes of the output dimension in the weights
      array.
    batch_axis: axis or sequence of axes in the weight array that should be
      ignored.
    dtype: the dtype of the weights.

  Returns:
    An initializer.

  Examples:

  >>> import jax, jax.numpy as jnp
  >>> initializer = jax.nn.initializers.glorot_uniform()
  >>> initializer(jax.random.key(42), (2, 3), jnp.float32)  # doctest: +SKIP
  Array([[ 0.50350785,  0.8088631 ,  0.81566876],
         [-0.6393332 , -0.6865721 ,  0.11003882]], dtype=float32)

  .. _Glorot uniform initializer: http://proceedings.mlr.press/v9/glorot10a.html
        ?r}   r7   rG   rI   rJ   r   r   r   s       r   glorot_uniformr   `  s/    B 
#y)W#+
%
Q 
Q 
Q Qr   c           	     .    t          ddd| |||          S )a  Builds a Glorot normal initializer (aka Xavier normal initializer).

  A `Glorot normal initializer`_ is a specialization of
  :func:`jax.nn.initializers.variance_scaling` where ``scale = 1.0``,
  ``mode="fan_avg"``, and ``distribution="truncated_normal"``.

  Args:
    in_axis: axis or sequence of axes of the input dimension in the weights
      array.
    out_axis: axis or sequence of axes of the output dimension in the weights
      array.
    batch_axis: axis or sequence of axes in the weight array that should be
      ignored.
    dtype: the dtype of the weights.

  Returns:
    An initializer.

  Examples:

  >>> import jax, jax.numpy as jnp
  >>> initializer = jax.nn.initializers.glorot_normal()
  >>> initializer(jax.random.key(42), (2, 3), jnp.float32)  # doctest: +SKIP
  Array([[ 0.41770416,  0.75262755,  0.7619329 ],
         [-0.5516644 , -0.6028657 ,  0.08661086]], dtype=float32)

  .. _Glorot normal initializer: http://proceedings.mlr.press/v9/glorot10a.html
  r   r}   rC   r   r   r   s       r   glorot_normalr     s0    B 
#y*<g#+
%
Q 
Q 
Q Qr   c           	     .    t          ddd| |||          S )a  Builds a Lecun uniform initializer.

  A `Lecun uniform initializer`_ is a specialization of
  :func:`jax.nn.initializers.variance_scaling` where ``scale = 1.0``,
  ``mode="fan_in"``, and ``distribution="uniform"``.

  Args:
    in_axis: axis or sequence of axes of the input dimension in the weights
      array.
    out_axis: axis or sequence of axes of the output dimension in the weights
      array.
    batch_axis: axis or sequence of axes in the weight array that should be
      ignored.
    dtype: the dtype of the weights.

  Returns:
    An initializer.

  Examples:

  >>> import jax, jax.numpy as jnp
  >>> initializer = jax.nn.initializers.lecun_uniform()
  >>> initializer(jax.random.key(42), (2, 3), jnp.float32)  # doctest: +SKIP
  Array([[ 0.56293887,  0.90433645,  0.9119454 ],
         [-0.71479625, -0.7676109 ,  0.12302713]], dtype=float32)

  .. _Lecun uniform initializer: https://arxiv.org/abs/1706.02515
  r   r_   r7   r   r   r   s       r   lecun_uniformr     /    B 
#xG#+
%
Q 
Q 
Q Qr   c           	     .    t          ddd| |||          S )a  Builds a Lecun normal initializer.

  A `Lecun normal initializer`_ is a specialization of
  :func:`jax.nn.initializers.variance_scaling` where ``scale = 1.0``,
  ``mode="fan_in"``, and ``distribution="truncated_normal"``.

  Args:
    in_axis: axis or sequence of axes of the input dimension in the weights
      array.
    out_axis: axis or sequence of axes of the output dimension in the weights
      array.
    batch_axis: axis or sequence of axes in the weight array that should be
      ignored.
    dtype: the dtype of the weights.

  Returns:
    An initializer.

  Examples:

  >>> import jax, jax.numpy as jnp
  >>> initializer = jax.nn.initializers.lecun_normal()
  >>> initializer(jax.random.key(42), (2, 3), jnp.float32)  # doctest: +SKIP
  Array([[ 0.46700746,  0.8414632 ,  0.8518669 ],
         [-0.61677957, -0.67402434,  0.09683388]], dtype=float32)

  .. _Lecun normal initializer: https://arxiv.org/abs/1706.02515
  r   r_   rC   r   r   r   s       r   lecun_normalr     0    B 
#x);W#+
%
Q 
Q 
Q Qr   c           	     .    t          ddd| |||          S )a  Builds a He uniform initializer (aka Kaiming uniform initializer).

  A `He uniform initializer`_ is a specialization of
  :func:`jax.nn.initializers.variance_scaling` where ``scale = 2.0``,
  ``mode="fan_in"``, and ``distribution="uniform"``.

  Args:
    in_axis: axis or sequence of axes of the input dimension in the weights
      array.
    out_axis: axis or sequence of axes of the output dimension in the weights
      array.
    batch_axis: axis or sequence of axes in the weight array that should be
      ignored.
    dtype: the dtype of the weights.

  Returns:
    An initializer.

  Examples:

  >>> import jax, jax.numpy as jnp
  >>> initializer = jax.nn.initializers.he_uniform()
  >>> initializer(jax.random.key(42), (2, 3), jnp.float32)  # doctest: +SKIP
  Array([[ 0.79611576,  1.2789248 ,  1.2896855 ],
         [-1.0108745 , -1.0855657 ,  0.17398663]], dtype=float32)

  .. _He uniform initializer: https://arxiv.org/abs/1502.01852
  r>   r_   r7   r   r   r   s       r   
he_uniformr     r   r   c           	     .    t          ddd| |||          S )a  Builds a He normal initializer (aka Kaiming normal initializer).

  A `He normal initializer`_ is a specialization of
  :func:`jax.nn.initializers.variance_scaling` where ``scale = 2.0``,
  ``mode="fan_in"``, and ``distribution="truncated_normal"``.

  Args:
    in_axis: axis or sequence of axes of the input dimension in the weights
      array.
    out_axis: axis or sequence of axes of the output dimension in the weights
      array.
    batch_axis: axis or sequence of axes in the weight array that should be
      ignored.
    dtype: the dtype of the weights.

  Returns:
    An initializer.

  Examples:

  >>> import jax, jax.numpy as jnp
  >>> initializer = jax.nn.initializers.he_normal()
  >>> initializer(jax.random.key(42), (2, 3), jnp.float32)  # doctest: +SKIP
  Array([[ 0.6604483 ,  1.1900088 ,  1.2047218 ],
         [-0.87225807, -0.95321447,  0.1369438 ]], dtype=float32)

  .. _He normal initializer: https://arxiv.org/abs/1502.01852
  r>   r_   rC   r   r   r   s       r   	he_normalr     r   r   r   column_axisrX   c                     |fd
 fd	}|S )a  
  Builds an initializer that returns uniformly distributed orthogonal matrices.

  If the shape is not square, the matrices will have orthonormal rows or columns
  depending on which side is smaller.

  Args:
    scale: the upper bound of the uniform distribution.
    column_axis: the axis that contains the columns that should be orthogonal.
    dtype: the default dtype of the weights.

  Returns:
    An orthogonal initializer.

  Examples:

  >>> import jax, jax.numpy as jnp
  >>> initializer = jax.nn.initializers.orthogonal()
  >>> initializer(jax.random.key(42), (2, 3), jnp.float32)  # doctest: +SKIP
  Array([[ 3.9026976e-01,  7.2495741e-01, -5.6756169e-01],
         [ 8.8047469e-01, -4.7409311e-01, -1.3157725e-04]],            dtype=float32)
  r   r   r   r   r   r   r   r   c           	        t          j        |          }t          |          dk     rt          d          t	          j        |          |
         z  |
         }}||k     r||fn||f}t          j        | ||          }t          j	        
                    |          \  }}t          j        t          j        t          j        |                    |j                  }	||	z  }||k     r|j        }t          j        |t%          t'          j        |
                    |
         fz             }t          j        |d
          }t          j        |          |z  S )Nrc   z3orthogonal initializer requires at least a 2D shape)rankrE   )r   r)   rU   rV   rY   rZ   r	   r=   r$   linalgqrr   broadcast_to_ranksigndiagndimTreshapetuplerf   deletemoveaxisr8   )r   r   r   n_rowsn_colsmatrix_shapeAQR	diag_signr   r3   s             r   r1   zorthogonal.<locals>.initZ  s8    %e,,E
5zzA~~LMMMYu%%{);;U;=OFF'-FF##VV<LLc<//A:==DAq%chsx{{&;&;!&IIIINAACAuRYuk::;;u[?Q>SSTTAQK((A9UE""Q&&r   r   r&   r3   r   r   r1   s   ``  r   
orthogonalr   @  s8    8 &+' ' ' ' ' ' ' '  
+r   c                     |fd
 fd	}|S )ae  
  Builds an initializer for delta orthogonal kernels.

  Args:
    scale: the upper bound of the uniform distribution.
    column_axis: the axis that contains the columns that should be orthogonal.
    dtype: the default dtype of the weights.

  Returns:
    A `delta orthogonal initializer`_. The shape passed to the initializer must
    be 3D, 4D, or 5D.

  Examples:

  >>> import jax, jax.numpy as jnp
  >>> initializer = jax.nn.initializers.delta_orthogonal()
  >>> initializer(jax.random.key(42), (3, 3, 3), jnp.float32)  # doctest: +SKIP
  Array([[[ 0.        ,  0.        ,  0.        ],
          [ 0.        ,  0.        ,  0.        ],
          [ 0.        ,  0.        ,  0.        ]],
  <BLANKLINE>
         [[ 0.27858758, -0.7949833 , -0.53887904],
          [ 0.9120717 ,  0.04322892,  0.40774566],
          [-0.30085585, -0.6050892 ,  0.73712474]],
  <BLANKLINE>
         [[ 0.        ,  0.        ,  0.        ],
          [ 0.        ,  0.        ,  0.        ],
          [ 0.        ,  0.        ,  0.        ]]], dtype=float32)


  .. _delta orthogonal initializer: https://arxiv.org/abs/1806.05393
  r   r   r   r   r   r   r   r   c                   t          j        |          }t          |          dvrt          d          |d         |d         k     rt          d          t	          
|          } || |dd                    }t          j        ||          }t          |          dk    r0|d	         }|j        |d
z
  dz  df                             |          S t          |          dk    r<|d d         \  }}|j        |d
z
  dz  |d
z
  dz  df                             |          S |d d         \  }}}	|j        |d
z
  dz  |d
z
  dz  |	d
z
  dz  df                             |          S )N)r~         z;Delta orthogonal initializer requires a 3D, 4D or 5D shape.rE   rD   z/`fan_in` must be less or equal than `fan_out`. )r3   r   r   r/   r~   r   rM   rc   .r   )	r   r)   rU   rV   r   r$   r(   atset)r   r   r   
ortho_initortho_matrixWkk1k2k3r   r3   s             r   r1   zdelta_orthogonal.<locals>.init  s    %e,,E
5zz""   ! ! !Ry59HIII%[NNNJ:c5:..L	%u%%%A
5zzQ
(aT1Q3(C- $$\222	UqRaRyfb"T2a4!)bdQY+,00>>>!9jb"bT2a4!)bdQYA	367;;LIIIr   r   r&   r   s   ``  r   delta_orthogonalr   l  sA    N &+J J J J J J J J* 
+r   r   )r,   r   r   r   r   r   )r3   r4   r   r   r   r   )r:   r4   r   r   r   r   )
r:   r4   r   r   r?   r4   r@   r4   r   r   )rD   rE   r&   )
r   rF   rG   rH   rI   rH   rJ   rH   r   rK   )r   r   r   rF   r   r   r   r   )
r   r   r@   r   r   rF   r   r   r   r   )r3   r4   rw   rx   ry   rz   rG   rH   rI   rH   rJ   rF   r   r   r   r   )
rG   rH   rI   rH   rJ   rF   r   r   r   r   )r3   r4   r   rX   r   r   r   r   )8__doc__
__future__r   collections.abcr   rY   typingr   r   r   numpyrf   	jax.numpyr$   jaxr   r	   jax._srcr
   r   jax._src.typingr   r   jax._src.utilr   exportr   DTypeLikeFloatDTypeLikeComplexr   r4   runtime_checkabler   r%   r(   r+   r2   r7   r=   rC   ra   rr   rv   r   r   xavier_uniformr   xavier_normalr   r   r   kaiming_uniformr   kaiming_normalr   r   r&   r   r   <module>r      s   
 # " " " " " $ $ $ $ $ $   ) ) ) ) ) ) ) ) ) )                                   , , , , , , , , $ $ $ $ $ $	)	*	*       (      %(J< < < < <  $':; ; ; ; ; '*z    , !%&)j    2 !%%(Z    2 +//2z*.*-# # # # #J 132446    @! ! ! !! ! ! !"  "$"$ JU U U U Un 2435/1-0Z!Q !Q !Q !Q !QF  1324.0,/J!Q !Q !Q !Q !QF 1324.0,/J!Q !Q !Q !Q !QF 0213-/+.:!Q !Q !Q !Q !QF .0/1+-),!Q !Q !Q !Q !QF -/.0*,(+
!Q !Q !Q !Q !QF $'"$),) ) ) ) )V J9 9 9 9 9 9 9r   