§
    ŠŠtjá  ã                   ó(   — d dl Z  G d„ d¦  «        ZdS )é    Nc            	       óÌ   — e Zd ZdZdZdZdd„Z	 	 	 dded	ej	        dz  d
ej
        dz  dej	        fd„Z	 	 dded	ej	        dz  d
ej
        dz  dej	        fd„Zd„ Zd„ Zd„ Zd„ ZdS )ÚSobolEnginea  
    The :class:`torch.quasirandom.SobolEngine` is an engine for generating
    (scrambled) Sobol sequences. Sobol sequences are an example of low
    discrepancy quasi-random sequences.

    This implementation of an engine for Sobol sequences is capable of
    sampling sequences up to a maximum dimension of 21201. It uses direction
    numbers from https://web.maths.unsw.edu.au/~fkuo/sobol/ obtained using the
    search criterion D(6) up to the dimension 21201. This is the recommended
    choice by the authors.

    References:
      - Art B. Owen. Scrambling Sobol and Niederreiter-Xing points.
        Journal of Complexity, 14(4):466-489, December 1998.

      - I. M. Sobol. The distribution of points in a cube and the accurate
        evaluation of integrals.
        Zh. Vychisl. Mat. i Mat. Phys., 7:784-802, 1967.

    Args:
        dimension (Int): The dimensionality of the sequence to be drawn
        scramble (bool, optional): Setting this to ``True`` will produce
                                   scrambled Sobol sequences. Scrambling is
                                   capable of producing better Sobol
                                   sequences. Default: ``False``.
        seed (Int, optional): This is the seed for the scrambling. The seed
                              of the random number generator is set to this,
                              if specified. Otherwise, it uses a random seed.
                              Default: ``None``

    Examples::

        >>> # xdoctest: +SKIP("unseeded random state")
        >>> soboleng = torch.quasirandom.SobolEngine(dimension=5)
        >>> soboleng.draw(3)
        tensor([[0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
                [0.5000, 0.5000, 0.5000, 0.5000, 0.5000],
                [0.7500, 0.2500, 0.2500, 0.2500, 0.7500]])
    é   iÑR  FNc                 ó†  — || j         k    s|dk     rt          d| j         › d�¦  «        ‚|| _        || _        || _        t          j        d¦  «        }t          j        || j        |t
          j	        ¬¦  «        | _
        t          j        | j
        | j        ¦  «         | j        s,t          j        | j        |t
          j	        ¬¦  «        | _        n|                      ¦   «          | j                             t
          j        ¬¦  «        | _        | j        d| j        z  z                       dd¦  «        | _        d	| _        d S )
Né   z9Supported range of dimensionality for SobolEngine is [1, ú]Úcpu)ÚdeviceÚdtype)Úmemory_formaté   éÿÿÿÿr   )ÚMAXDIMÚ
ValueErrorÚseedÚscrambleÚ	dimensionÚtorchr
   ÚzerosÚMAXBITÚlongÚ
