a
    8Sic##                     @   s   d Z ddlZddlmZmZmZmZmZ ddlZddl	Z
ejejejejejejiZdd e D Zddddddeeejee eedf f ejeeejf ee ee eeeejd		d
dZdS )z1
This module contains tensor creation utilities.
    N)OptionalListTupleUnioncastc                 C   s   i | ]\}}||qS  r   ).0kvr   r   S/var/www/html/django/DPS/env/lib/python3.9/site-packages/torch/testing/_creation.py
<dictcomp>       r   F)lowhighrequires_gradnoncontiguousexclude_zero.)	shapedtypedevicer   r   r   r   r   returnc              
   G   sr  dd }t |dkr.t|d tjjr.|d }tttdf t|}t	j
t	jt	jt	jt	jg}	t	jt	jt	jt	jg}
t	jt	jt	jg}|r| |
vr| |vrtd| t	ju rt	jdd||| d}n| t	j
u r(t	| jt	| jf}ttttf ||||d |d dd	| \}}t	j||||| d}nr| |	v rt	| jt	| jf}||||d |d d
d	| \}}t	j||||| d}n| |
v rt	| jt	| jf}||||d |d d
d| \}}t	j||| d}|| |d|   }n| |v rt|  }t	|jt	|jf}||||d |d d
d| \}}t	j|||d}t	j|||d}|| |d|   }|| |d|   }t	||}nt d|  d|r|! dkrt	j"|ddd}|ddddf }|rZ| |	v s| t	ju rt	j#d|| d}nP| |
v r"t	j#t	| j$|| d}n,t|  }t	j#t	|j$||d}t	||}|||dk< | |
| v rn||_%|S )a  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``.
        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.
        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``.

    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``.
        TypeError: If :attr:`dtype` isn't supported by this function.

    Examples:
        >>> 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)
        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')
    c                 S   s   dd }| dur| n|} |dur$|n|}| | ks8||kr@t d| |krPt d|| ||} ||||}|tjtjtjtjtjf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.
        c                 S   s   t t| ||S )N)minmax)alhr   r   r   clampX   s    z4make_tensor.<locals>._modify_low_high.<locals>.clampNz(make_tensor: one of low or high was NaN!z/make_tensor: low must be weakly less than high!)

ValueErrortorchuint8int8int16int32int64mathfloorceil)r   r   ZlowestZhighestZdefault_lowZdefault_highr   r   r   r   r   _modify_low_highT   s    z%make_tensor.<locals>._modify_low_high   r   .z;make_tensor: requires_grad must be False for integral dtype   )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)dimN)&len
isinstancecollectionsabcSequencer   r   inttupler   r   r    r!   r"   r#   float16bfloat16float32float64	complex32	complex64
complex128r   boolrandintiinfor   r   finforand'complex_to_corresponding_float_type_mapcomplex	TypeErrornumelrepeat_interleavetensortinyr   )r   r   r   r   r   r   r   r   r'   Z_integral_typesZ_floating_typesZ_complex_typesresultrangesZranges_floatsZrand_valZfloat_dtypeZreal_rand_valZimag_rand_valrealimagreplace_withZ	float_epsr   r   r   make_tensor   sb    D
.
 
 
 
rM   )__doc__r   typingr   r   r   r   r   r$   collections.abcr0   r9   r5   r:   r7   r;   r8   rA   itemsZ'float_to_corresponding_complex_type_mapr3   Sizer   strr   floatr<   TensorrM   r   r   r   r   <module>   s2   