Skip to main content

TensorElement

Trait TensorElement 

Source
pub trait TensorElement:
    TensorScalar
    + Copy
    + Send
    + Sync
    + 'static {
    // Required methods
    fn dense_native_tensor_from_col_major(
        data: &[Self],
        dims: &[usize],
    ) -> Result<Tensor, Error>;
    fn diag_native_tensor_from_col_major(
        data: &[Self],
        logical_rank: usize,
    ) -> Result<Tensor, Error>;
    fn scalar_native_tensor(value: Self) -> Result<Tensor, Error>;
    fn dense_values_from_native_col_major(
        tensor: &Tensor,
    ) -> Result<Vec<Self>, Error>;
    fn diag_values_from_native_temp(tensor: &Tensor) -> Result<Vec<Self>, Error>;
}
Expand description

Public scalar element types supported by tensor4all dense/diag constructors.

Implemented for f32, f64, Complex32, and Complex64.

§Examples

use tensor4all_tensorbackend::TensorElement;

let t = f64::dense_native_tensor_from_col_major(&[1.0, 2.0], &[2]).unwrap();
assert_eq!(t.shape(), &[2]);

let vals = f64::dense_values_from_native_col_major(&t).unwrap();
assert_eq!(vals, vec![1.0, 2.0]);

Required Methods§

Source

fn dense_native_tensor_from_col_major( data: &[Self], dims: &[usize], ) -> Result<Tensor, Error>

Build a dense native tensor from column-major data.

§Errors

Returns an error when the data length does not match the dimensions (a /// shape mismatch) or the backend conversion fails.

Source

fn diag_native_tensor_from_col_major( data: &[Self], logical_rank: usize, ) -> Result<Tensor, Error>

Build a diagonal native tensor from column-major diagonal payload data.

§Errors

Returns an error when the diagonal payload is incompatible (a shape /// mismatch) or the backend conversion fails.

Source

fn scalar_native_tensor(value: Self) -> Result<Tensor, Error>

Build a rank-0 native tensor.

§Errors

Returns an error when the scalar cannot be converted (a dtype mismatch or /// backend failure).

Source

fn dense_values_from_native_col_major( tensor: &Tensor, ) -> Result<Vec<Self>, Error>

Materialize dense column-major values from a native tensor.

§Errors

Returns an error when the native tensor cannot be materialized (a dtype /// mismatch or backend failure).

Source

fn diag_values_from_native_temp(tensor: &Tensor) -> Result<Vec<Self>, Error>

Materialize diagonal values from a dense native tensor.

§Errors

Returns an error when the native tensor cannot be materialized (a dtype /// mismatch or backend failure).

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl TensorElement for Complex<f32>

Source§

impl TensorElement for Complex<f64>

Source§

impl TensorElement for f32

Source§

impl TensorElement for f64

Implementors§