sobolstateÚ_sobol_engine_initialize_state_ÚshiftÚ	_scrambleÚcloneÚcontiguous_formatÚquasiÚreshapeÚ_first_pointÚnum_generated)Úselfr   r   r   r	   s        úO/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/quasirandom.pyÚ__init__zSobolEngine.__init__2   s.  € Ø�t”{Ò"Ð" i°!¢m mÝð9Ø*.¬+ð9ð 9ð 9ñô ð ð
 ˆŒ	Ø ˆŒØ"ˆŒåŒl˜5Ñ!Ô!ˆåœ+Ø�t”{¨3µe´jð
ñ 
ô 
ˆŒõ 	Ô-¨d¬o¸t¼~ÑNÔNÐNàŒ}ð 	Ýœ T¤^¸CÅuÄzÐRÑRÔRˆDŒJˆJà�NŠNÑÔÐà”Z×%Ò%µEÔ4KÐ%ÑLÔLˆŒ
Ø!œZ¨!¨T¬[©.Ñ8×AÒAÀ!ÀRÑHÔHˆÔØˆÔÐÐó    r   ÚnÚoutr   Úreturnc                 óF  — |€t          j        ¦   «         }| j        dk    r‹|dk    r| j                             |¦  «        }n£t          j        | j        |dz
  | j        | j        | j        |¬¦  «        \  }| _        t          j	        | j                             |¦  «        |fd¬¦  «        }n9t          j        | j        || j        | j        | j        dz
  |¬¦  «        \  }| _        | xj        |z  c_        |�*| 
                    |¦  «                             |¦  «         |S |S )ak  
        Function to draw a sequence of :attr:`n` points from a Sobol sequence.
        Note that the samples are dependent on the previous samples. The size
        of the result is :math:`(n, dimension)`.

        Args:
            n (Int, optional): The length of sequence of points to draw.
                               Default: 1
            out (Tensor, optional): The output tensor
            dtype (:class:`torch.dtype`, optional): the desired data type of the
                                                    returned tensor.
                                                    Default: ``None``
        Nr   r   )r   éþÿÿÿ)Údim)r   Úget_default_dtyper!   r    ÚtoÚ_sobol_engine_drawr   r   r   ÚcatÚ
resize_as_Úcopy_)r"   r&   r'   r   Úresults        r#   ÚdrawzSobolEngine.drawM   s4  € ð& ˆ=ÝÔ+Ñ-Ô-ˆEàÔ Ò"Ð"Ø�AŠvˆvØÔ*×-Ò-¨eÑ4Ô4��å%*Ô%=Ø”JØ˜‘EØ”OØ”NØÔ&Øð&ñ &ô &Ñ"�˜œ
õ œ DÔ$5×$8Ò$8¸Ñ$?Ô$?ÀÐ#HÈbÐQÑQÔQ��å!&Ô!9Ø”
ØØ”Ø”ØÔ" QÑ&Øð"ñ "ô "ÑˆF�D”Jð 	ÐÔ˜aÑÐÔàˆ?Ø�NŠN˜6Ñ"Ô"×(Ò(¨Ñ0Ô0Ð0ØˆJàˆr%   Úmc                 ó´   — d|z  }| j         |z   }||dz
  z  dk    s&t          d| j         › d| j         › d|› d|› d�	¦  «        ‚|                      |||¬	¦  «        S )
aI  
        Function to draw a sequence of :attr:`2**m` points from a Sobol sequence.
        Note that the samples are dependent on the previous samples. The size
        of the result is :math:`(2**m, dimension)`.

        Args:
            m (Int): The (base2) exponent of the number of points to draw.
            out (Tensor, optional): The output tensor
            dtype (:class:`torch.dtype`, optional): the desired data type of the
                                                    returned tensor.
                                                    Default: ``None``
        r   r   r   zFThe balance properties of Sobol' points require n to be a power of 2. z0 points have been previously generated, then: n=z+2**ú=zH. If you still want to do this, please use 'SobolEngine.draw()' instead.)r&   r'   r   )r!   r   r3   )r"   r4   r'   r   r&   Útotal_ns         r#   Ú
draw_base2zSobolEngine.draw_base2‚   sž   € ð$ ˆq‰DˆØÔ$ qÑ(ˆØ˜7 Q™;Ñ'¨1Ò,Ð,Ýð0Ø)-Ô);ð0ð 0à15Ô1Cð0ð 0àIJð0ð 0àMTð0ð 0ð 0ñô ð ð �yŠy˜1 #¨UˆyÑ3Ô3Ð3r%   c                 óR   — | j                              | j        ¦  «         d| _        | S )zF
        Function to reset the ``SobolEngine`` to base state.
        r   )r   r1   r   r!   )r"   s    r#   ÚresetzSobolEngine.reset    s)   € ð 	Œ
