mod tensor¶
- module tensor¶
DLPack tensor helpers for creating, freeing, and validating tensors.
This module provides the bridge between rgpot’s C API and the DLPack tensor exchange format. Two categories of tensors are supported:
Borrowed (non-owning): wraps an existing raw pointer. The deleter frees only the
DLManagedTensorVersionedmetadata, not the data.Owned: wraps a Vec<T>. The deleter frees both metadata and data.
All exported
extern "C"functions are collected by cbindgen intorgpot.h.Functions
- unsafe extern C fn rgpot_tensor_cpu_f64_2d(data: *mut f64, rows: i64, cols: i64) -> *mut DLManagedTensorVersioned¶
Create a non-owning 2-D f64 tensor on CPU wrapping an existing buffer.
The returned tensor borrows
data— the caller must keepdataalive for the lifetime of the tensor. Callrgpot_tensor_freewhen done.Safety
datamust point to at leastrows * colscontiguousf64values.
- unsafe extern C fn rgpot_tensor_cpu_f64_matrix3(data: *mut f64) -> *mut DLManagedTensorVersioned¶
Create a non-owning 2-D f64 tensor on CPU for a 3x3 matrix.
Convenience wrapper — equivalent to
rgpot_tensor_cpu_f64_2d(data, 3, 3).Safety
datamust point to at least 9 contiguousf64values.
- unsafe extern C fn rgpot_tensor_cpu_i32_1d(data: *mut c_int, len: i64) -> *mut DLManagedTensorVersioned¶
Create a non-owning 1-D i32 tensor on CPU wrapping an existing buffer.
Safety
datamust point to at leastlencontiguousc_intvalues.
- unsafe extern C fn rgpot_tensor_data(tensor: *const DLManagedTensorVersioned) -> *const c_void¶
Get the raw data pointer of a DLPack tensor.
Safety
tensormust be a valid, non-nullDLManagedTensorVersioned*.
- unsafe extern C fn rgpot_tensor_device(tensor: *const DLManagedTensorVersioned) -> DLDevice¶
Get the device of a DLPack tensor.
Safety
tensormust be a valid, non-nullDLManagedTensorVersioned*.
- unsafe extern C fn rgpot_tensor_free(tensor: *mut DLManagedTensorVersioned)¶
Free a DLPack tensor by invoking its deleter.
If
tensorisNULL, this is a no-op.Safety
tensormust have been obtained from one of thergpot_tensor_*creation functions, or be a validDLManagedTensorVersionedwith a deleter.
- unsafe extern C fn rgpot_tensor_owned_cpu_f64_2d(data: *const f64, rows: i64, cols: i64) -> *mut DLManagedTensorVersioned¶
Create an owning 2-D f64 tensor on CPU by copying data.
The returned tensor owns a copy of the data — the caller may free the original buffer after this call. Call
rgpot_tensor_freewhen done.Safety
datamust point to at leastrows * colscontiguousf64values.
- unsafe extern C fn rgpot_tensor_shape(tensor: *const DLManagedTensorVersioned, ndim_out: *mut i32) -> *const i64¶
Get the shape array and number of dimensions of a DLPack tensor.
Writes the number of dimensions to
*ndim_outand returns a pointer to the shape array (length*ndim_out).Safety Both
tensorandndim_outmust be valid, non-null pointers.