ó
    !Eñia  ã                   óf  • S r SSKrSSKrSSKJr  SSKJrJr  SSKJ	r	  SSK
r
SSK
Jr  / SQr\" S5      r\	" S	5      r\S
   r\S   r S2S\S\S\S\
R$                  S-  S\4
S jjr S2S\S\S\S\
R$                  S-  S\4
S jjr S2S\S\S\S\S\S\
R$                  S-  S\4S jjrS\S\S\4S jrS\S\4S jr S2S\S\\-  S-  S\4S jjr   S3S\S\S\S\
R$                  S-  S\4
S jjr   S3S\S\S\S\
R$                  S-  S\4
S jjr     S4S\S\S\S\S\S\
R$                  S-  S\4S jjrS\S\S\4S jrS\S\4S  jrS\S\4S! jrS\S\4S" jr S5S\S#\S\4S$ jjr!S\S\"\\4   4S% jr#  S6S\S&\S\
R$                  S-  S\4S' jjr$  S6S\S&\S\
R$                  S-  S\4S( jjr%S\S)\S\4S* jr&    S7S\S\S)\S\S\
R$                  S-  S\4S+ jjr'    S7S\S\S)\S\S\
R$                  S-  S\4S, jjr(  S8S\S&\S\
R$                  S-  S\4S- jjr)  S9S\S.\S\S\
R$                  S-  S\4
S/ jjr*S0\\\4   S\\\4   4S1 jr+\+" \5      r,\+" \5      r-\+" \5      r.\+" \ 5      r/\+" \!5      r0\+" \$5      r1\+" \%5      r2\+" \'5      r3\+" \(5      r4\+" \)5      r5\+" \*5      r6g):zHThis file contains utilities for initializing neural network parameters.é    N)ÚCallable)ÚLiteralÚTypeVar)Ú	ParamSpec)ÚTensor)Úcalculate_gainÚuniform_Únormal_Útrunc_normal_Ú	constant_Úones_Úzeros_Úeye_Údirac_Úxavier_uniform_Úxavier_normal_Úkaiming_uniform_Úkaiming_normal_Úorthogonal_Úsparse_ÚuniformÚnormalÚconstantÚeyeÚdiracÚxavier_uniformÚxavier_normalÚkaiming_uniformÚkaiming_normalÚ
orthogonalÚsparseÚ_RÚ_P)ÚlinearÚconv1dÚconv2dÚconv3dÚconv_transpose1dÚconv_transpose2dÚconv_transpose3dÚsigmoidÚtanhÚreluÚ
leaky_reluÚselu)Úfan_inÚfan_outÚtensorÚaÚbÚ	generatorÚreturnc                 ó‚   • [         R                  " 5          U R                  XUS9sS S S 5        $ ! , (       d  f       g = f©N©r5   )ÚtorchÚno_gradr	   ©r2   r3   r4   r5   s       ÚJ/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/nn/init.pyÚ_no_grad_uniform_r>   E   s'   € ô 
�Š�Ø�‰˜q¨yˆÐ9÷ 
��úó   –0°
>ÚmeanÚstdc                 ó‚   • [         R                  " 5          U R                  XUS9sS S S 5        $ ! , (       d  f       g = fr8   )r:   r;   r
   ©r2   r@   rA   r5   s       r=   Ú_no_grad_normal_rD   L   s'   € ô 
�Š�Ø�~‰~˜d°9ˆ~Ð=÷ 
��úr?   c                 óü  • S[         S[         4S jnXSU-  -
  :  d  XSU-  -   :”  a  [        R                  " SSS9  [        R                  " 5          U" X1-
  U-  5      nU" XA-
  U-  5      nU R                  SU-  S-
  SU-  S-
  US9  U R                  5         U R                  U[        R                  " S	5      -  5        U R                  U5        U R                  X4S
9  U sS S S 5        $ ! , (       d  f       g = f)NÚxr6   c                 óh   • S[         R                  " U [         R                  " S5      -  5      -   S-  $ )Nç      ð?ç       @)ÚmathÚerfÚsqrt)rF   s    r=   Únorm_cdfÚ(_no_grad_trunc_normal_.<locals>.norm_cdf_   s(   € à”d—h’h˜q¤4§9¢9¨S£>Ñ1Ó2Ñ2°cÑ9Ð9ó    é   zjmean is more than 2 std from [a, b] in nn.init.trunc_normal_. The distribution of values may be incorrect.©Ú
stacklevelé   r9   rI   )ÚminÚmax)ÚfloatÚwarningsÚwarnr:   r;   r	   Úerfinv_Úmul_rJ   rL   Úadd_Úclamp_)	r2   r@   rA   r3   r4   r5   rM   ÚlÚus	            r=   Ú_no_grad_trunc_normal_r_   V   sé   € ð:”Eð :œeô :ð 	�1�s‘7‰{Ó ¨1¨s©7¡{Ó 2Ü�Šð;àò	
ô 
�Š�ñ �a‘h #Ñ%Ó&ˆÙ�a‘h #Ñ%Ó&ˆð 	�‰˜˜A™ ™	 1 q¡5¨1¡9¸	ˆÑBð 	�‰Ôð 	�‰�Cœ$Ÿ)š) C›.Ñ(Ô)Ø�‰�DÔð 	�‰˜!ˆÑ#Ø÷+ 
��ús   ÁBC-Ã-
C;Úvalc                 ó„   • [         R                  " 5          U R                  U5      sS S S 5        $ ! , (       d  f       g = f©N)r:   r;   Úfill_©r2   r`   s     r=   Ú_no_grad_fill_re   ‚   s!   € Ü	�Š�Ø�|‰|˜CÓ ÷ 
��ús   –1±
?c                 ó‚   • [         R                  " 5          U R                  5       sS S S 5        $ ! , (       d  f       g = frb   )r:   r;   Úzero_©r2   s    r=   Ú_no_grad_zero_ri   ‡   s   € Ü	�Š�Ø�|‰|‹~÷ 
��úr?   ÚnonlinearityÚparamc                 óŒ  • / SQnX;   d  U S:X  a  gU S:X  a  gU S:X  a  [         R                  " S5      $ U S:X  av  Uc  S	nOQ[        U[        5      (       d  [        U[        5      (       d  [        U[
        5      (       a  UnO[        S
U S35      e[         R                  " SSUS-  -   -  5      $ U S:X  a   g[        SU  35      e)aŒ  Return the recommended gain value for the given nonlinearity function.

The values are as follows:

================= ====================================================
nonlinearity      gain
================= ====================================================
Linear / Identity :math:`1`
Conv{1,2,3}D      :math:`1`
Sigmoid           :math:`1`
Tanh              :math:`\frac{5}{3}`
ReLU              :math:`\sqrt{2}`
Leaky Relu        :math:`\sqrt{\frac{2}{1 + \text{negative\_slope}^2}}`
SELU              :math:`\frac{3}{4}`
================= ====================================================

.. warning::
    In order to implement `Self-Normalizing Neural Networks`_ ,
    you should use ``nonlinearity='linear'`` instead of ``nonlinearity='selu'``.
    This gives the initial weights a variance of ``1 / N``,
    which is necessary to induce a stable fixed point in the forward pass.
    In contrast, the default gain for ``SELU`` sacrifices the normalization
    effect for more stable gradient flow in rectangular layers.

Args:
    nonlinearity: the non-linear function (`nn.functional` name)
    param: optional parameter for the non-linear function

Examples:
    >>> gain = nn.init.calculate_gain(
    ...     "leaky_relu", 0.2
    ... )  # leaky_relu with negative_slope=0.2

.. _Self-Normalizing Neural Networks: https://papers.nips.cc/paper/2017/hash/5d44ee6f2c3f71b73125876103c8f6c4-Abstract.html
)r$   r%   r&   r'   r(   r)   r*   r+   rS   r,   g«ªªªªªú?r-   rI   r.   ç{®Gáz„?znegative_slope z not a valid numberrP   r/   g      è?zUnsupported nonlinearity )rJ   rL   Ú
isinstanceÚboolÚintrV   Ú
ValueError)rj   rk   Ú
linear_fnsÚnegative_slopes       r=   r   r   Œ   sÕ   € òL€Jð Ó! \°YÓ%>ØØ	˜Ó	ØØ	˜Ó	Ü�yŠy˜‹~ÐØ	˜Ó	%Ø‰=Ø!‰Nä˜5¤$×'Ñ'Ü˜5¤#×&Ñ&Ü˜%¤×'Ñ'ð #‰Nä˜¨u¨gÐ5HÐIÓJÐJÜ�yŠy˜  N°AÑ$5Ñ 5Ñ6Ó7Ð7Ø	˜Ó	àð	
ô Ð4°\°NÐCÓDÐDrO   c           	      ó¬   • [         R                  R                  U 5      (       a%  [         R                  R                  [        U 4XX#S9$ [        XX#5      $ )aƒ  Fill the input Tensor with values drawn from the uniform distribution.

:math:`\mathcal{U}(a, b)`.

Args:
    tensor: an n-dimensional `torch.Tensor`
    a: the lower bound of the uniform distribution
    b: the upper bound of the uniform distribution
    generator: the torch Generator to sample from (default: None)

Examples:
    >>> w = torch.empty(3, 5)
    >>> nn.init.uniform_(w)
r<   )r:   Ú	overridesÚhas_torch_function_variadicÚhandle_torch_functionr	   r>   r<   s       r=   r	   r	   Ö   sO   € ô( ‡�×2Ñ2°6×:Ñ:Ü�‰×4Ñ4Ü�v�i¨°qð 5ð 
ð 	
ô ˜V¨Ó5Ð5rO   c           	      ó¬   • [         R                  R                  U 5      (       a%  [         R                  R                  [        U 4XX#S9$ [        XX#5      $ )a™  Fill the input Tensor with values drawn from the normal distribution.

:math:`\mathcal{N}(\text{mean}, \text{std}^2)`.

Args:
    tensor: an n-dimensional `torch.Tensor`
    mean: the mean of the normal distribution
    std: the standard deviation of the normal distribution
    generator: the torch Generator to sample from (default: None)

Examples:
    >>> w = torch.empty(3, 5)
    >>> nn.init.normal_(w)
rC   )r:   ru   rv   rw   r
   rD   rC   s       r=   r
   r
   ñ   sO   € ô( ‡�×2Ñ2°6×:Ñ:Ü�‰×4Ñ4Ü�f�Y v¸cð 5ð 
ð 	
ô ˜F¨#Ó9Ð9rO   c           	      ó   • [        XX#XES9$ )aÕ  Fill the input Tensor with values drawn from a truncated normal distribution.

The values are effectively drawn from the
normal distribution :math:`\mathcal{N}(\text{mean}, \text{std}^2)`
with values outside :math:`[a, b]` redrawn until they are within
the bounds. The method used for generating the random values works
best when :math:`a \leq \text{mean} \leq b`.

Args:
    tensor: an n-dimensional `torch.Tensor`
    mean: the mean of the normal distribution
    std: the standard deviation of the normal distribution
    a: the minimum cutoff value
    b: the maximum cutoff value
    generator: the torch Generator to sample from (default: None)

Examples:
    >>> w = torch.empty(3, 5)
    >>> nn.init.trunc_normal_(w)
r9   )r_   )r2   r@   rA   r3   r4   r5   s         r=   r   r     s   € ô8 " &°¸ÑOÐOrO   c                 ó¨   • [         R                  R                  U 5      (       a$  [         R                  R                  [        U 4XS9$ [        X5      $ )zâFill the input Tensor with the value :math:`\text{val}`.

Args:
    tensor: an n-dimensional `torch.Tensor`
    val: the value to fill the tensor with

Examples:
    >>> w = torch.empty(3, 5)
    >>> nn.init.constant_(w, 0.3)
rd   )r:   ru   rv   rw   r   re   rd   s     r=   r   r   +  sK   € ô ‡�×2Ñ2°6×:Ñ:Ü�‰×4Ñ4Ü˜�y¨ð 5ð 
ð 	
ô ˜&Ó&Ð&rO   c                 ó   • [        U S5      $ )z¦Fill the input Tensor with the scalar value `1`.

Args:
    tensor: an n-dimensional `torch.Tensor`

Examples:
    >>> w = torch.empty(3, 5)
    >>> nn.init.ones_(w)
rH   )re   rh   s    r=   r   r   =  s   € ô ˜& #Ó&Ð&rO   c                 ó   • [        U 5      $ )z§Fill the input Tensor with the scalar value `0`.

Args:
    tensor: an n-dimensional `torch.Tensor`

Examples:
    >>> w = torch.empty(3, 5)
    >>> nn.init.zeros_(w)
)ri   rh   s    r=   r   r   J  s   € ô ˜&Ó!Ð!rO   c                 óø   • U R                  5       S:w  a  [        S5      e[        R                  " 5          [        R                  " U R
                  X R                  S.6  SSS5        U $ ! , (       d  f       U $ = f)a  Fill the 2-dimensional input `Tensor` with the identity matrix.

Preserves the identity of the inputs in `Linear` layers, where as
many inputs are preserved as possible.

Args:
    tensor: a 2-dimensional `torch.Tensor`

Examples:
    >>> w = torch.empty(3, 5)
    >>> nn.init.eye_(w)
rP   ú,Only tensors with 2 dimensions are supported)ÚoutÚrequires_gradN)Ú
ndimensionrq   r:   r;   r   Úshaper€   rh   s    r=   r   r   W  sY   € ð ×ÑÓ˜aÓÜÐGÓHÐHä	�Š�Ü�	Š	�6—<‘< V×;OÑ;OÓP÷ 
à€M÷ 
Œà€Mús   µ+A*Á*
A9Úgroupsc                 óÔ  • U R                  5       nUS;  a  [        S5      eU R                  5       nUS   U-  S:w  a  [        S5      eUS   U-  n[        XCS   5      n[        R
                  " 5          U R                  5         [        U5       Hº  n[        U5       H¨  nUS:X  a   SXU-  U-   XpR                  S5      S-  4'   M)  US:X  a4  SU Xd-  U-   UU R                  S5      S-  U R                  S5      S-  4'   Mc  SU Xd-  U-   UU R                  S5      S-  U R                  S5      S-  U R                  S5      S-  4'   Mª     M¼     S	S	S	5        U $ ! , (       d  f       U $ = f)
a  Fill the {3, 4, 5}-dimensional input `Tensor` with the Dirac delta function.

Preserves the identity of the inputs in `Convolutional`
layers, where as many input channels are preserved as possible. In case
of groups>1, each group of channels preserves identity

Args:
    tensor: a {3, 4, 5}-dimensional `torch.Tensor`
    groups (int, optional): number of groups in the conv layer (default: 1)
Examples:
    >>> w = torch.empty(3, 16, 5, 5)
    >>> nn.init.dirac_(w)
    >>> w = torch.empty(3, 24, 5, 5)
    >>> nn.init.dirac_(w, 3)
)é   é   é   z5Only tensors with 3, 4, or 5 dimensions are supportedr   z!dim 0 must be divisible by groupsrS   r…   rP   r†   N)r�   rq   ÚsizerT   r:   r;   rg   Úrange)r2   rƒ   Ú
dimensionsÚsizesÚout_chans_per_grpÚmin_dimÚgÚds           r=   r   r   l  s|  € ð  ×"Ñ"Ó$€JØ˜Ó"ÜÐPÓQÐQà�K‰K‹M€EàˆQ�x�&Ñ˜AÓÜÐ<Ó=Ð=à˜a™ FÑ*ÐÜÐ#¨1¡XÓ.€Gä	�Š�Ø�‰Œä�v–ˆAÜ˜7–^�Ø “?ØPQ�FÐ0Ñ0°1Ñ4°a¿¹ÀQ»È1Ñ9LÐLÓMØ 1“_ð ð ØÑ-°Ñ1ØØŸ™ A›¨!Ñ+ØŸ™ A›¨!Ñ+ð-óð ð ØÑ-°Ñ1ØØŸ™ A›¨!Ñ+ØŸ™ A›¨!Ñ+ØŸ™ A›¨!Ñ+ð	-óó $ñ ÷ 
ð, €M÷- 
Œð, €Mús   Á4CEÅ
E'c                 óþ   • U R                  5       nUS:  a  [        S5      eU R                  S5      nU R                  S5      nSnU R                  5       S:”  a  U R                  SS   H  nXE-  nM	     X$-  nX4-  nXg4$ )NrP   zNFan in and fan out can not be computed for tensor with fewer than 2 dimensionsrS   r   )Údimrq   rˆ   r‚   )r2   rŠ   Únum_input_fmapsÚnum_output_fmapsÚreceptive_field_sizeÚsr0   r1   s           r=   Ú_calculate_fan_in_and_fan_outr–   ¡  s�   € Ø—‘“€JØ�Aƒ~ÜØ\ó
ð 	
ð —k‘k !“n€OØ—{‘{ 1“~ÐØÐØ‡z�zƒ|�aÓð —‘˜a˜bÓ!ˆAØ Ñ%Ò ñ "àÑ3€FØÑ5€Gàˆ?ÐrO   Úgainc                 ó¶   • [        U 5      u  p4U[        R                  " S[        X4-   5      -  5      -  n[        R                  " S5      U-  n[	        X* Xb5      $ )a°  Fill the input `Tensor` with values using a Xavier uniform distribution.

The method is described in `Understanding the difficulty of training
deep feedforward neural networks` - Glorot, X. & Bengio, Y. (2010).
The resulting tensor will have values sampled from
:math:`\mathcal{U}(-a, a)` where

.. math::
    a = \text{gain} \times \sqrt{\frac{6}{\text{fan\_in} + \text{fan\_out}}}

Also known as Glorot initialization.

Args:
    tensor: an n-dimensional `torch.Tensor`
    gain: an optional scaling factor
    generator: the torch Generator to sample from (default: None)

Examples:
    >>> w = torch.empty(3, 5)
    >>> nn.init.xavier_uniform_(w, gain=nn.init.calculate_gain("relu"))
rI   ç      @)r–   rJ   rL   rV   r>   )r2   r—   r5   r0   r1   rA   r3   s          r=   r   r   ¶  sQ   € ô4 4°FÓ;�O€FØ
”—’˜3¤ vÑ'7Ó!8Ñ8Ó9Ñ
9€CÜ�	Š	�#‹˜Ñ€Aä˜V R¨Ó6Ð6rO   c                 ó„   • [        U 5      u  p4U[        R                  " S[        X4-   5      -  5      -  n[	        U SXR5      $ )aœ  Fill the input `Tensor` with values using a Xavier normal distribution.

The method is described in `Understanding the difficulty of training deep feedforward
neural networks` - Glorot, X. & Bengio, Y. (2010). The resulting tensor
will have values sampled from :math:`\mathcal{N}(0, \text{std}^2)` where

.. math::
    \text{std} = \text{gain} \times \sqrt{\frac{2}{\text{fan\_in} + \text{fan\_out}}}

Also known as Glorot initialization.

Args:
    tensor: an n-dimensional `torch.Tensor`
    gain: an optional scaling factor
    generator: the torch Generator to sample from (default: None)

Examples:
    >>> w = torch.empty(3, 5)
    >>> nn.init.xavier_normal_(w)
rI   ç        )r–   rJ   rL   rV   rD   )r2   r—   r5   r0   r1   rA   s         r=   r   r   ×  s?   € ô2 4°FÓ;�O€FØ
”—’˜3¤ vÑ'7Ó!8Ñ8Ó9Ñ
9€Cä˜F C¨Ó8Ð8rO   Úmodec                 ó„   • UR                  5       nSS/nX;  a  [        SU SU 35      e[        U 5      u  p4US:X  a  U$ U$ )Nr0   r1   zMode z" not supported, please use one of )Úlowerrq   r–   )r2   rœ   Úvalid_modesr0   r1   s        r=   Ú_calculate_correct_fanr    ö  sT   € à�:‰:‹<€DØ˜YÐ'€KØÓÜ˜5  Ð&HÈÈÐVÓWÐWä3°FÓ;�O€FØ˜XÓ%ˆ6Ð2¨7Ð2rO   c           
      óú  • [         R                  R                  U 5      (       a(  [         R                  R                  [        U 4U UUUUS9$ SU R
                  ;   a  [        R                  " SSS9  U $ [        X5      n[        X15      nU[        R                  " U5      -  n[        R                  " S5      U-  n[         R                  " 5          U R                  U* X„S9sSSS5        $ ! , (       d  f       g= f)	aD  Fill the input `Tensor` with values using a Kaiming uniform distribution.

The method is described in `Delving deep into rectifiers: Surpassing
human-level performance on ImageNet classification` - He, K. et al. (2015).
The resulting tensor will have values sampled from
:math:`\mathcal{U}(-\text{bound}, \text{bound})` where

.. math::
    \text{bound} = \text{gain} \times \sqrt{\frac{3}{\text{fan\_mode}}}

Also known as He initialization.

Args:
    tensor: an n-dimensional `torch.Tensor`
    a: the negative slope of the rectifier used after this layer (only
        used with ``'leaky_relu'``)
    mode: either ``'fan_in'`` (default) or ``'fan_out'``. Choosing ``'fan_in'``
        preserves the magnitude of the variance of the weights in the
        forward pass. Choosing ``'fan_out'`` preserves the magnitudes in the
        backwards pass.
    nonlinearity: the non-linear function (`nn.functional` name),
        recommended to use only with ``'relu'`` or ``'leaky_relu'`` (default).
    generator: the torch Generator to sample from (default: None)

Examples:
    >>> w = torch.empty(3, 5)
    >>> nn.init.kaiming_uniform_(w, mode="fan_in", nonlinearity="relu")

Note:
    Be aware that ``fan_in`` and ``fan_out`` are calculated assuming
    that the weight matrix is used in a transposed manner,
    (i.e., ``x @ w.T`` in ``Linear`` layers, where ``w.shape = [fan_out, fan_in]``).
    This is important for correct initialization.
    If you plan to use ``x @ w``, where ``w.shape = [fan_in, fan_out]``,
    pass in a transposed weight matrix, i.e. ``nn.init.kaiming_uniform_(w.T, ...)``.
)r2   r3   rœ   rj   r5   r   ú,Initializing zero-element tensors is a no-oprP   rQ   r™   r9   N)r:   ru   rv   rw   r   r‚   rW   rX   r    r   rJ   rL   r;   r	   )	r2   r3   rœ   rj   r5   Úfanr—   rA   Úbounds	            r=   r   r     sÍ   € ôV ‡�×2Ñ2°6×:Ñ:Ü�‰×4Ñ4ÜØˆIØØØØ%Øð 5ð 
ð 	
ð 	ˆF�L‰LÓÜ�ŠÐDÐQRÒSØˆÜ
  Ó
.€CÜ˜,Ó*€DØ
”—’˜3“Ñ
€CÜ�IŠI�c‹N˜SÑ €EÜ	�Š�Ø�‰ ˜v uˆÐB÷ 
��ús   ÃC,Ã,
C:c                 ó.  • SU R                   ;   a  [        R                  " SSS9  U $ [        X5      n[	        X15      nU[
        R                  " U5      -  n[        R                  " 5          U R                  SXtS9sSSS5        $ ! , (       d  f       g= f)a+  Fill the input `Tensor` with values using a Kaiming normal distribution.

The method is described in `Delving deep into rectifiers: Surpassing
human-level performance on ImageNet classification` - He, K. et al. (2015).
The resulting tensor will have values sampled from
:math:`\mathcal{N}(0, \text{std}^2)` where

.. math::
    \text{std} = \frac{\text{gain}}{\sqrt{\text{fan\_mode}}}

Also known as He initialization.

Args:
    tensor: an n-dimensional `torch.Tensor`
    a: the negative slope of the rectifier used after this layer (only
        used with ``'leaky_relu'``)
    mode: either ``'fan_in'`` (default) or ``'fan_out'``. Choosing ``'fan_in'``
        preserves the magnitude of the variance of the weights in the
        forward pass. Choosing ``'fan_out'`` preserves the magnitudes in the
        backwards pass.
    nonlinearity: the non-linear function (`nn.functional` name),
        recommended to use only with ``'relu'`` or ``'leaky_relu'`` (default).
    generator: the torch Generator to sample from (default: None)

Examples:
    >>> w = torch.empty(3, 5)
    >>> nn.init.kaiming_normal_(w, mode="fan_out", nonlinearity="relu")

Note:
    Be aware that ``fan_in`` and ``fan_out`` are calculated assuming
    that the weight matrix is used in a transposed manner,
    (i.e., ``x @ w.T`` in ``Linear`` layers, where ``w.shape = [fan_out, fan_in]``).
    This is important for correct initialization.
    If you plan to use ``x @ w``, where ``w.shape = [fan_in, fan_out]``,
    pass in a transposed weight matrix, i.e. ``nn.init.kaiming_normal_(w.T, ...)``.
r   r¢   rP   rQ   r9   N)
r‚   rW   rX   r    r   rJ   rL   r:   r;   r
   )r2   r3   rœ   rj   r5   r£   r—   rA   s           r=   r   r   B  so   € ðV 	ˆF�L‰LÓÜ�ŠÐDÐQRÒSØˆÜ
  Ó
.€CÜ˜,Ó*€DØ
”—’˜3“Ñ
€CÜ	�Š�Ø�~‰~˜a ˆ~Ð:÷ 
��ús   Á,BÂ
Bc                 ó¨  • U R                  5       S:  a  [        S5      eU R                  5       S:X  a  U $ U R                  S5      nU R                  5       U-  nU R	                  X445      R                  SSUS9nX4:  a  UR                  5         [        R                  R                  U5      u  pg[        R                  " US5      nUR                  5       n	Xi-  nX4:  a  UR                  5         [        R                  " 5          U R                  U5      R                  U5        U R                  U5        SSS5        U $ ! , (       d  f       U $ = f)al  Fill the input `Tensor` with a (semi) orthogonal matrix.

Described in `Exact solutions to the nonlinear dynamics of learning in deep
linear neural networks` - Saxe, A. et al. (2013). The input tensor must have
at least 2 dimensions, and for tensors with more than 2 dimensions the
trailing dimensions are flattened.

Args:
    tensor: an n-dimensional `torch.Tensor`, where :math:`n \geq 2`
    gain: optional scaling factor
    generator: the torch Generator to sample from (default: None)

Examples:
    >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_LAPACK)
    >>> w = torch.empty(3, 5)
    >>> nn.init.orthogonal_(w)
rP   z4Only tensors with 2 or more dimensions are supportedr   rS   r9   N)r�   rq   Únumelrˆ   Ú	new_emptyr
   Út_r:   ÚlinalgÚqrÚdiagÚsignr;   Úview_asÚcopy_rZ   )
r2   r—   r5   ÚrowsÚcolsÚ	flattenedÚqÚrr�   Úphs
             r=   r   r   w  s  € ð, ×ÑÓ˜QÓÜÐOÓPÐPà‡|�|ƒ~˜ÓàˆØ�;‰;�q‹>€DØ�<‰<‹>˜TÑ!€DØ× Ñ  $ Ó.×6Ñ6°q¸!ÀyÐ6ÐQ€Iàƒ{Ø�‰Œô �<‰<�?‰?˜9Ó%�D€Aä�
Š
�1�aÓ€AØ	
�‰‹€BØ�G€Aàƒ{Ø	�‰Œä	�Š�Ø�‰�qÓ×Ñ Ô"Ø�‰�DÔ÷ 
ð €M÷ 
Œð €Mús   Ä2EÅ
EÚsparsityc                 óv  • U R                  5       S:w  a  [        S5      eU R                  u  pE[        R                  " X-  5      n[
        R                  " 5          U R                  SX#S9  [        U5       H$  n[
        R                  " U5      nUSU n	SX	U4'   M&     SSS5        U $ ! , (       d  f       U $ = f)aZ  Fill the 2D input `Tensor` as a sparse matrix.

The non-zero elements will be drawn from the normal distribution
:math:`\mathcal{N}(0, 0.01)`, as described in `Deep learning via
Hessian-free optimization` - Martens, J. (2010).

Args:
    tensor: an n-dimensional `torch.Tensor`
    sparsity: The fraction of elements in each column to be set to zero
    std: the standard deviation of the normal distribution used to generate
        the non-zero values
    generator: the torch Generator to sample from (default: None)

Examples:
    >>> w = torch.empty(3, 5)
    >>> nn.init.sparse_(w, sparsity=0.1)
rP   r~   r   r9   N)
r�   rq   r‚   rJ   Úceilr:   r;   r
   r‰   Úrandperm)
r2   r¶   rA   r5   r°   r±   Ú	num_zerosÚcol_idxÚrow_indicesÚzero_indicess
             r=   r   r   ª  s¥   € ð. ×ÑÓ˜aÓÜÐGÓHÐHà—‘�J€DÜ—	’	˜(™/Ó*€Iä	�Š�Ø�‰�q˜#ˆÑ3Ü˜T–{ˆGÜŸ.š.¨Ó.ˆKØ& z¨	Ð2ˆLØ,-ˆF Ð(Ó)ñ #÷ 
ð €M÷ 
Œð €Mús   ÁAB)Â)
B8Úmethc                 ó¾   ^ ^^• T R                   mTS S mS[        R                  S[        R                  S[        4U UU4S jjnST ST ST S	3Ul        TUl         U$ )
NéÿÿÿÿÚargsÚkwargsr6   c                  óV   >• [         R                  " ST ST S3[        SS9  T" U 0 UD6$ )Nz	`nn.init.z)` is now deprecated in favor of `nn.init.z`.rP   rQ   )rW   rX   ÚFutureWarning)rÁ   rÂ   r¾   Únew_nameÚold_names     €€€r=   Údeprecated_initÚ(_make_deprecate.<locals>.deprecated_initÕ  s;   ø€ Ü�ŠØ˜�zÐ!JÈ8È*ÐTVÐWÜØò	
ñ
 �TÐ$˜VÑ$Ð$rO   z
    z_(...)

    .. warning::
        This method is now deprecated in favor of :func:`torch.nn.init.z"`.

    See :func:`~torch.nn.init.z` for details.)Ú__name__r#   rÁ   rÂ   r"   Ú__doc__)r¾   rÇ   rÅ   rÆ   s   ` @@r=   Ú_make_deprecaterË   Ñ  s~   ú€ Ø�}‰}€HØ˜˜ˆ}€Hð%œrŸw™wð %´"·)±)ð %Ä÷ %ñ %ð$Ø€Jð Hð IQÀzð Rà'˜j¨ð:€OÔð  (€OÔØÐrO   rb   )r›   rH   N)r›   rH   g       ÀrI   N)rS   )rH   N)r   r0   r.   N)rS   N)rm   N)7rÊ   rJ   rW   Úcollections.abcr   Útypingr   r   Útyping_extensionsr   r:   r   Ú__all__r"   r#   Ú_NonlinearityTypeÚ_FanModerV   Ú	Generatorr>   rD   r_   re   ri   rp   r   r	   r
   r   r   r   r   r   r   Útupler–   r   r   r    r   r   r   r   rË   r   r   r   r   r   r   r   r   r   r    r!   © rO   r=   Ú<module>rÕ      sb  ðÙ Nã Û Ý $ß #Ý 'ã Ý ò€ñ> ˆTƒ]€Ùˆtƒ_€àðñÐ ð Ð&Ñ'€ð MQñ:Øð:Øð:Ø!&ð:Ø38·?±?ÀTÑ3Ið:àõ:ð )-ñ	>Øð>à
ð>ð 
ð>ð �‰ Ñ%ð	>ð
 õ>ð  )-ñ)Øð)à
ð)ð 
ð)ð ð	)ð
 ð)ð �‰ Ñ%ð)ð õ)ðX!˜6ð !¨ð !°&ô !ð
˜6ð  fô ð BFñGEØ#ðGEØ,/°%©K¸$Ñ,>ðGEà
õGEðX ØØ(,ñ	6Øð6àð6ð ð6ð �‰ Ñ%ð	6ð
 õ6ð: ØØ(,ñ	:Øð:à
ð:ð 
ð:ð �‰ Ñ%ð	:ð
 õ:ð: ØØØØ(,ñPØðPà
ðPð 
ðPð ð	Pð
 ðPð �‰ Ñ%ðPð õPð>'�fð ' 5ð '¨Vô 'ð$
'�&ð 
'˜Vô 
'ð
"�6ð 
"˜fô 
"ð�ð ˜Fô ñ*2�6ð 2 3ð 2¨võ 2ðj¨&ð °U¸3À¸8±_ô ð. Ø(,ñ7Øð7à
ð7ð �‰ Ñ%ð7ð õ	7ðF Ø(,ñ9Øð9à
ð9ð �‰ Ñ%ð9ð õ	9ð>3 6ð 3°ð 3¸cô 3ð ØØ&2Ø(,ñ>CØð>Càð>Cð ð>Cð $ð	>Cð
 �‰ Ñ%ð>Cð õ>CðF ØØ&2Ø(,ñ2;Øð2;àð2;ð ð2;ð $ð	2;ð
 �‰ Ñ%ð2;ð õ2;ðn Ø(,ñ0Øð0à
ð0ð �‰ Ñ%ð0ð õ	0ðl Ø(,ñ	#Øð#àð#ð 
ð#ð �‰ Ñ%ð	#ð
 õ#ðN˜( 2 r 6Ñ*ð ¨x¸¸B¸Ñ/?ô ñ. ˜(Ó
#€Ù	˜Ó	!€Ù˜9Ó%€Ù�dÓ€Ù˜Ó€Ù  Ó1€Ù Ó/€Ù!Ð"2Ó3€Ù  Ó1€Ù˜[Ó)€
Ù	˜Ó	!�rO   