Back to Pytorch

Stable Operators

docs/cpp/source/api/stable/operators.md

2.12.03.6 KB
Original Source

Stable Operators

The stable API provides tensor operations that maintain binary compatibility across PyTorch versions.

Tensor Class

{doxygenclass}
:members:
:undoc-members:

Example:

cpp
torch::stable::Tensor tensor = torch::stable::empty({3, 4}, ...);
float* data = tensor.data_ptr<float>();
auto shape = tensor.sizes();

Device Class

{doxygenclass}
:members:
:undoc-members:

Example:

cpp
torch::stable::Device cpu_device(torch::headeronly::DeviceType::CPU);
torch::stable::Device cuda_device(torch::headeronly::DeviceType::CUDA, 0);

Tensor Creation

{doxygenfunction}
{doxygenfunction}
{doxygenfunction}
{doxygenfunction}
{doxygenfunction}
{doxygenfunction}

Example:

cpp
auto tensor = torch::stable::empty(
    {3, 4},
    torch::headeronly::ScalarType::Float,
    torch::headeronly::Layout::Strided,
    torch::stable::Device(torch::headeronly::DeviceType::CUDA, 0),
    false,
    torch::headeronly::MemoryFormat::Contiguous);

Tensor Manipulation

{doxygenfunction}
{doxygenfunction}
{doxygenfunction}
{doxygenfunction}
{doxygenfunction}
{doxygenfunction}
{doxygenfunction}
{doxygenfunction}
{doxygenfunction}
{doxygenfunction}
{doxygenfunction}

Device and Type Conversion

{doxygenfunction}
{doxygenfunction}

In-place Operations

{doxygenfunction}
{doxygenfunction}
{doxygenfunction}

Mathematical Operations

{doxygenfunction}
{doxygenfunction}
{doxygenfunction}
{doxygenfunction}
{doxygenfunction}
{doxygenfunction}