o
    h/                     @   sN  d Z ddlZddlZddlZddlZddlmZmZm	Z	 ddl
Z
e
je
je
je
je
je
je
je
jgZe
je
je
je
jgZe
je
je
je
jgZe
je
je
j gZ!e
j"geZ#g ee!Z$de
j%de&de&de
j%fdd	Z'ddd
d
d
ddde	e(e
j)e*e( e+e(df f de
j,de	e-e
j.f dee& dee& de"de"de"dee
j/ de
j%fddZ0dS )z1
This module contains tensor creation utilities.
    N)castOptionalUniontlowhighreturnc                 C   s<   || t | jjkr| |d |d dS | ||S )N   )torchfinfodtypemaxuniform_mul_)r   r   r    r   k/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/torch/testing/_creation.py_uniform_random_$   s   r   F)r   r   requires_gradnoncontiguousexclude_zeromemory_formatshape.r   devicer   r   r   r   c                    s  dt t dt t dtdtdtdtdtttf f fdd	}	t|d
kr0t|d tjjr0|d }ttt	df t|}|rK|durKt
d|d||rX tv rXt
d |odtdd |d
d
k}|r}ttt	df g |dd d|d  R } tju rttt	t	f |	||ddddd\}}tj|||| d}
n tv rttt	t	f |	||t jt j tjurd
nd ddd\}}tj|||| d}
ng tv r|	||t jt jddd\}}tj|| d}
t tv rt|
n|
|| n6 tv r2|	||t jt jddd\}}tj||tjd}
t|
|| |
 }
ntd  d|rG|
dd
ddf }
n|durR|
j|d}
|rf tv r\d
nt j |
|
dk<  tv rn||
_!|
S )as  Creates 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')
    r   r   lowest_inclusivehighest_exclusivedefault_lowdefault_highr   c                   s  dt dt dt dt fdd}| dur| n|} |dur|n|}tdd	 | |fD r2td
| d|| |krC tv rCtjdtdd n*| |krQtd|  d| ||k sY| |krmtd|  d| d  d| d| d|| ||} ||||} tv rt	| t	|fS | |fS )z
        Modifies (and raises ValueError when appropriate) low and high values given by the user (input_low, input_high)
        if required.
        alhr   c                 S   s   t t| ||S N)minr   )r   r   r   r   r   r   clamp   s   z3make_tensor.<locals>.modify_low_high.<locals>.clampNc                 s   s$    | ]}t |tot|V  qd S r    )
isinstancefloatmathisnan).0valuer   r   r   	<genexpr>   s   " z7make_tensor.<locals>.modify_low_high.<locals>.<genexpr>z,`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_TYPESwarningswarnFutureWarning_BOOLEAN_OR_INTEGRAL_TYPESr%   ceil)r   r   r   r   r   r   r"   r   r   r   modify_low_high   s<   z$make_tensor.<locals>.modify_low_high   r   .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                 S   s   | | S r    r   )xyr   r   r   <lambda>   s    zmake_tensor.<locals>.<lambda>r	   )r   r   r   r   )r   r   i
   	   zThe 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   )"r   r$   tuplelenr#   collectionsabcSequencer   intr.   r3   	functoolsreducer
   boolrandintiinfor!   r   int64r/   r   emptyr   _COMPLEX_TYPESview_as_real_FLOATING_8BIT_TYPESfloat32to	TypeErrorclonetinyr   )r   r   r   r   r   r   r   r   r   r6   resultr   r5   r   make_tensor-   s   R
3,
















rT   )1__doc__collections.abcr@   rD   r%   r0   typingr   r   r   r
   uint8int8int16int32rI   uint16uint32uint64_INTEGRAL_TYPESfloat16bfloat16rN   float64_FLOATING_TYPESfloat8_e4m3fnfloat8_e5m2float8_e4m3fnuzfloat8_e5m2fnuzrM   	complex32	complex64
complex128rK   rF   r3   r/   Tensorr$   r   rC   Sizelistr>   r   strr   r   rT   r   r   r   r   <module>   sj    
	