×Ò˜œÑ$Ô$Ð$ØˆÔØˆr%   c                 óú   — | j         dk    r0t          j        | j        |dz
  | j        | j        | j         ¦  «         n/t          j        | j        || j        | j        | j         dz
  ¦  «         | xj         |z  c_         | S )a  
        Function to fast-forward the state of the ``SobolEngine`` by
        :attr:`n` steps. This is equivalent to drawing :attr:`n` samples
        without using the samples.

        Args:
            n (Int): The number of steps to fast-forward by.
        r   r   )r!   r   Ú_sobol_engine_ff_r   r   r   )r"   r&   s     r#   Úfast_forwardzSobolEngine.fast_forward¨   s�   € ð Ô Ò"Ð"ÝÔ#Ø”
˜A ™E 4¤?°D´NÀDÔDVñô ð ð õ Ô#Ø”
˜A˜tœ°´ÀÔ@RÐUVÑ@Vñô ð ð 	ÐÔ˜aÑÐÔØˆr%   c                 ó,  — d }| j         �-t          j        ¦   «         }|                     | j         ¦  «         t          j        d¦  «        }t          j        d| j        | j        f||¬¦  «        }t          j        |t          j	        dt          j
        d| j        |¬¦  «        ¦  «        ¦  «        | _        | j        | j        | j        f}t          j        d|||¬¦  «                             ¦   «         }t          j        | j        || j        ¦  «         d S )Nr	   r   )r
   Ú	generatorr   )r
   )r   r   Ú	GeneratorÚmanual_seedr
   Úrandintr   r   ÚmvÚpowÚaranger   ÚtrilÚ_sobol_engine_scramble_r   )r"   Úgr	   Ú
shift_intsÚltm_dimsÚltms         r#   r   zSobolEngine._scramble¼   sù   € Ø$(ˆØŒ9Ð Ý”Ñ!Ô!ˆAØ�MŠM˜$œ)Ñ$Ô$Ð$åŒl˜5Ñ!Ô!ˆõ ”]Ø�” ¤Ð,°SÀAð
ñ 
ô 
ˆ
õ ”XØ�œ	 !¥U¤\°!°T´[ÈÐ%MÑ%MÔ%MÑNÔNñ
ô 
ˆŒ
ð
 ”N D¤K°´Ð=ˆÝŒm˜A˜x°¸qÐAÑAÔA×FÒFÑHÔHˆåÔ% d¤o°s¸D¼NÑKÔKÐKÐKÐKr%   c                 ó¬   — d| j         › �g}| j        r|dgz  }| j        �|d| j        › �gz  }| j        j        dz   d                     |¦  «        z   dz   S )Nz
dimension=zscramble=Truezseed=ú(z, ú))r   r   r   Ú	__class__Ú__name__Újoin)r"   Ú
fmt_strings     r#   Ú__repr__zSobolEngine.__repr__Ò   sq   € Ø3 4¤>Ð3Ð3Ð4ˆ
ØŒ=ð 	,Ø˜?Ð+Ñ+ˆJØŒ9Ð ØÐ. 4¤9Ð.Ð.Ð/Ñ/ˆJØŒ~Ô&¨Ñ,¨t¯yªy¸Ñ/DÔ/DÑDÀsÑJÐJr%   )FN)r   NN)NN)rP   Ú
__module__Ú__qualname__Ú__doc__r   r   r$   Úintr   ÚTensorr   r3   r8   r:   r=   r   rS   © r%   r#   r   r      s5  € € € € € ð&ð &ðP €FØ€Fðð ð ð ð: Ø#'Ø$(ð	3ð 3àð3ð Œ\˜DÑ ð3ð Œ{˜TÑ!ð	3ð
 
Œð3ð 3ð 3ð 3ðp $(Ø$(ð	4ð 4àð4ð Œ\˜DÑ ð4ð Œ{˜TÑ!ð	4ð
 
Œð4ð 4ð 4ð 4ð<ð ð ðð ð ð(Lð Lð Lð,Kð Kð Kð Kð Kr%   r   )r   r   rY   r%   r#   ú<module>rZ      sV   ðð €€€ðRKð RKð RKð RKð RKñ RKô RKð RKð RKð RKr%   