Skip to main content

ComputeBackendTensorExt

Trait ComputeBackendTensorExt 

Source
pub trait ComputeBackendTensorExt: ComputeBackend {
    // Provided methods
    fn make_tensor<T: Clone>(
        &self,
        data: Vec<T>,
        shape: Vec<usize>,
    ) -> DenseTensorData<T> { ... }
    fn dense<T: Clone>(&self, data: Vec<T>, shape: Vec<usize>) -> DenseTensor<T> { ... }
    fn zeros<T: Clone + Zero>(&self, shape: Vec<usize>) -> DenseTensorData<T> { ... }
    fn ones<T: Clone + Zero + One>(
        &self,
        shape: Vec<usize>,
    ) -> DenseTensorData<T> { ... }
    fn filled<T: Clone>(
        &self,
        shape: Vec<usize>,
        value: T,
    ) -> DenseTensorData<T> { ... }
    fn eye<T: Clone + Zero + One>(&self, n: usize) -> DenseTensorData<T> { ... }
}
Expand description

Extension trait for backend-aware tensor construction.

Provides tensor constructors on any ComputeBackend. The constructed tensors have order() matching the backend’s preferred_order(), so downstream linalg operations driven by that backend find the storage already in the layout they expect. Most constructors return the Mid-layer DenseTensorData<T> for kernel-output paths; dense returns the wrapped DenseTensor<T> for the input-fabrication case.

Provided Methods§

Source

fn make_tensor<T: Clone>( &self, data: Vec<T>, shape: Vec<usize>, ) -> DenseTensorData<T>

Construct a DenseTensorData from data in this backend’s preferred memory order.

The caller must arrange data in this backend’s preferred_order(). The resulting tensor data has order() == self.preferred_order().

Source

fn dense<T: Clone>(&self, data: Vec<T>, shape: Vec<usize>) -> DenseTensor<T>

Construct a DenseTensor from data in this backend’s preferred memory order.

The caller must arrange data in this backend’s preferred_order(). The resulting tensor has order() == self.preferred_order().

One-call entry for fabricating an input tensor from flat parts: fuses make_tensor — which yields the Mid-layer DenseTensorData, kept for kernel-output paths — with the DenseTensor wrap, so a caller that just wants a tensor need not reach across the Data layer. The backend stays explicit at the call site, so this is not a host-hardcoded constructor.

Source

fn zeros<T: Clone + Zero>(&self, shape: Vec<usize>) -> DenseTensorData<T>

Create a zero-filled tensor whose order() matches this backend.

Source

fn ones<T: Clone + Zero + One>(&self, shape: Vec<usize>) -> DenseTensorData<T>

Create a ones-filled tensor whose order() matches this backend.

Source

fn filled<T: Clone>(&self, shape: Vec<usize>, value: T) -> DenseTensorData<T>

Create a tensor filled with value whose order() matches this backend.

Source

fn eye<T: Clone + Zero + One>(&self, n: usize) -> DenseTensorData<T>

Create an identity matrix whose order() matches this backend.

The identity matrix is symmetric, so its flat data layout is the same regardless of memory order; only the order() field differs.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§