�
J��g� � �4 � d dl Z d dlmZ G d� d� � ZdS )� N)�Optionalc �� � e Zd ZdZdZdZdd�Z dded ee j
d
ee j de j
fd�Z dd
ed ee j
d
ee j de 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�R FNc � � || j k s|dk rt 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 � dd� � | _ 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 �a/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/torch/quasirandom.py�__init__zSobolEngine.__init__1 s/ � ��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 � |�t j � � }| j dk r�|dk r| j � |� � }n�t j | j |dz
| j | j | j |�� � \ }| _ t j | j � |� � |fd�� � }n9t j | j || j | j | j dz
|�� � \ }| _ | 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``
Nr r )r �����)�dim)r �get_default_dtyper"