+
    &j6                        ^ RI t ^ RIHtHt ^ RIHt ]P                  3R R lltRR]P                  3R R llt	RR]P                  3R	 R
 llt
]P                  3R R lltR t]P                  3R R llt]P                  3R R llt]P                  3R R llt]P                  3R R lltRR]P                  3R R lltR]P                  3R R lltR# )    N)CallableLiteralc                    V ^8  d   QhR\         R\        P                  R\        \        P                  .\        P                  3,          /# )   valuedtypereturnfloatmxDtyper   array)formats   "c/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/mlx/nn/init.py__annotate__r   	   s<      rxxj"(("#    c                   a a R VV 3R llpV# )a  An initializer that returns an array filled with ``value``.

Args:
    value (float): The value to fill the array with.
    dtype (Dtype, optional): The data type of the array. Default:
      ``float32``.

Returns:
    Callable[[array], array]: An initializer that returns an array with the
    same shape as the input, filled with ``value``.

Example:

    >>> init_fn = nn.init.constant(0.5)
    >>> init_fn(mx.zeros((2, 2)))
    array([[0.5, 0.5],
           [0.5, 0.5]], dtype=float32)
c                X    V ^8  d   QhR\         P                  R\         P                  /# r   ar	   r   r   )r   s   "r   r   constant.<locals>.__annotate__   s"     4 4rxx 4BHH 4r   c                 J   < \         P                  ! V P                  SSR 7      # r   )r   fullshape)r   r   r   s   &r   initializerconstant.<locals>.initializer   s    wwqwwU33r    )r   r   r   s   ff r   constantr!   	   s    ,4 4 r   g              ?c          
          V ^8  d   QhR\         R\         R\        P                  R\        \        P                  .\        P                  3,          /# )r   meanstdr   r	   r
   )r   s   "r   r   r   %   sD      
!02rxxj"(("#r   c                "   a aa R VV V3R llpV# )a  An initializer that returns samples from a normal distribution.

Args:
    mean (float, optional): Mean of the normal distribution. Default:
      ``0.0``.
    std (float, optional): Standard deviation of the normal distribution.
      Default: ``1.0``.
    dtype (Dtype, optional): The data type of the array. Default:
      ``float32``.

Returns:
    Callable[[array], array]: An initializer that returns an array with the
    same shape as the input, filled with samples from a normal distribution.

Example:

    >>> init_fn = nn.init.normal()
    >>> init_fn(mx.zeros((2, 2)))
    array([[-0.982273, -0.534422],
           [0.380709, 0.0645099]], dtype=float32)
