Skip to main content

Tensor

Trait Tensor 

Source
pub trait Tensor:
    Clone
    + Debug
    + Display
    + Send
    + Sync
    + 'static
    + Serialize
    + DeserializeOwned {
    type Scalar: Scalar;

    // Required methods
    fn dims(&self) -> &[i64];
    fn len(&self) -> usize;
    fn to_proto(&self) -> TensorProto;
    fn from_proto(proto: TensorProto) -> Result<Self, TensorSerializationError>;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

The contract every backend’s concrete tensor type implements.

Backend impls land in integration crates (e.g. bb-cpu-onnx). The framework crate ships no concrete tensor type - the Tensor trait IS the contract.

The serde + Clone bounds are what make every concrete tensor type a crate::slot_value::SlotValue via the universal blanket - tensors ride slots, wire envelopes, and snapshots through the same bincode encoding path as every other value.

Required Associated Types§

Source

type Scalar: Scalar

The scalar element type this tensor holds.

Required Methods§

Source

fn dims(&self) -> &[i64]

Tensor shape. ONNX-compatible signed-dim convention; -1 for dynamic dims.

Source

fn len(&self) -> usize

Total element count across all dims. For dynamic-dim tensors callers must resolve concrete dims before consulting.

Source

fn to_proto(&self) -> TensorProto

Serialize to canonical ONNX TensorProto. The result is portable across backends declaring the same scalar type.

Source

fn from_proto(proto: TensorProto) -> Result<Self, TensorSerializationError>

Deserialize from canonical ONNX TensorProto. Returns an error if the proto’s elem_type / shape doesn’t match Self’s expectations.

Provided Methods§

Source

fn is_empty(&self) -> bool

true when the tensor holds zero elements.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§