Skip to main content

TensorScalar

Trait TensorScalar 

pub trait TensorScalar:
    Copy
    + Clone
    + Send
    + Sync
    + 'static
    + Sealed {
    type Real: TensorScalar;

    // Required methods
    fn dtype() -> DType;
    fn into_tensor(shape: SmallVec<[usize; 8]>, data: Vec<Self>) -> Tensor;
    fn tensor_slice(tensor: &Tensor) -> Option<&[Self]>;
    fn tensor_mut_slice(tensor: &mut Tensor) -> Option<&mut [Self]>;
    fn into_typed(tensor: Tensor) -> Option<HostTensor<Self>>;
}
Expand description

Sealed trait for scalar types supported by the core tensor data model.

§Examples

use tenferro_tensor_core::{DType, TensorScalar};

assert_eq!(f64::dtype(), DType::F64);
assert_eq!(num_complex::Complex64::dtype(), DType::C64);

Required Associated Types§

type Real: TensorScalar

Real-valued counterpart of this scalar type.

Required Methods§

fn dtype() -> DType

Return the scalar dtype tag.

§Examples
use tenferro_tensor_core::{DType, TensorScalar};

assert_eq!(i64::dtype(), DType::I64);

fn into_tensor(shape: SmallVec<[usize; 8]>, data: Vec<Self>) -> Tensor

fn tensor_slice(tensor: &Tensor) -> Option<&[Self]>

fn tensor_mut_slice(tensor: &mut Tensor) -> Option<&mut [Self]>

fn into_typed(tensor: Tensor) -> Option<HostTensor<Self>>

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§

§

impl TensorScalar for bool

§

type Real = bool

§

fn dtype() -> DType

§

fn into_tensor(shape: SmallVec<[usize; 8]>, data: Vec<bool>) -> Tensor

§

fn tensor_slice(tensor: &Tensor) -> Option<&[bool]>

§

fn tensor_mut_slice(tensor: &mut Tensor) -> Option<&mut [bool]>

§

fn into_typed(tensor: Tensor) -> Option<HostTensor<bool>>

§

impl TensorScalar for f32

§

type Real = f32

§

fn dtype() -> DType

§

fn into_tensor(shape: SmallVec<[usize; 8]>, data: Vec<f32>) -> Tensor

§

fn tensor_slice(tensor: &Tensor) -> Option<&[f32]>

§

fn tensor_mut_slice(tensor: &mut Tensor) -> Option<&mut [f32]>

§

fn into_typed(tensor: Tensor) -> Option<HostTensor<f32>>

§

impl TensorScalar for f64

§

type Real = f64

§

fn dtype() -> DType

§

fn into_tensor(shape: SmallVec<[usize; 8]>, data: Vec<f64>) -> Tensor

§

fn tensor_slice(tensor: &Tensor) -> Option<&[f64]>

§

fn tensor_mut_slice(tensor: &mut Tensor) -> Option<&mut [f64]>

§

fn into_typed(tensor: Tensor) -> Option<HostTensor<f64>>

§

impl TensorScalar for i32

§

type Real = i32

§

fn dtype() -> DType

§

fn into_tensor(shape: SmallVec<[usize; 8]>, data: Vec<i32>) -> Tensor

§

fn tensor_slice(tensor: &Tensor) -> Option<&[i32]>

§

fn tensor_mut_slice(tensor: &mut Tensor) -> Option<&mut [i32]>

§

fn into_typed(tensor: Tensor) -> Option<HostTensor<i32>>

§

impl TensorScalar for i64

§

type Real = i64

§

fn dtype() -> DType

§

fn into_tensor(shape: SmallVec<[usize; 8]>, data: Vec<i64>) -> Tensor

§

fn tensor_slice(tensor: &Tensor) -> Option<&[i64]>

§

fn tensor_mut_slice(tensor: &mut Tensor) -> Option<&mut [i64]>

§

fn into_typed(tensor: Tensor) -> Option<HostTensor<i64>>

§

impl TensorScalar for Complex<f32>

§

type Real = f32

§

fn dtype() -> DType

§

fn into_tensor(shape: SmallVec<[usize; 8]>, data: Vec<Complex<f32>>) -> Tensor

§

fn tensor_slice(tensor: &Tensor) -> Option<&[Complex<f32>]>

§

fn tensor_mut_slice(tensor: &mut Tensor) -> Option<&mut [Complex<f32>]>

§

fn into_typed(tensor: Tensor) -> Option<HostTensor<Complex<f32>>>

§

impl TensorScalar for Complex<f64>

§

type Real = f64

§

fn dtype() -> DType

§

fn into_tensor(shape: SmallVec<[usize; 8]>, data: Vec<Complex<f64>>) -> Tensor

§

fn tensor_slice(tensor: &Tensor) -> Option<&[Complex<f64>]>

§

fn tensor_mut_slice(tensor: &mut Tensor) -> Option<&mut [Complex<f64>]>

§

fn into_typed(tensor: Tensor) -> Option<HostTensor<Complex<f64>>>

Implementors§