Skip to main content

ScalarTensorElement

Trait ScalarTensorElement 

Source
pub trait ScalarTensorElement: TensorElement {
    // Required method
    fn scalar_value(value: Self) -> ScalarValue;
}
Expand description

Maps a concrete tensor element type onto its ScalarValue variant.

This is the single implementation of the scalar construction contract: BackendScalar::from_value here and tensor4all_core::AnyScalar::from_value use it instead of each matching on the element type. It is public for the same reason as ScalarValue: the core wrapper is in a downstream crate and bounds its own from_value on this trait. Implemented for f32, f64, Complex32, and Complex64.

§Examples

use num_complex::Complex64;
use tensor4all_tensorbackend::{BackendScalar, ScalarTensorElement, ScalarValue};

assert_eq!(Complex64::scalar_value(Complex64::new(1.0, -2.0)), ScalarValue::C64(Complex64::new(1.0, -2.0)));
assert!((BackendScalar::from_value(Complex64::new(3.0, -4.0)).abs() - 5.0).abs() < 1e-12);

Required Methods§

Source

fn scalar_value(value: Self) -> ScalarValue

Lifts this concrete element into its dynamic scalar variant.

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 ScalarTensorElement for Complex32

Source§

impl ScalarTensorElement for Complex64

Source§

impl ScalarTensorElement for f32

Source§

impl ScalarTensorElement for f64

Implementors§