Rate this Page

Function torch::stable::from_blob(void *, torch::headeronly::IntHeaderOnlyArrayRef, torch::headeronly::IntHeaderOnlyArrayRef, torch::stable::Device, torch::headeronly::ScalarType, DeleterFnPtr, int64_t, torch::headeronly::Layout)#

Function Documentation#

inline torch::stable::Tensor torch::stable::from_blob(void *data, torch::headeronly::IntHeaderOnlyArrayRef sizes, torch::headeronly::IntHeaderOnlyArrayRef strides, torch::stable::Device device, torch::headeronly::ScalarType dtype, DeleterFnPtr deleter, int64_t storage_offset = 0, torch::headeronly::Layout layout = torch::headeronly::Layout::Strided)#

Creates a tensor from an existing data blob with a custom deleter.

This is the same as the from_blob function above, but allows specifying a custom deleter function that will be called when the tensor’s storage is deallocated. Minimum compatible version: PyTorch 2.11.

Parameters:
  • data – Pointer to the data buffer.

  • sizes – The size of each dimension of the tensor.

  • strides – The stride for each dimension.

  • device – The device where the data resides.

  • dtype – The scalar type of the data.

  • deleter – Function to call when the tensor is deallocated. May be nullptr if no cleanup is needed.

  • storage_offset – The offset into the data buffer. Defaults to 0.

  • layout – The memory layout. Defaults to Strided.

Returns:

A tensor backed by the provided data.