L i/>dZddlZddlZddlZddlZddlmZmZm Z ddl Z e je je je je je j e j"e j$gZe j(e j*e j,e j.gZe j2e j4e j6e j8gZe j<e j>e j@gZ!e jDgeZ#gee!Z$de jJde&de&de jJfdZ'ddd d d dd d e e(e jRe*e(e+e(d ffd e jXde e-e j\fdee&dee&de"de"de"dee j^de jJfdZ0y)z1 This module contains tensor creation utilities. N)castOptionalUniontlowhighreturnc||z tj|jjk\r'|j |dz |dz j dS|j ||S)N)torchfinfodtypemaxuniform_mul_)rrrs ]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/testing/_creation.py_uniform_random_r$sX czU[[)---zz#'4!8,11!44zz#t$$F)rr requires_grad noncontiguous exclude_zero memory_formatshape.rdevicerrrrcrdttdttdtdtdtdtdtttfffd } t|d k(r,t |d t j jr|d }tttd ft|}|r|td |d||rtvrtd|xrtjd|d d kD}|r'tttd fg|d dd|dz}tjurHttttf| ||d dd d\}}tj ||||} nމtvrttttf| ||tj"j$tj"j&tj(urd nd zdd\}}tj ||||} n=t*vr| ||tj,j$tj,j&dd\}}tj.||} t1t2vrtj4| n| ||nt6vr| ||tj,j$tj,j&dd\}}tj.||tj8} t1| ||| j;} nt=dd|r | d d d df} n|| j?|} |r/tvrd ntj,j@| | d k(<t*vr|| _!| S)asCreates a tensor with the given :attr:`shape`, :attr:`device`, and :attr:`dtype`, and filled with values uniformly drawn from ``[low, high)``. If :attr:`low` or :attr:`high` are specified and are outside the range of the :attr:`dtype`'s representable finite values then they are clamped to the lowest or highest representable finite value, respectively. If ``None``, then the following table describes the default values for :attr:`low` and :attr:`high`, which depend on :attr:`dtype`. +---------------------------+------------+----------+ | ``dtype`` | ``low`` | ``high`` | +===========================+============+==========+ | boolean type | ``0`` | ``2`` | +---------------------------+------------+----------+ | unsigned integral type | ``0`` | ``10`` | +---------------------------+------------+----------+ | signed integral types | ``-9`` | ``10`` | +---------------------------+------------+----------+ | floating types | ``-9`` | ``9`` | +---------------------------+------------+----------+ | complex types | ``-9`` | ``9`` | +---------------------------+------------+----------+ Args: shape (Tuple[int, ...]): Single integer or a sequence of integers defining the shape of the output tensor. dtype (:class:`torch.dtype`): The data type of the returned tensor. device (Union[str, torch.device]): The device of the returned tensor. low (Optional[Number]): Sets the lower limit (inclusive) of the given range. If a number is provided it is clamped to the least representable finite value of the given dtype. When ``None`` (default), this value is determined based on the :attr:`dtype` (see the table above). Default: ``None``. high (Optional[Number]): Sets the upper limit (exclusive) of the given range. If a number is provided it is clamped to the greatest representable finite value of the given dtype. When ``None`` (default) this value is determined based on the :attr:`dtype` (see the table above). Default: ``None``. .. deprecated:: 2.1 Passing ``low==high`` to :func:`~torch.testing.make_tensor` for floating or complex types is deprecated since 2.1 and will be removed in 2.3. Use :func:`torch.full` instead. requires_grad (Optional[bool]): If autograd should record operations on the returned tensor. Default: ``False``. noncontiguous (Optional[bool]): If `True`, the returned tensor will be noncontiguous. This argument is ignored if the constructed tensor has fewer than two elements. Mutually exclusive with ``memory_format``. exclude_zero (Optional[bool]): If ``True`` then zeros are replaced with the dtype's small positive value depending on the :attr:`dtype`. For bool and integer types zero is replaced with one. For floating point types it is replaced with the dtype's smallest positive normal number (the "tiny" value of the :attr:`dtype`'s :func:`~torch.finfo` object), and for complex types it is replaced with a complex number whose real and imaginary parts are both the smallest positive normal number representable by the complex type. Default ``False``. memory_format (Optional[torch.memory_format]): The memory format of the returned tensor. Mutually exclusive with ``noncontiguous``. Raises: ValueError: If ``requires_grad=True`` is passed for integral `dtype` ValueError: If ``low >= high``. ValueError: If either :attr:`low` or :attr:`high` is ``nan``. ValueError: If both :attr:`noncontiguous` and :attr:`memory_format` are passed. TypeError: If :attr:`dtype` isn't supported by this function. Examples: >>> # xdoctest: +SKIP >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA) >>> from torch.testing import make_tensor >>> # Creates a float tensor with values in [-1, 1) >>> make_tensor((3,), device="cpu", dtype=torch.float32, low=-1, high=1) >>> # xdoctest: +SKIP tensor([ 0.1205, 0.2282, -0.6380]) >>> # Creates a bool tensor on CUDA >>> make_tensor((2, 2), device="cuda", dtype=torch.bool) tensor([[False, False], [False, True]], device='cuda:0') rrlowest_inclusivehighest_exclusive default_low default_highr c dtdtdtdtfd}||n|}||n|}td||fDrtd|d|||k(r%tvrt j d t d n;||k\rtd |d |||ks||k\rtd|d|dd|d|d ||||}||||}tvr*tj|tj|fS||fS)z Modifies (and raises ValueError when appropriate) low and high values given by the user (input_low, input_high) if required. alhr c.tt|||SN)minr)r!r"r#s rclampz3make_tensor..modify_low_high..clampss1ay!$ $rc3jK|]+}t|txrtj|-ywr%) isinstancefloatmathisnan).0values r z7make_tensor..modify_low_high..s(W%z%'=DJJu,==Ws13z,`low` and `high` cannot be NaN, but got low=z and high=zPassing `low==high` to `torch.testing.make_tensor` for floating or complex types is deprecated since 2.1 and will be removed in 2.3. Use `torch.full(...)` instead.) stacklevelz(`low` must be less than `high`, but got z >= z5The value interval specified by `low` and `high` is [z, z), but z only supports [)) r*any ValueError_FLOATING_OR_COMPLEX_TYPESwarningswarn FutureWarning_BOOLEAN_OR_INTEGRAL_TYPESr+ceil)rrrrrrr'rs rmodify_low_highz$make_tensor..modify_low_highs] %U %u % %5 %_c+'t\ WCQU;W W?3& dWM D[U&@@ MM1  D[GuDQUPVWX X $ $/@(@GuBtfUg-.>-?rBSATTUW  C)+<=T+->? . .99S>499T?2 2Dyrr.NzaThe parameters `noncontiguous` and `memory_format` are mutually exclusive, but got noncontiguous=z and memory_format=zU`requires_grad=True` is not supported for boolean and integral dtypes, but got dtype=c ||zSr%)xys rzmake_tensor..s AErr )rrrr)rri zThe requested dtype 'z' is not supported by torch.testing.make_tensor(). To request support, file an issue at: https://github.com/pytorch/pytorch/issues)r)"rr*tuplelenr) collectionsabcSequencerintr4r9 functoolsreducer boolrandintiinfor&rint64r5r emptyr_COMPLEX_TYPES view_as_real_FLOATING_8BIT_TYPESfloat32to TypeErrorclonetinyr) rrrrrrrrrr;results ` r make_tensorr[-sd1 e_1uo1 1 ! 1  11 ue| 1f 5zQ:eAh 0H0HIa sCx%, /E2&$&&:M+; =  "<<d^c]e f  "Xi&6&67I5RS&TWX&XMU38_&Bcr &BAb M&BC   #s(O !""#    TsD%eL , , #s(O !&U!3!7!7"'++e"4"8"8U[[01a #9  T"sD%eL , ,#  "[[/33#kk%044  TU6?*/>*AE  v &vsTX  & &#  "[[/33#kk%044  TU6Gd+5!#E7+_ _  QTT "  "M:44A%++e:L:Q:Q v{ **, Mr)1__doc__collections.abcrGrKr+r6typingrrrr uint8int8int16int32rPuint16uint32uint64_INTEGRAL_TYPESfloat16bfloat16rUfloat64_FLOATING_TYPES float8_e4m3fn float8_e5m2float8_e4m3fnuzfloat8_e5m2fnuzrT complex32 complex64 complex128rRrMr9r5Tensorr*rrJSizelistrErstrrrr[r>rrrvs ((  KK JJ KK KK KK LL LL LL ==%..%--O      //5??E4D4DE#jj;?;@@@% %5%%%,,%  37g #uzz49eCHo= >g ;;g #u||# $g % g 5/ g  gggE//0g \\gr