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§
Required Methods§
Sourcefn dims(&self) -> &[i64]
fn dims(&self) -> &[i64]
Tensor shape. ONNX-compatible signed-dim convention; -1
for dynamic dims.
Sourcefn len(&self) -> usize
fn len(&self) -> usize
Total element count across all dims. For dynamic-dim tensors callers must resolve concrete dims before consulting.
Sourcefn to_proto(&self) -> TensorProto
fn to_proto(&self) -> TensorProto
Serialize to canonical ONNX TensorProto. The result is
portable across backends declaring the same scalar type.
Sourcefn from_proto(proto: TensorProto) -> Result<Self, TensorSerializationError>
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§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".