Rate this Page

Function torch::stable::to(const torch::stable::Tensor&, std::optional<torch::headeronly::ScalarType>, std::optional<torch::headeronly::Layout>, std::optional<torch::stable::Device>, std::optional<bool>, bool, bool, std::optional<torch::headeronly::MemoryFormat>)#

Function Documentation#

inline torch::stable::Tensor torch::stable::to(const torch::stable::Tensor &self, std::optional<torch::headeronly::ScalarType> dtype = std::nullopt, std::optional<torch::headeronly::Layout> layout = std::nullopt, std::optional<torch::stable::Device> device = std::nullopt, std::optional<bool> pin_memory = std::nullopt, bool non_blocking = false, bool copy = false, std::optional<torch::headeronly::MemoryFormat> memory_format = std::nullopt)#

Stable version of the to.dtype_layout op.

Converts a tensor to the specified dtype, layout, device, and/or memory format. Returns a new tensor with the specified properties.

Minimum compatible version: PyTorch 2.10.

Parameters:
  • self – The input tensor.

  • dtype – Optional target scalar type.

  • layout – Optional target memory layout.

  • device – Optional target device.

  • pin_memory – Optional flag to use pinned memory.

  • non_blocking – If true, the operation may be asynchronous. Defaults to false.

  • copy – If true, always create a copy. Defaults to false.

  • memory_format – Optional target memory format.

Returns:

A tensor with the specified properties.