Returns a new tensor with the same data as the self tensor but of a
different shape.
The returned tensor shares the same data and must have the same number
of elements, but may have a different size. For a tensor to be viewed, the new
view size must be compatible with its original size and stride, i.e., each new
view dimension must either be a subspace of an original dimension, or only span
across original dimensions that satisfy the following
contiguity-like condition that ,
d,d+1,…,d+k
∀i=d,…,d+k−1
stride[i]=stride[i+1]×size[i+1]
Otherwise, it will not be possible to view self tensor as shape
without copying it (e.g., via contiguous()). When it is unclear whether a
view() can be performed, it is advisable to use reshape(), which
returns a view if the shapes are compatible, and copies (equivalent to calling
contiguous()) otherwise.
Returns a new tensor with the same data as the self tensor but of a
different dtype.
If the element size of dtype is different than that of self.dtype,
then the size of the last dimension of the output will be scaled
proportionally. For instance, if dtype element size is twice that of
self.dtype, then each pair of elements in the last dimension of
self will be combined, and the size of the last dimension of the output
will be half that of self. If dtype element size is half that
of self.dtype, then each element in the last dimension of self will
be split in two, and the size of the last dimension of the output will be
double that of self. For this to be possible, the following conditions
must be true:
self.dim() must be greater than 0.
self.stride(-1) must be 1.
Additionally, if the element size of dtype is greater than that of
self.dtype, the following conditions must be true as well:
self.size(-1) must be divisible by the ratio between the element
sizes of the dtypes.
self.storage_offset() must be divisible by the ratio between the
element sizes of the dtypes.
The strides of all dimensions, except the last dimension, must be
divisible by the ratio between the element sizes of the dtypes.
If any of the above conditions are not met, an error is thrown.