Expand description
The cross-package tensor protocol.
Independently-linked EdgeFirst packages cannot share a Rust type: each
Python extension module statically links its own copy of this crate, and
PyO3 caches every #[pyclass]’s type object in a static belonging to the
module that defined it. Two modules therefore see two distinct Python
classes even when the Rust types are identical.
So the contract between packages is a descriptor, not a type. A producer
exposes __edgefirst_tensor__() returning a PyCapsule named
edgefirst_tensor_v2 whose payload leads with TensorDesc (followed by
the quantization metadata TensorDesc deliberately does not carry – see
edgefirst-python-common’s QuantDesc); a consumer reads the descriptor
and never performs an isinstance check. That duck typing is
what makes the protocol survive independent release cadences, and it is the
same pattern numpy, pyarrow and DLPack use.
DLPack cannot serve this role alone: it has no device type for dma-buf, IOSurface or PBO, which are precisely the zero-copy cases this library exists for.
Modules§
- flags
- Bit flags, as reported in
TensorDesc::flags. - format
- HAL pixel format, as reported in
TensorDesc::format.
Structs§
- Quant
Desc - Quantization metadata, in a form that can cross an
.soboundary. - Send
Const Ptr - A
*const Tthat may cross aPyCapsule. - SendPtr
- A raw pointer that may cross a
PyCapsule. - Tensor
Desc - The cross-package descriptor. Layout is part of the contract: it is
#[repr(C)]and its size is pinned by test.
Constants§
- ABI_
VERSION - Protocol version, checked by
TensorDyn::import_descriptorafter the payload has already been read as this build’sTensorDesc.
Functions§
- c_
byte_ strides - Row-major byte strides for
shape, with the row dimension replaced byrow_stridewhen one is recorded. - dtype_
to_ dtype - Map a wire [
dtype] code back to acrate::DType. Inverse of [dtype_of].Nonefor a code this build does not recognise (e.g. a dtype added by a newer producer this build predates) — the caller rejects rather than guessing. - format_
from_ code - Map a
formatwire code back to acrate::PixelFormat.Noneforformat::NONEor a code this build does not recognise (e.g. a format added by a newer producer).