Welcome to pytorch-types’s documentation!¶
Pytorch typing for pydantic.
-
class
pytorch_types.
Tensor
[source]¶ -
-
classmethod
device
(device) → pytorch_types.tensor.Tensor[source]¶ Is the
torch.device
where this Tensor is.
-
classmethod
cpu
(memory_format=torch.preserve_format) → Tensor[source]¶ Returns a copy of this object in CPU memory.
If this object is already in CPU memory and on the correct device, then no copy is performed and the original object is returned.
- Args:
- memory_format (
torch.memory_format
, optional): the desired memory format of returned Tensor. Default:
torch.preserve_format
.
- memory_format (
-
classmethod
cuda
(device=None, non_blocking=False, memory_format=torch.preserve_format) → Tensor[source]¶ Returns a copy of this object in CUDA memory.
If this object is already in CUDA memory and on the correct device, then no copy is performed and the original object is returned.
- Args:
- device (
torch.device
): The destination GPU device. Defaults to the current CUDA device.
- non_blocking (bool): If
True
and the source is in pinned memory, the copy will be asynchronous with respect to the host. Otherwise, the argument has no effect. Default:
False
.- memory_format (
torch.memory_format
, optional): the desired memory format of returned Tensor. Default:
torch.preserve_format
.
- device (
-
classmethod
float
(memory_format=torch.preserve_format) → Tensor[source]¶ self.float()
is equivalent toself.to(torch.float32)
. Seeto()
.- Args:
- memory_format (
torch.memory_format
, optional): the desired memory format of returned Tensor. Default:
torch.preserve_format
.
- memory_format (
-
classmethod
half
(memory_format=torch.preserve_format) → Tensor[source]¶ self.half()
is equivalent toself.to(torch.float16)
. Seeto()
.- Args:
- memory_format (
torch.memory_format
, optional): the desired memory format of returned Tensor. Default:
torch.preserve_format
.
- memory_format (
-
classmethod
double
(memory_format=torch.preserve_format) → Tensor[source]¶ self.double()
is equivalent toself.to(torch.float64)
. Seeto()
.- Args:
- memory_format (
torch.memory_format
, optional): the desired memory format of returned Tensor. Default:
torch.preserve_format
.
- memory_format (
-
classmethod
int
(memory_format=torch.preserve_format) → Tensor[source]¶ self.int()
is equivalent toself.to(torch.int32)
. Seeto()
.- Args:
- memory_format (
torch.memory_format
, optional): the desired memory format of returned Tensor. Default:
torch.preserve_format
.
- memory_format (
-
classmethod
long
(memory_format=torch.preserve_format) → Tensor[source]¶ self.long()
is equivalent toself.to(torch.int64)
. Seeto()
.- Args:
- memory_format (
torch.memory_format
, optional): the desired memory format of returned Tensor. Default:
torch.preserve_format
.
- memory_format (
-
classmethod
short
(memory_format=torch.preserve_format) → Tensor[source]¶ self.short()
is equivalent toself.to(torch.int16)
. Seeto()
.- Args:
- memory_format (
torch.memory_format
, optional): the desired memory format of returned Tensor. Default:
torch.preserve_format
.
- memory_format (
-
classmethod
-
class
pytorch_types.
Numpy
[source]¶ -
-
classmethod
ndim
(ndim) → pytorch_types.numpy.Numpy[source]¶ Number of array dimensions.
>>> x = np.array([1, 2, 3]) >>> x.ndim 1 >>> y = np.zeros((2, 3, 4)) >>> y.ndim 3
-
classmethod
shape
(*sizes) → pytorch_types.numpy.Numpy[source]¶ Tuple of array dimensions.
The shape property is usually used to get the current shape of an array, but may also be used to reshape the array in-place by assigning a tuple of array dimensions to it. As with numpy.reshape, one of the new shape dimensions can be -1, in which case its value is inferred from the size of the array and the remaining dimensions. Reshaping an array in-place will fail if a copy is required.
>>> x = np.array([1, 2, 3, 4]) >>> x.shape (4,) >>> y = np.zeros((2, 3, 4)) >>> y.shape (2, 3, 4) >>> y.shape = (3, 8) >>> y array([[ 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0.]]) >>> y.shape = (3, 6) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: total size of new array must be unchanged >>> np.zeros((4,2))[::2].shape = (-1,) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: Incompatible shape for in-place modification. Use `.reshape()` to make a copy with the desired shape.
numpy.reshape : similar function ndarray.reshape : similar method
-
classmethod