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_v1 wrapping TensorDesc; 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. - kind
- Backing store kind, as reported in
TensorDesc::kind.
Structs§
- 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§
- 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).