pub struct Tensor<T: Copy + Default + DType, const N: usize, const R: usize> { /* private fields */ }Expand description
Owned, fixed-capacity tensor stored inline.
T— scalar element type (Copy + Default + DType).N— maximum element capacity (compile-time).R— tensor rank / number of dimensions (compile-time).
len tracks live elements (≤ N). Shape is [usize; R] with all
dimensions active. Rank-0 scalars use R = 0.
Byte size is computed, not stored — one multiply is cheaper than 8 bytes of struct overhead on a constrained MCU.
§Examples
// TF Lite Micro person detection input.
let img = Tensor::<u8, 9216, 4>::nhwc(1, 96, 96, 1, &pixels);
// Classifier output.
let out = Tensor::<i8, 3, 2>::nc(1, 3, &scores);
// Flat feature vector.
let v = Tensor::<f32, 128, 1>::from_slice(&features);
// Destructure shape for processing.
let [batch, height, width, channels] = *img.shape();
let pixel = img.at([0, 10, 20, 0]);Implementations§
Source§impl<T: Copy + Default + DType, const N: usize, const R: usize> Tensor<T, N, R>
impl<T: Copy + Default + DType, const N: usize, const R: usize> Tensor<T, N, R>
Sourcepub fn from_shape(shape: [usize; R], data: &[T]) -> Self
pub fn from_shape(shape: [usize; R], data: &[T]) -> Self
Create from a shape and data slice.
§Panics
- If
data.len() > N. - In debug: if the product of
shape!=data.len().
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Mutably borrow the live data.
Sourcepub fn is_compatible(&self) -> bool
pub fn is_compatible(&self) -> bool
Validate that the shape product matches the element count.
Source§impl<T: Copy + Default + DType, const N: usize> Tensor<T, N, 1>
impl<T: Copy + Default + DType, const N: usize> Tensor<T, N, 1>
Sourcepub fn from_slice(data: &[T]) -> Self
pub fn from_slice(data: &[T]) -> Self
Create from a data slice (shape inferred as [data.len()]).
Source§impl<T: Copy + Default + DType, const N: usize> Tensor<T, N, 3>
impl<T: Copy + Default + DType, const N: usize> Tensor<T, N, 3>
Trait Implementations§
Source§impl<T: Clone + Copy + Default + DType, const N: usize, const R: usize> Clone for Tensor<T, N, R>
impl<T: Clone + Copy + Default + DType, const N: usize, const R: usize> Clone for Tensor<T, N, R>
Source§impl ComputeBackend<Tensor<u32, TEST_TENSOR_ELEMENT_COUNT, 2>, Tensor<u32, TEST_TENSOR_ELEMENT_COUNT, 2>> for TestTensorBackend
impl ComputeBackend<Tensor<u32, TEST_TENSOR_ELEMENT_COUNT, 2>, Tensor<u32, TEST_TENSOR_ELEMENT_COUNT, 2>> for TestTensorBackend
Source§type Model = TestTensorModel
type Model = TestTensorModel
Concrete model type (no trait objects).
Source§type Error = InferenceError
type Error = InferenceError
Backend-specific error.
Source§type ModelDescriptor<'d> = ()
type ModelDescriptor<'d> = ()
Backend-chosen borrowed descriptor used to load a model. Read more
Source§fn capabilities(&self) -> BackendCapabilities
fn capabilities(&self) -> BackendCapabilities
Capability report.
Source§fn load_model<'d>(
&self,
_desc: Self::ModelDescriptor<'d>,
) -> Result<Self::Model, Self::Error>
fn load_model<'d>( &self, _desc: Self::ModelDescriptor<'d>, ) -> Result<Self::Model, Self::Error>
Load a model from a descriptor.
Source§impl ComputeModel<Tensor<u32, TEST_TENSOR_ELEMENT_COUNT, 2>, Tensor<u32, TEST_TENSOR_ELEMENT_COUNT, 2>> for TestTensorModel
impl ComputeModel<Tensor<u32, TEST_TENSOR_ELEMENT_COUNT, 2>, Tensor<u32, TEST_TENSOR_ELEMENT_COUNT, 2>> for TestTensorModel
Source§fn init(&mut self) -> Result<(), InferenceError>
fn init(&mut self) -> Result<(), InferenceError>
Prepare internal state (allocate work buffers, compile kernels, etc.).
Source§fn infer_one(
&mut self,
inp: &TestTensor,
out: &mut TestTensor,
) -> Result<(), InferenceError>
fn infer_one( &mut self, inp: &TestTensor, out: &mut TestTensor, ) -> Result<(), InferenceError>
Single-item inference (1×1).
Source§fn infer_batch(
&mut self,
inputs: Batch<'_, TestTensor>,
outputs: &mut [TestTensor],
) -> Result<(), InferenceError>
fn infer_batch( &mut self, inputs: Batch<'_, TestTensor>, outputs: &mut [TestTensor], ) -> Result<(), InferenceError>
Optional: batched inference. Default loops
infer_one.Source§fn drain(&mut self) -> Result<(), InferenceError>
fn drain(&mut self) -> Result<(), InferenceError>
Ensure outstanding device work is complete (if any).
Source§fn reset(&mut self) -> Result<(), InferenceError>
fn reset(&mut self) -> Result<(), InferenceError>
Reset internal state to a known baseline (drop caches, etc.).
Source§fn metadata(&self) -> ModelMetadata
fn metadata(&self) -> ModelMetadata
Return model metadata (I/O placement preferences, limits).
Source§impl<T: Copy + Default + DType + Debug, const N: usize, const R: usize> Debug for Tensor<T, N, R>
impl<T: Copy + Default + DType + Debug, const N: usize, const R: usize> Debug for Tensor<T, N, R>
Source§impl<T: Copy + Default + DType + PartialEq, const N: usize, const R: usize> PartialEq for Tensor<T, N, R>
impl<T: Copy + Default + DType + PartialEq, const N: usize, const R: usize> PartialEq for Tensor<T, N, R>
Source§impl<T: Copy + Default + DType, const N: usize, const R: usize> Payload for Tensor<T, N, R>
impl<T: Copy + Default + DType, const N: usize, const R: usize> Payload for Tensor<T, N, R>
Source§fn buffer_descriptor(&self) -> BufferDescriptor
fn buffer_descriptor(&self) -> BufferDescriptor
Return a descriptor containing the byte size of this payload.
Source§impl Sink<Tensor<u32, TEST_TENSOR_ELEMENT_COUNT, 2>, 1> for TestSinkNodeTensor
impl Sink<Tensor<u32, TEST_TENSOR_ELEMENT_COUNT, 2>, 1> for TestSinkNodeTensor
Source§type Error = Infallible
type Error = Infallible
Sink-specific error type for
open() or consume().Source§fn open(&mut self) -> Result<(), Self::Error>
fn open(&mut self) -> Result<(), Self::Error>
Prepare the sink for consumption (open file/device, connect network, etc.). Read more
Source§fn consume(&mut self, msg: &Message<TestTensor>) -> Result<(), Self::Error>
fn consume(&mut self, msg: &Message<TestTensor>) -> Result<(), Self::Error>
Consume a single message pulled from
port. Read moreSource§fn input_acceptance(&self) -> [PlacementAcceptance; 1]
fn input_acceptance(&self) -> [PlacementAcceptance; 1]
Input placement acceptances for zero-copy compatibility.
Source§fn capabilities(&self) -> NodeCapabilities
fn capabilities(&self) -> NodeCapabilities
Describe sink capabilities (device streams, degrade tiers, etc.).
Source§fn policy(&self) -> NodePolicy
fn policy(&self) -> NodePolicy
Provide the node policy bundle (batching/budget/deadlines).
Source§fn select_input(&mut self, occ: &[EdgeOccupancy; IN]) -> Option<usize>
fn select_input(&mut self, occ: &[EdgeOccupancy; IN]) -> Option<usize>
Optional: choose which input to read this step based on occupancies. Read more
Source§impl<Clock, const BACKLOG_CAP: usize> Source<Tensor<u32, TEST_TENSOR_ELEMENT_COUNT, 2>, 1> for TestCounterSourceTensor<Clock, BACKLOG_CAP>where
Clock: PlatformClock,
impl<Clock, const BACKLOG_CAP: usize> Source<Tensor<u32, TEST_TENSOR_ELEMENT_COUNT, 2>, 1> for TestCounterSourceTensor<Clock, BACKLOG_CAP>where
Clock: PlatformClock,
Source§fn peek_ingress_creation_tick(&self, item_index: usize) -> Option<u64>
fn peek_ingress_creation_tick(&self, item_index: usize) -> Option<u64>
Peek the creation tick of the item_index’th ingress item (0 = oldest).
Non-blocking and non-destructive. Returns None if metadata is not
available (no backlog) or item_index is out of range.
Source§type Error = Infallible
type Error = Infallible
Source-specific error type for
open().Source§fn open(&mut self) -> Result<(), Self::Error>
fn open(&mut self) -> Result<(), Self::Error>
Prepare the source for production (e.g., open device, init driver). Read more
Source§fn try_produce(&mut self) -> Option<(usize, Message<TestTensor>)>
fn try_produce(&mut self) -> Option<(usize, Message<TestTensor>)>
Attempt to produce exactly one
(port, message) pair. Read moreSource§fn ingress_occupancy(&self) -> EdgeOccupancy
fn ingress_occupancy(&self) -> EdgeOccupancy
Report ingress pressure (items/bytes before the source). Read more
Source§fn output_acceptance(&self) -> [PlacementAcceptance; 1]
fn output_acceptance(&self) -> [PlacementAcceptance; 1]
Return output placement acceptances for zero-copy compatibility.
Source§fn capabilities(&self) -> NodeCapabilities
fn capabilities(&self) -> NodeCapabilities
Describe source capabilities (device streams, degrade tiers, etc.).
Source§fn policy(&self) -> NodePolicy
fn policy(&self) -> NodePolicy
Provide the node policy bundle (batching/budget/deadlines).
Source§fn ingress_policy(&self) -> EdgePolicy
fn ingress_policy(&self) -> EdgePolicy
Provude the ingress edge policy for this source node.
Source§fn into_sourcenode(self, policy: NodePolicy) -> SourceNode<Self, OutP, OUT>where
Self: Sized,
fn into_sourcenode(self, policy: NodePolicy) -> SourceNode<Self, OutP, OUT>where
Self: Sized,
Convenience: wrap this source in a
SourceNode with the provided policy. Read moreimpl<T: Copy + Copy + Default + DType, const N: usize, const R: usize> Copy for Tensor<T, N, R>
impl<T: Copy + Default + DType + Eq, const N: usize, const R: usize> Eq for Tensor<T, N, R>
Auto Trait Implementations§
impl<T, const N: usize, const R: usize> Freeze for Tensor<T, N, R>where
T: Freeze,
impl<T, const N: usize, const R: usize> RefUnwindSafe for Tensor<T, N, R>where
T: RefUnwindSafe,
impl<T, const N: usize, const R: usize> Send for Tensor<T, N, R>where
T: Send,
impl<T, const N: usize, const R: usize> Sync for Tensor<T, N, R>where
T: Sync,
impl<T, const N: usize, const R: usize> Unpin for Tensor<T, N, R>where
T: Unpin,
impl<T, const N: usize, const R: usize> UnsafeUnpin for Tensor<T, N, R>where
T: UnsafeUnpin,
impl<T, const N: usize, const R: usize> UnwindSafe for Tensor<T, N, R>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more