[docs] Update set_default_(tensor_|d)type docs (#6843)
* update set_default_(tensor_|d)type docs
* make ndarray display nicer
diff --git a/torch/__init__.py b/torch/__init__.py
index 3bab31f..5fac95a 100644
--- a/torch/__init__.py
+++ b/torch/__init__.py
@@ -129,18 +129,22 @@
def set_default_tensor_type(t):
- r"""Sets the default ``torch.Tensor`` type to type :attr:`t`.
+ r"""Sets the default ``torch.Tensor`` type to floating point tensor type
+ :attr:`t`. This type will also be used as default floating point type for
+ type inference in :func:`torch.tensor`.
- The default tensor type is initially ``"torch.FloatTensor"``.
+ The default tensor type is initially ``torch.FloatTensor``
Args:
- t (type or string): the tensor type or its name
+ t (type or string): the floating point tensor type or its name
Example::
- >>> torch.set_default_tensor_type("torch.FloatTensor")
- >>> torch.tensor([1.2, 3])
- tensor([ 1.2000, 3.0000])
+ >>> torch.tensor([1.2, 3]).dtype # default is float32
+ torch.float32
+ >>> torch.set_default_tensor_type(torch.DoubleTensor)
+ >>> torch.tensor([1.2, 3]).dtype # floating point tensor
+ torch.float64
"""
if isinstance(t, _string_classes):
@@ -149,16 +153,20 @@
def set_default_dtype(d):
- r"""Sets the default ``torch.dtype`` type to type :attr:`d`.
+ r"""Sets the default floating point dtype to :attr:`d`. This type will be
+ used as default floating point type for type inference in
+ :func:`torch.tensor`.
Args:
- d (torch.dtype): the dtype to make the default
+ d (:class:`torch.dtype`): the floating point dtype to make the default
Example::
+ >>> torch.tensor([1.2, 3]).dtype # default is float32
+ torch.float32
>>> torch.set_default_dtype(torch.double)
- >>> torch.tensor([1.2, 3], device='cpu')
- tensor([ 1.2000, 3.0000])
+ >>> torch.tensor([1.2, 3]).dtype
+ torch.float64
"""
_C._set_default_dtype(d)
diff --git a/torch/_torch_docs.py b/torch/_torch_docs.py
index 4e84350..a9def09 100644
--- a/torch/_torch_docs.py
+++ b/torch/_torch_docs.py
@@ -1465,9 +1465,9 @@
Creates a :class:`Tensor` from a :class:`numpy.ndarray`.
-The returned tensor and `ndarray` share the same memory. Modifications to the
-tensor will be reflected in the `ndarray` and vice versa. The returned tensor
-is not resizable.
+The returned tensor and :attr:`ndarray` share the same memory. Modifications to
+the tensor will be reflected in the :attr:`ndarray` and vice versa. The returned
+tensor is not resizable.
Example::
@@ -3476,12 +3476,12 @@
:func:`torch.tensor` always copies :attr:`data`. If you have a Tensor
``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
or :func:`torch.Tensor.detach`.
- If you have a numpy array and want to avoid a copy, use
+ If you have a NumPy ``ndarray`` and want to avoid a copy, use
:func:`torch.from_numpy`.
Args:
data (array_like): Initial data for the tensor. Can be a list, tuple,
- numpy array, scalar, and other types.
+ NumPy ``ndarray``, scalar, and other types.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if None, infers data type from :attr:`data`.
device (:class:`torch.device`, optional): the desired device of returned tensor.