docs/cpp/source/api/aten/tensor.md
The at::Tensor class is the primary tensor class in ATen, representing
a multi-dimensional array with a specific data type and device.
The primary tensor class in ATen. Represents a multi-dimensional array
with a specific data type and device.
Default constructor. Creates an undefined tensor.
Returns the number of dimensions of the tensor.
Returns the size of the tensor at the given dimension.
Returns the sizes of all dimensions.
Returns the strides of all dimensions.
Returns the data type of the tensor.
Returns the device where the tensor is stored.
Returns true if the tensor is on a CUDA device.
Returns true if the tensor is on CPU.
Returns true if gradients need to be computed for this tensor.
Sets whether gradients should be computed for this tensor.
Returns a tensor on the specified device.
Returns a tensor with the specified data type.
Returns a contiguous tensor with the same data.
Returns a pointer to the underlying data.
Example:
#include <ATen/ATen.h>
at::Tensor a = at::ones({2, 2}, at::kInt);
at::Tensor b = at::randn({2, 2});
auto c = a + b.to(at::kInt);
A class to specify options for tensor creation, including dtype, device,
layout, and requires_grad.
Default constructor.
Returns options with the specified data type.
Returns options with the specified device.
Returns options with the specified layout.
Returns options with the specified requires_grad setting.
Example:
auto options = at::TensorOptions()
.dtype(at::kFloat)
.device(at::kCUDA, 0)
.requires_grad(true);
at::Tensor tensor = at::zeros({3, 4}, options);
Represents a scalar value that can be converted to various numeric types.
Construct from an integer.
Construct from a double.
Convert to the specified type.
Returns true if the scalar is an integral type.
Returns true if the scalar is a floating point type.
Enumeration of data types supported by tensors.
8-bit unsigned integer (uint8_t)
8-bit signed integer (int8_t)
16-bit signed integer (int16_t)
32-bit signed integer (int32_t)
64-bit signed integer (int64_t)
16-bit floating point (float16)
32-bit floating point (float)
64-bit floating point (double)
Boolean type
Brain floating point (bfloat16)
Convenience constants:
at::kByte, at::kChar, at::kShort, at::kInt, at::kLongat::kHalf, at::kFloat, at::kDouble, at::kBFloat16at::kBool:members:
:undoc-members:
Example:
{
c10::DeviceGuard guard(at::Device(at::kCUDA, 1));
// Operations here run on CUDA device 1
auto tensor = at::zeros({2, 2});
}
// Previous device is restored
Enumeration of tensor memory layouts.
Dense tensor with strides.
Sparse tensor (COO format).
Sparse tensor in CSR format.
Sparse tensor in CSC format.