� J��g���4�ddlZddlmZGd�d��ZdS)�N)�Optionalc ���eZdZdZdZdZdd�Z dded ee j d ee j d e j fd �Z dd ed ee j d ee j d e j fd�Z d�Zd�Zd�Zd�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�RFNc��||jks|dkrtd|j�d����||_||_||_t jd��}t j||j|t j ���|_ t j |j |j��|js,t j|j|t j ���|_ n|� ��|j �t j���|_|jd|jzz �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� sobolstate�_sobol_engine_initialize_state_�shift� _scramble�clone�contiguous_format�quasi�reshape� _first_point� num_generated)�selfrrrr s �a/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/torch/quasirandom.py�__init__zSobolEngine.__init__1s/�� �t�{� "� "�i�!�m�m��F�7;�{�F�F�F�G�G� G��� � �� �"����l�5�!�!���+�i���S�PU�PZ�[�[�[��� �-�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�{�*:�:�C�C�A�r�J�J��������r�n�outr �returnc�F�|�tj��}|jdkr�|dkr|j�|��}n�tj|j|dz |j|j|j|���\}|_tj |j�|��|fd���}n9tj|j||j|j|jdz |���\}|_|xj|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`` Nrr)r �����)�dim) r�get_default_dtyper"r!�to�_sobol_engine_drawrrr�cat� resize_as_�copy_)r#r'r(r �results r$�drawzSobolEngine.drawHs-�� �=��+�-�-�E� � �� "� "��A�v�v��*�-�-�e�4�4���%*�%=��J��A��t�����HZ�bg�&�&�&�"��� ���D�$5�$8�$8��$?�$?��#H�b�Q�Q�Q���!&�!9�� �A�t�����@R�UV�@V�^c�"�"�"� �F�D�J� ���a���� �?� �N�N�6� "� "� (� (�� 0� 0� 0��J�� r&�mc ��d|z}|j|z}||dz zdks&td|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`` rrrzFThe 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"rr4)r#r5r(r r'�total_ns r$� draw_base2zSobolEngine.draw_base2os��� ��F���$�q�(���7�Q�;�'�1�,�,��=�6:�6H�=�=�>B�>P�=�=�VW�=�=�Za�=�=�=��� � �y�y�1�#�U�y�3�3�3r&c�R�|j�|j��d|_|S)zF Function to reset the ``SobolEngine`` to base state. r)rr2rr")r#s r$�resetzSobolEngine.reset�s)�� � �����$�$�$����� r&c���|jdkr0tj|j|dz |j|j|j��n/tj|j||j|j|jdz ��|xj|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. rr)r"r�_sobol_engine_ff_rrr)r#r's r$� fast_forwardzSobolEngine.fast_forward�s~�� � �� "� "� � #�D�J��A��t����X\�Xj� k� k� k� k� � #�D�J��4�?�D�N�TX�Tf�ij�Tj� k� k� k� ���a����� r&c �,�d}|j�-tj��}|�|j��tjd��}tjd|j|jf||���}tj|tj dtj d|j|�������|_ |j|j|jf}tjd|||���� ��}tj |j||j��dS)Nr r)r � generatorr)r )rr� Generator� manual_seedr �randintrr�mv�pow�aranger�tril�_sobol_engine_scramble_r)r#�gr � shift_ints�ltm_dims�ltms r$rzSobolEngine._scramble�s���'+�� �9� ���!�!�A� �M�M�$�)� $� $� $��l�5�!�!���]�1�t�~�t�{�&C�C�[\�]�]�]� ��X�j�%�)�A�u�|�A�t�{�[^�7_�7_�7_�*`�*`�a�a�� ��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}|jr|dgz }|j�|d|j��gz }|jjdzd�|��zdzS)Nz dimension=z scramble=Truezseed=�(z, �))rrr� __class__�__name__�join)r#� fmt_strings r$�__repr__zSobolEngine.__repr__�sq��3�4�>�3�3�4� � �=� ,� �?�+� +�J� �9� � �.�4�9�.�.�/� /�J��~�&��,�t�y�y��/D�/D�D�s�J�Jr&)FN)rNN)NN)rQ� __module__� __qualname__�__doc__rrr%�intrr�Tensorr r4r9r;r>rrT�r&r$rrs%������&�&�N�F� �F�����.>B�,0�%�%�c�%�H�U�\�$:�%��U�[�)�%�5:�\�%�%�%�%�N@D�26�4�4�C�4�h�u�|�&<�4�"�5�;�/�4�;@�<�4�4�4�4�2������ L�L�L�$K�K�K�K�Kr&r)r�typingrrrZr&r$�<module>r\sf�� � � � �������rK�rK�rK�rK�rK�rK�rK�rK�rK�rKr&
Memory