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<NativeTensor>;
    fn dense_native_tensor_from_col_major_owned(
        data: Vec<Self>,
        dims: &[usize],
    ) -> Result<NativeTensor>;
    fn diag_native_tensor_from_col_major(
        data: &[Self],
        logical_rank: usize,
    ) -> Result<NativeTensor>;
    fn scalar_native_tensor(value: Self) -> Result<NativeTensor>;
    fn dense_values_from_native_col_major(
        tensor: &NativeTensor,
    ) -> Result<Vec<Self>>;
    fn diag_values_from_native_temp(tensor: &NativeTensor) -> Result<Vec<Self>>;
}
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<NativeTensor>

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 dense_native_tensor_from_col_major_owned( data: Vec<Self>, dims: &[usize], ) -> Result<NativeTensor>

Build a dense native tensor by moving an owned column-major payload.

This is the allocation-preserving counterpart of Self::dense_native_tensor_from_col_major. The payload must contain exactly the product of dims elements.

§Errors

Returns an error for a shape mismatch when the data length does not equal the dimension product, or for a backend conversion failure.

§Arguments
  • data - Owned column-major values whose length equals the product of dims.
  • dims - Logical tensor dimensions in column-major axis order.
§Returns

A native dense tensor that owns the supplied payload without cloning it.

§Examples
use tensor4all_tensorbackend::TensorElement;

let tensor = f64::dense_native_tensor_from_col_major_owned(
    vec![1.0, 2.0, 3.0, 4.0],
    &[2, 2],
)
.unwrap();
assert_eq!(tensor.shape(), &[2, 2]);
assert_eq!(tensor.as_slice::<f64>().unwrap(), &[1.0, 2.0, 3.0, 4.0]);
Source

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

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<NativeTensor>

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: &NativeTensor, ) -> Result<Vec<Self>>

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: &NativeTensor) -> Result<Vec<Self>>

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 Complex32

Source§

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

Source§

fn dense_native_tensor_from_col_major_owned( data: Vec<Self>, dims: &[usize], ) -> Result<NativeTensor>

Source§

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

Source§

fn scalar_native_tensor(value: Self) -> Result<NativeTensor>

Source§

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

Source§

fn diag_values_from_native_temp(tensor: &NativeTensor) -> Result<Vec<Self>>

Source§

impl TensorElement for Complex64

Source§

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

Source§

fn dense_native_tensor_from_col_major_owned( data: Vec<Self>, dims: &[usize], ) -> Result<NativeTensor>

Source§

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

Source§

fn scalar_native_tensor(value: Self) -> Result<NativeTensor>

Source§

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

Source§

fn diag_values_from_native_temp(tensor: &NativeTensor) -> Result<Vec<Self>>

Source§

impl TensorElement for f32

Source§

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

Source§

fn dense_native_tensor_from_col_major_owned( data: Vec<Self>, dims: &[usize], ) -> Result<NativeTensor>

Source§

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

Source§

fn scalar_native_tensor(value: Self) -> Result<NativeTensor>

Source§

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

Source§

fn diag_values_from_native_temp(tensor: &NativeTensor) -> Result<Vec<Self>>

Source§

impl TensorElement for f64

Source§

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

Source§

fn dense_native_tensor_from_col_major_owned( data: Vec<Self>, dims: &[usize], ) -> Result<NativeTensor>

Source§

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

Source§

fn scalar_native_tensor(value: Self) -> Result<NativeTensor>

Source§

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

Source§

fn diag_values_from_native_temp(tensor: &NativeTensor) -> Result<Vec<Self>>

Implementors§