Skip to main content

StorageScalar

Trait StorageScalar 

Source
pub trait StorageScalar:
    Clone
    + Send
    + Sync
    + 'static {
    // Required methods
    fn build_dense_storage(
        data: Vec<Self>,
        logical_dims: &[usize],
    ) -> Result<Storage>;
    fn build_diag_storage(
        diag_data: Vec<Self>,
        logical_rank: usize,
    ) -> Result<Storage>;
    fn build_structured_storage(
        data: Vec<Self>,
        payload_dims: Vec<usize>,
        strides: Vec<isize>,
        axis_classes: Vec<usize>,
    ) -> Result<Storage>;
}
Expand description

Trait for scalar types that can be stored in Storage.

This enables generic constructors such as Storage::from_dense_col_major and Storage::from_diag_col_major. Implemented for f64 and Complex64.

§Examples

use tensor4all_tensorbackend::{Storage, StorageScalar};

// Using the generic constructor -- scalar type is inferred from data
let s = Storage::from_dense_col_major(vec![1.0_f64, 2.0, 3.0], &[3]).unwrap();
assert!(s.is_f64());

use num_complex::Complex64;
let c = Storage::from_dense_col_major(
    vec![Complex64::new(1.0, 0.0), Complex64::new(0.0, 1.0)],
    &[2],
).unwrap();
assert!(c.is_c64());

Required Methods§

Source

fn build_dense_storage( data: Vec<Self>, logical_dims: &[usize], ) -> Result<Storage>

Build a dense Storage from column-major data.

Source

fn build_diag_storage( diag_data: Vec<Self>, logical_rank: usize, ) -> Result<Storage>

Build a diagonal Storage from diagonal payload data.

Source

fn build_structured_storage( data: Vec<Self>, payload_dims: Vec<usize>, strides: Vec<isize>, axis_classes: Vec<usize>, ) -> Result<Storage>

Build a structured Storage from explicit payload metadata.

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.

Implementations on Foreign Types§

Source§

impl StorageScalar for f64

Source§

fn build_dense_storage( data: Vec<Self>, logical_dims: &[usize], ) -> Result<Storage>

Source§

fn build_diag_storage( diag_data: Vec<Self>, logical_rank: usize, ) -> Result<Storage>

Source§

fn build_structured_storage( data: Vec<Self>, payload_dims: Vec<usize>, strides: Vec<isize>, axis_classes: Vec<usize>, ) -> Result<Storage>

Source§

impl StorageScalar for Complex64

Source§

fn build_dense_storage( data: Vec<Self>, logical_dims: &[usize], ) -> Result<Storage>

Source§

fn build_diag_storage( diag_data: Vec<Self>, logical_rank: usize, ) -> Result<Storage>

Source§

fn build_structured_storage( data: Vec<Self>, payload_dims: Vec<usize>, strides: Vec<isize>, axis_classes: Vec<usize>, ) -> Result<Storage>

Implementors§