Skip to main content

CpuTensor

Struct CpuTensor 

Source
pub struct CpuTensor(/* private fields */);
Expand description

f32-dense CPU-resident tensor handle. Arc-shared so intra-Node clones (FedAvg’s per-peer buffer insert, slot-table writes, etc.) are refcount bumps rather than Vec<f32> deep copies. The underlying CpuBackendBuffer is owned by the backend, which is free to pool / reuse / free the storage at a later milestone without API churn (the handle shape stays identical).

Implementations§

Source§

impl CpuTensor

Source

pub fn from_array(data: ArrayD<f32>) -> Self

Wrap an existing ArrayD<f32> in a fresh backend buffer. charged_bytes = 0 — kernel outputs and test fixtures don’t arrive via the wire and therefore don’t hold an ingress charge. The wire path uses the crate-private from_wire_buffer helper from CpuBackend::materialize_from_wire.

Source

pub fn from_vec(shape: Vec<i64>, data: Vec<f32>) -> Self

Construct from ONNX-signed shape + flat row-major data via ndarray::ArrayD::from_shape_vec. Equivalent to Self::new but spelled out for callers preferring the builder-style name.

Source

pub fn as_array(&self) -> &ArrayD<f32>

Borrow the underlying ndarray.

Source

pub fn into_array(self) -> ArrayD<f32>

Clone the backend buffer into an owned ArrayD<f32>. The Arc shape means the buffer cannot be unwrapped in-place (other handles may share it), so this always pays the ndarray deep copy. Test-only callers needing flat data should prefer Self::flat_data.

Source

pub fn new(dims: Vec<i64>, data: Vec<f32>) -> Self

Construct from ONNX-signed shape + flat row-major data. Panics if the dims product doesn’t match the data length — callers needing strict checking use Self::new_checked.

Source

pub fn new_checked( dims: Vec<i64>, data: Vec<f32>, ) -> Result<Self, CpuTensorError>

Construct + validate dims_product(&dims) == data.len().

Source

pub fn zeros(dims: Vec<i64>) -> Self

Construct a zero-filled tensor with the given shape.

Source

pub fn ones(dims: Vec<i64>) -> Self

Construct a ones-filled tensor with the given shape.

Source

pub fn strong_count(&self) -> usize

Observe the underlying Arc<CpuBackendBuffer> strong-refcount. One strong holder means the caller holds the only handle to the buffer; future pooling implementations (v2) read this to decide whether to return the buffer to the pool on drop. Tests use this to prove the wire-decode path lands a single carrier in the slot table with no spurious clones.

Trait Implementations§

Source§

impl Clone for CpuTensor

Source§

fn clone(&self) -> CpuTensor

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CpuTensor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for CpuTensor

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for CpuTensor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for CpuTensor

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Storage for CpuTensor

CpuTensorTYPE_TENSOR_F32 in the polymorphism tree.

Source§

const TYPE: &'static TypeNode

Position-in-tree declaration. The TypeNode static this constant points at decides what other storage types unify with this one during the type-solver walk.
Source§

impl Tensor for CpuTensor

Source§

type Scalar = f32

The scalar element type this tensor holds.
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.
Source§

fn is_empty(&self) -> bool

true when the tensor holds zero elements.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedComponent for T
where T: Any + Send + Sync,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> SlotValue for T

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Downcast surface — recover the concrete type.
Source§

fn into_any_boxed(self: Box<T>) -> Box<dyn Any + Sync + Send>

Repackage Box<dyn SlotValue> as Box<dyn Any> for Box::downcast. Required because the SlotValue and Any vtables are distinct even though SlotValue: Any.
Source§

fn clone_boxed(&self) -> Box<dyn SlotValue>

Polymorphic clone preserving the concrete type.
Source§

fn to_wire_bytes(&self) -> Result<Vec<u8>, SlotValueError>

Wire-boundary encode (bincode + serde). Local forwarding uses clone_boxed instead.
Source§

fn type_hash(&self) -> u64

Stable cross-Node type discriminator. FNV-1a of std::any::type_name::<T>(); receiver decodes only on a matching hash.
Source§

fn runtime_type(&self) -> &'static TypeNode

Runtime TypeNode for this value. Returns the leaf registered via [register_type_node!] or TYPE_ANY. Consulted at wire boundaries + TypeSolver seeding; the atomic-dispatch hot path uses compile-time-stamped closures.
Source§

fn charged_bytes(&self) -> usize

Bytes the carrier owes against NodeConfig::ingress_byte_budget. Slot-table eviction calls this to release the charge. Default 0 — only ingress-derived carriers register a non-zero resolver via [register_charged_bytes!].
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more