Template Function torch::stable::from_blob(void *, torch::headeronly::IntHeaderOnlyArrayRef, torch::headeronly::IntHeaderOnlyArrayRef, torch::stable::Device, torch::headeronly::ScalarType, F, int64_t, torch::headeronly::Layout)#
Defined in File ops.h
Function Documentation#
-
template<class F, std::enable_if_t<std::is_invocable_v<F, void*>, int> = 0>
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, F 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. Accepts both plain function pointers and capturing lambdas.
Minimum compatible version: PyTorch 2.11.
- Template Parameters:
F – The callable type. Must be invocable with (void*).
- 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 – Callable to invoke when the tensor is deallocated.
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.