o �J�h��@s&ddlmZddlZGdd�d�ZdS)�)�OptionalNc @s�eZdZdZdZdZddd�Z   dd ed ee j d ee j d e j fd d�Z  dded ee j d ee j d e j fdd�Z dd�Zdd�Zdd�Zdd�ZdS)� 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�RFNcCs�||jks |dkrtd|j�d���||_||_||_t�d�}tj||j|tj d�|_ t� |j |j�|jsCtj|j|tj d�|_ n|� �|j jtjd�|_|jd|j�dd�|_d |_dS) N�z9Supported range of dimensionality for SobolEngine is [1, �]�cpu)�device�dtype)� memory_format������r)�MAXDIM� ValueError�seed�scramble� dimension�torchr�zeros�MAXBIT�long� sobolstateZ_sobol_engine_initialize_state_�shift� _scramble�clone�contiguous_format�quasi�reshape� _first_point� num_generated)�selfrrrr�r �OC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\torch\quasirandom.py�__init__3s(��  � zSobolEngine.__init__r�n�outr �returncCs�|durt��}|jdkr:|dkr|j�|�}n6tj|j|d|j|j|j|d�\}|_tj |j�|�|fdd�}ntj|j||j|j|jd|d�\}|_|j|7_|durc|� |�� |�|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`` Nrr)r �����)�dim) r�get_default_dtyperr�toZ_sobol_engine_drawrrr�cat� resize_as_�copy_)rr#r$r �resultr r r!�drawNs6  � � zSobolEngine.draw�mc CsXd|}|j|}||d@dks$td|j�d|j�d|�d|�d� ��|j|||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 rrzFThe 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 )rrr.)rr/r$r r#Ztotal_nr r r!� draw_base2�s �����zSobolEngine.draw_base2cCs|j�|j�d|_|S)zF Function to reset the ``SobolEngine`` to base state. r)rr,rr)rr r r!�reset�szSobolEngine.resetcCsZ|jdkrt�|j|d|j|j|j�nt�|j||j|j|jd�|j|7_|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. rr)rrZ_sobol_engine_ff_rrr)rr#r r r!� fast_forward�s ��zSobolEngine.fast_forwardc Cs�d}|jdurt��}|�|j�t�d�}tjd|j|jf||d�}t�|t� dtj d|j|d���|_ |j|j|jf}tjd|||d�� �}t� |j||j�dS)Nrr )r� generatorr)r)rr� Generator� manual_seedr�randintrr�mv�pow�aranger�trilZ_sobol_engine_scramble_r)r�grZ shift_intsZltm_dimsZltmr r r!r�s   ��zSobolEngine._scramblecCsTd|j��g}|jr|dg7}|jdur|d|j��g7}|jjdd�|�dS)Nz dimension=z scramble=Truezseed=�(z, �))rrr� __class__�__name__�join)r� fmt_stringr r r!�__repr__�s   zSobolEngine.__repr__)FN)rNN)NN)r@� __module__� __qualname__�__doc__rr r"�intrr�Tensorr r.r1r2r3rrCr r r r!rs@( ���� �8���� � r)�typingrrrr r r r!�<module>s 
Memory