Skip to main content

BackendTestAdapter

Trait BackendTestAdapter 

Source
pub trait BackendTestAdapter {
    type Executor: TlExecutor<Tensor = Self::Tensor>;
    type Tensor: Clone;

    // Required methods
    fn create_executor() -> Self::Executor;
    fn create_tensor_from_data(data: &[f64], shape: &[usize]) -> Self::Tensor;
    fn tensor_to_vec(tensor: &Self::Tensor) -> Vec<f64>;
    fn tensor_shape(tensor: &Self::Tensor) -> Vec<usize>;

    // Provided methods
    fn create_scalar(value: f64) -> Self::Tensor { ... }
    fn create_vector(data: &[f64]) -> Self::Tensor { ... }
    fn create_matrix(data: &[f64], rows: usize, cols: usize) -> Self::Tensor { ... }
}
Expand description

Adapter trait for backend testing.

Backend developers implement this trait to adapt their executor to the test framework.

Required Associated Types§

Source

type Executor: TlExecutor<Tensor = Self::Tensor>

The executor type being tested

Source

type Tensor: Clone

The tensor type used by the executor

Required Methods§

Source

fn create_executor() -> Self::Executor

Create a new executor instance for testing

Source

fn create_tensor_from_data(data: &[f64], shape: &[usize]) -> Self::Tensor

Create a tensor from raw data and shape

Source

fn tensor_to_vec(tensor: &Self::Tensor) -> Vec<f64>

Convert tensor to a flat vector for comparison

Source

fn tensor_shape(tensor: &Self::Tensor) -> Vec<usize>

Get the shape of a tensor

Provided Methods§

Source

fn create_scalar(value: f64) -> Self::Tensor

Create a scalar tensor

Source

fn create_vector(data: &[f64]) -> Self::Tensor

Create a 1D tensor (vector)

Source

fn create_matrix(data: &[f64], rows: usize, cols: usize) -> Self::Tensor

Create a 2D tensor (matrix)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§