@@ -46,6 +46,19 @@ def parse_kwargs(desc):
4646 returned tensor. Default: ``False``.
4747""" )
4848
49+ factory_data_common_args = parse_kwargs ("""
50+ data (array_like): Initial data for the tensor. Can be a list, tuple,
51+ NumPy ``ndarray``, scalar, and other types.
52+ dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
53+ Default: if None, infers data type from :attr:`data`.
54+ device (:class:`torch.device`, optional): the desired device of returned tensor.
55+ Default: if None, uses the current device for the default tensor type
56+ (see :func:`torch.set_default_tensor_type`). :attr:`device` will be the CPU
57+ for CPU tensor types and the current CUDA device for CUDA tensor types.
58+ requires_grad (bool, optional): If autograd should record operations on the
59+ returned tensor. Default: ``False``.
60+ """ )
61+
4962add_docstr (torch .abs ,
5063 r"""
5164abs(input, out=None) -> Tensor
@@ -388,6 +401,35 @@ def parse_kwargs(desc):
388401 [ 3., 6.]])
389402""" )
390403
404+ add_docstr (torch .as_tensor ,
405+ r"""
406+ as_tensor(data, dtype=None, device=None) -> Tensor
407+
408+ Convert the data into a `torch.Tensor`. If the data is already a `Tensor` of the same `dtype` and `device`, no copy
409+ will be performed. Similarly, if the data is an ``ndarray`` of the corresponding `dtype` and the `device` is the cpu,
410+ no copy will be performed.
411+
412+ Args:
413+ {data}
414+ {dtype}
415+ {device}
416+
417+ Example::
418+
419+ >>> torch.tensor([[0.1, 1.2], [2.2, 3.1], [4.9, 5.2]])
420+ tensor([[ 0.1000, 1.2000],
421+ [ 2.2000, 3.1000],
422+ [ 4.9000, 5.2000]])
423+
424+ >>> a = numpy.array([1, 2, 3])
425+ >>> t = torch.from_numpy(a)
426+ >>> t
427+ tensor([ 1, 2, 3])
428+ >>> t[0] = -1
429+ >>> a
430+ array([-1, 2, 3])
431+ """ .format (** factory_data_common_args ))
432+
391433add_docstr (torch .asin ,
392434 r"""
393435asin(input, out=None) -> Tensor
@@ -3514,16 +3556,10 @@ def parse_kwargs(desc):
35143556 :func:`torch.from_numpy`.
35153557
35163558Args:
3517- data (array_like): Initial data for the tensor. Can be a list, tuple,
3518- NumPy ``ndarray``, scalar, and other types.
3519- dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
3520- Default: if None, infers data type from :attr:`data`.
3521- device (:class:`torch.device`, optional): the desired device of returned tensor.
3522- Default: if None, uses the current device for the default tensor type
3523- (see :func:`torch.set_default_tensor_type`). :attr:`device` will be the CPU
3524- for CPU tensor types and the current CUDA device for CUDA tensor types.
3525- requires_grad (bool, optional): If autograd should record operations on the
3526- returned tensor. Default: ``False``.
3559+ {data}
3560+ {dtype}
3561+ {device}
3562+ {requires_grad}
35273563
35283564
35293565Example::
@@ -3546,7 +3582,7 @@ def parse_kwargs(desc):
35463582
35473583 >>> torch.tensor([]) # Create an empty tensor (of size (0,))
35483584 tensor([])
3549- """ )
3585+ """ . format ( ** factory_data_common_args ) )
35503586
35513587add_docstr (torch .range ,
35523588 r"""
0 commit comments