c                X    V ^8  d   QhR\         P                  R\         P                  /# r   r   )r   s   "r   r   normal.<locals>.__annotate__>   s&     Q Qrxx QBHH Qr   c                 ^   < \         P                  P                  V P                  SSSR 7      # )r   scalelocr   )r   randomnormalr   )r   r   r$   r%   s   &r   r   normal.<locals>.initializer>   s%    yyaggSd%PPr   r    )r$   r%   r   r   s   fff r   r.   r.   %   s    2Q Q r   c          
          V ^8  d   QhR\         R\         R\        P                  R\        \        P                  .\        P                  3,          /# )r   lowhighr   r	   r
   )r   s   "r   r   r   D   sD      	!02rxxj"(("#r   c                "   a aa R VVV 3R llpV# )a  An initializer that returns samples from a uniform distribution.

Args:
    low (float, optional): The lower bound of the uniform distribution.
      Default: ``0.0``.
    high (float, optional): The upper bound of the uniform distribution.
      Default: ``1.0``
    dtype (Dtype, optional): The data type of the array. Default: ``float32``.

Returns:
    Callable[[array], array]: An initializer that returns an array
    with the same shape as the input, filled with samples from a uniform
    distribution

Example:

    >>> init_fn = nn.init.uniform(low=0, high=1)
    >>> init_fn(mx.zeros((2, 2)))
    array([[0.883935, 0.863726],
           [0.617261, 0.417497]], dtype=float32)
c                X    V ^8  d   QhR\         P                  R\         P                  /# r   r   )r   s   "r   r   uniform.<locals>.__annotate__]   s&     B Brxx BBHH Br   c                 ^   < \         P                  P                  SSV P                  SR 7      # r   )r   r-   uniformr   )r   r   r2   r1   s   &r   r   uniform.<locals>.initializer]   s%    yy  dAGG5 AAr   r    )r1   r2   r   r   s   fff r   r7   r7   D   s    2B B r   c                    V ^8  d   QhR\         P                  R\        \         P                  .\         P                  3,          /# r   r   r	   )r   r   r   r   )r   s   "r   r   r   c   s2      BHH hz2887K.L r   c                   a  R V 3R llpV# )a  An initializer that returns an identity matrix.

Args:
    dtype (Dtype, optional): The data type of the array. Default:
      ``float32``.

Returns:
    Callable[[array], array]: An initializer that returns an identity
    matrix with the same shape as the input.

Example:

    >>> init_fn = nn.init.identity()
    >>> init_fn(mx.zeros((2, 2)))
    array([[1, 0],
           [0, 1]], dtype=float32)
c                X    V ^8  d   QhR\         P                  R\         P                  /# )r   arrr	   r   )r   s   "r   r   identity.<locals>.__annotate__v   s"     3 3 3bhh 3r   c                    < V P                   ^8w  g*   V P                  ^ ,          V P                  ^,          8w  d   \        RV P                   R24      h\        P                  ! V P                  ^ ,          SR7      # )r   z6The input array must be a square matrix but got shape .)nr   )ndimr   
ValueErrorr   eye)r=   r   s   &r   r   identity.<locals>.initializerv   s^    88q=CIIaLCIIaL8HSTU  vv		!E22r   r    r   r   s   f r   identityrG   c   s    &3 3 r   c                 *   V P                   ^8  d   \        RV P                    R24      hV P                  R,          pV P                  ^ ,          pV P                   ^8  d1   ^pV P                  ^R  F  pW4,          pK  	  W,          pW#,          pW3# )r   zPGlorot / He initialization requires at least 2 dimensional input but input with z dimensions.)rB   rC   r   )xfan_infan_outreceptive_fieldds   &    r   _calculate_fan_in_fan_outrO      s    vvz vvhl4
 	

 WWR[FggajGvvz2A O  )+?r   c                    V ^8  d   QhR\         P                  R\        \         P                  \        .\         P                  3,          /# r:   r   r   r   r   r   )r   s   "r   r   r      7     ( (88(rxx)*(r   c                   a  RR V 3R lllpV# )a  A Glorot normal initializer.

This initializer samples from a normal distribution with a standard
deviation computed from the number of input (``fan_in``) and output
(``fan_out``) units according to:

.. math::
    \sigma = \gamma \sqrt{\frac{2.0}{\text{fan\_in} + \text{fan\_out}}}

For more details see the original reference: `Understanding the difficulty
of training deep feedforward neural networks
<https://proceedings.mlr.press/v9/glorot10a.html>`_

Args:
    dtype (Dtype, optional): The data type of the array. Default: ``float32``.

Returns:
    Callable[[array, float], array]: An initializer that returns an array
    with the same shape as the input, filled with samples from the Glorot
    normal distribution.

Example:

    >>> init_fn = nn.init.glorot_normal()
    >>> init_fn(mx.zeros((2, 2)))
    array([[0.191107, 1.61278],
           [-0.150594, -0.363207]], dtype=float32)
    >>> init_fn(mx.zeros((2, 2)), gain=4.0)
    array([[1.89613, -4.53947],
           [4.48095, 0.995016]], dtype=float32)
c                d    V ^8  d   QhR\         P                  R\        R\         P                  /# r   r   gainr	   r   r   r   )r   s   "r   r   #glorot_normal.<locals>.__annotate__   s.     G Grxx Gu Grxx Gr   c                    < \        V 4      w  r#V\        P                  ! R W#,           ,          4      ,          p\        P                  P                  V P                  VSR7      # )g       @r   r+   r   )rO   mathsqrtr   r-   r.   r   )r   rV   rK   rL   r%   r   s   &&   r   r   "glorot_normal.<locals>.initializer   sJ    3A6TYYsf&6788yyaggSFFr   r"   r    rF   s   f r   glorot_normalr_      s    FG G
 r   c                    V ^8  d   QhR\         P                  R\        \         P                  \        .\         P                  3,          /# r:   rQ   )r   s   "r   r   r      rR   r   c                   a  RR V 3R lllpV# )a  A Glorot uniform initializer.

This initializer samples from a uniform distribution with a range
computed from the number of input (``fan_in``) and output (``fan_out``)
units according to:

.. math::
    \sigma = \gamma \sqrt{\frac{6.0}{\text{fan\_in} + \text{fan\_out}}}

For more details see the original reference: `Understanding the difficulty
of training deep feedforward neural networks
<https://proceedings.mlr.press/v9/glorot10a.html>`_

Args:
    dtype (Dtype, optional): The data type of the array. Default: ``float32``.

Returns:
    Callable[[array, float], array]: An initializer that returns an array
    with the same shape as the input, filled with samples from the Glorot
    uniform distribution.

Example:

    >>> init_fn = nn.init.glorot_uniform()
    >>> init_fn(mx.zeros((2, 2)))
    array([[0.223404, -0.890597],
           [-0.379159, -0.776856]], dtype=float32)
    >>> init_fn(mx.zeros((2, 2)), gain=4.0)
    array([[-1.90041, 3.02264],
           [-0.912766, 4.12451]], dtype=float32)
c                d    V ^8  d   QhR\         P                  R\        R\         P                  /# rU   rW   )r   s   "r   r   $glorot_uniform.<locals>.__annotate__   s.     F Frxx Fu Frxx Fr   c                    < \        V 4      w  r#V\        P                  ! R W#,           ,          4      ,          p\        P                  P                  V) W@P                  SR7      # )g      @r   )rO   r[   r\   r   r-   r7   r   )r   rV   rK   rL   limitr   s   &&   r   r   #glorot_uniform.<locals>.initializer   sL    3A6tyy(8!9::yy  %u EEr   r^   r    rF   s   f r   glorot_uniformrg      s    FF F
 r   c                    V ^8  d   QhR\         P                  R\        \         P                  \        R,          \
        .\         P                  3,          /# r   r   r	   rK   rL   r   r   r   r   r   r   )r   s   "r   r   r      s?     7 7887rxx!45u=rxxGH7r   c                   a  RR V 3R lllpV# )a  Build a He normal initializer.

This initializer samples from a normal distribution with a standard
deviation computed from the number of input (``fan_in``) or output
(``fan_out``) units according to:

.. math::
    \sigma = \gamma \frac{1}{\sqrt{\text{fan}}}

where :math:`\text{fan}` is either the number of input units when the
``mode`` is ``"fan_in"`` or output units when the ``mode`` is
``"fan_out"``.

For more details see the original reference: `Delving Deep into Rectifiers:
Surpassing Human-Level Performance on ImageNet Classification
<https://arxiv.org/abs/1502.01852>`_

Args:
    dtype (Dtype, optional): The data type of the array. Default: ``float32``.

Returns:
    Callable[[array, str, float], array]: An initializer that returns an
    array with the same shape as the input, filled with samples from the He
    normal distribution.

Example:

    >>> init_fn = nn.init.he_normal()
    >>> init_fn(mx.zeros((2, 2)))  # uses fan_in
    array([[-1.25211, 0.458835],
           [-0.177208, -0.0137595]], dtype=float32)
    >>> init_fn(mx.zeros((2, 2)), mode="fan_out", gain=5)
    array([[5.6967, 4.02765],
           [-4.15268, -2.75787]], dtype=float32)
c                ~    V ^8  d   QhR\         P                  R\        R,          R\        R\         P                  /# r   r   moderV   r	   rj   r   r   r   r   )r   s   "r   r   he_normal.<locals>.__annotate__  sD     G G88G)*G G 
	Gr   c                    < \        V 4      w  r4VR 8X  d   TpMVR8X  d   TpM\        RV R24      hV\        P                  ! V4      ,          p\        P
                  P                  V P                  VSR7      # )rK   rL   Invalid mode: ". Valid modes are: fan_in, fan_outrZ   )rO   rC   r[   r\   r   r-   r.   r   )r   ro   rV   rK   rL   fanr%   r   s   &&&    r   r   he_normal.<locals>.initializer  sr    
 4A68CYC~dV3UVWWTYYs^#yyaggSFFr   rK   r"   r    rF   s   f r   	he_normalrx      s    NG G  r   c                    V ^8  d   QhR\         P                  R\        \         P                  \        R,          \
        .\         P                  3,          /# ri   rk   )r   s   "r   r   r   %  s?     9 9889rxx!45u=rxxGH9r   c                   a  RR V 3R lllpV# )a  A He uniform (Kaiming uniform) initializer.

This initializer samples from a uniform distribution with a range
computed from the number of input (``fan_in``) or output (``fan_out``)
units according to:

.. math::

    \sigma = \gamma \sqrt{\frac{3.0}{\text{fan}}}

where :math:`\text{fan}` is either the number of input units when the
``mode`` is ``"fan_in"`` or output units when the ``mode`` is
``"fan_out"``.

For more details see the original reference: `Delving Deep into Rectifiers:
Surpassing Human-Level Performance on ImageNet Classification
<https://arxiv.org/abs/1502.01852>`_


Args:
    dtype (Dtype, optional): The data type of the array. Default: ``float32``.

Returns:
    Callable[[array, str, float], array]: An initializer that returns an
    array with the same shape as the input, filled with samples from  the
    He uniform distribution.

Example:

    >>> init_fn = nn.init.he_uniform()
    >>> init_fn(mx.zeros((2, 2)))  # uses fan_in
    array([[0.0300242, -0.0184009],
           [0.793615, 0.666329]], dtype=float32)
    >>> init_fn(mx.zeros((2, 2)), mode="fan_out", gain=5)
    array([[-1.64331, -2.16506],
           [1.08619, 5.79854]], dtype=float32)
c                ~    V ^8  d   QhR\         P                  R\        R,          R\        R\         P                  /# rn   rp   )r   s   "r   r    he_uniform.<locals>.__annotate__N  sD     F F88F)*F F 
	Fr   c                   < \        V 4      w  r4VR 8X  d   TpMVR8X  d   TpM\        RV R24      hV\        P                  ! RV,          4      ,          p\        P
                  P                  V) W`P                  SR7      # )rK   rL   rs   rt   g      @r   )rO   rC   r[   r\   r   r-   r7   r   )r   ro   rV   rK   rL   ru   re   r   s   &&&    r   r   he_uniform.<locals>.initializerN  sy    
 4A68CYC~dV3UVWWtyys++yy  %u EEr   rw   r    rF   s   f r   
he_uniformr   %  s    RF F  r   c                    V ^8  d   QhR\         R\         R\         R\        P                  R\        \        P                  .\        P                  3,          /# )r   sparsityr$   r%   r   r	   r
   )r   s   "r   r   r   a  sR     , ,,
, 
, 88	,
 rxxj"(("#,r   c                &   a aaa R VVV V3R llpV# )a  An initializer that returns a sparse matrix.

Args:
    sparsity (float): The fraction of elements in each column to be set to
    zero.
    mean (float, optional): Mean of the normal distribution. Default:
      ``0.0``.
    std (float, optional): Standard deviation of the normal distribution.
      Default: ``1.0``.
    dtype (Dtype, optional): The data type of the array. Default:
      ``float32``.

Returns:
    Callable[[array], array]: An initializer that returns an array with the
    same shape as the input, filled with samples from a normal distribution.

Example:

    >>> init_fn = nn.init.sparse(sparsity=0.5)
    >>> init_fn(mx.zeros((2, 2)))
    array([[-1.91187, -0.117483],
   [0, 0]], dtype=float32)
c                X    V ^8  d   QhR\         P                  R\         P                  /# r   r   )r   s   "r   r   sparse.<locals>.__annotate__  s"      rxx BHH r   c                   < V P                   ^8w  d   \        R4      hV P                  w  r\        \        P
                  ! SV,          4      4      p\        P                  ! \        P                  P                  V P                  R7      ^R7      p\        P                  P                  V P                  SSSR7      p ^ V \        P                  ! V4      P                  V^4      VRRV13,          3&   V # )r   z,Only tensors with 2 dimensions are supportedr   )axisr*   :NNNN)rB   rC   r   intr[   ceilr   argsortr-   r7   r.   arangereshape)	r   rowscols	num_zerosorderr   r$   r   r%   s	   &    r   r   sparse.<locals>.initializer  s    66Q;KLLWW
		(T/23	

299,,177,;!DII177#4uMDE"))D/
!
!$
*E!ZiZ-,@
@Ar   r    )r   r$   r%   r   r   s   ffff r   sparser   a  s    <  r   c                    V ^8  d   QhR\         R\        P                  R\        \        P                  .\        P                  3,          /# )r   rV   r   r	   r
   )r   s   "r   r   r     s<     ) )
) hh)rxxj"(("#)r   c                   a a R VV 3R llpV# )ac  An initializer that returns an orthogonal matrix.

Args:
    gain (float, optional): Scaling factor for the orthogonal matrix.
        Default: ``1.0``.
    dtype (Dtype, optional): Data type of the array. Default: ``float32``.

Returns:
    Callable[[array], array]: An initializer that returns
    an orthogonal matrix with the same shape as the input.
c                X    V ^8  d   QhR\         P                  R\         P                  /# r   r   )r   s   "r   r    orthogonal.<locals>.__annotate__  s"      rxx BHH r   c                   < V P                   ^8w  d   \        R4      hV P                  w  r\        W4      p\        P
                  P                  W33R7      p\        P                  P                  V\        P                  R7      w  rV\        P                  ! V4      pV\        P                  ! V4      ,          pVRV1RV13,          pVS	,          pVP                  S4      # )r   zHOrthogonal initialization requires a 2D array but got a {a.ndim}D array.r   )streamN)rB   rC   r   maxr   r-   r.   linalgqrcpudiagsignastype)
r   r   r   rA   rmatqrrN   r   rV   s
   &       r   r   orthogonal.<locals>.initializer  s    66Q;& 
 WW
Oyyqf- yy||D|0 GGAJ
N eteUdUlO Hxxr   r    )rV   r   r   s   ff r   
orthogonalr     s     4 r   )r[   typingr   r   mlx.corecorer   float32r!   r.   r7   rG   rO   r_   rg   rx   r   r   r   r    r   r   <module>r      s     $  %'JJ: C2::@ C2::>  "zz :, jj(X jj(X jj7v jj9| jj	,` ) )r   