pub trait TensorScalar:
Copy
+ Clone
+ Send
+ Sync
+ 'static
+ Sealed {
type Real: TensorScalar;
// Required methods
fn dtype() -> DType;
fn into_tensor(shape: Vec<usize>, data: Vec<Self>) -> Tensor;
fn try_as_slice(tensor: &Tensor) -> Option<&[Self]>;
fn try_into_typed(tensor: Tensor) -> Option<TypedTensor<Self>>;
}Expand description
Sealed trait for scalar types that can be stored in a Tensor.
This trait is implemented for f64, f32, Complex64, and
Complex32.
§Examples
use tenferro_tensor::TensorScalar;
let tensor = <f64 as TensorScalar>::into_tensor(vec![2], vec![1.0, 2.0]);
assert_eq!(tensor.as_slice::<f64>(), Some([1.0, 2.0].as_slice()));Required Associated Types§
Sourcetype Real: TensorScalar
type Real: TensorScalar
Real-valued counterpart of this scalar type.
Required Methods§
Sourcefn into_tensor(shape: Vec<usize>, data: Vec<Self>) -> Tensor
fn into_tensor(shape: Vec<usize>, data: Vec<Self>) -> Tensor
Wrap typed data into a Tensor enum variant.
Sourcefn try_as_slice(tensor: &Tensor) -> Option<&[Self]>
fn try_as_slice(tensor: &Tensor) -> Option<&[Self]>
Try to borrow the host data from a Tensor.
Sourcefn try_into_typed(tensor: Tensor) -> Option<TypedTensor<Self>>
fn try_into_typed(tensor: Tensor) -> Option<TypedTensor<Self>>
Try to extract a TypedTensor<Self> from a dynamic Tensor.
Returns None if the tensor dtype does not match Self.
§Examples
use tenferro_tensor::{Tensor, TensorScalar};
let tensor = Tensor::from_vec(vec![2], vec![1.0_f64, 2.0]);
let typed = <f64 as TensorScalar>::try_into_typed(tensor).unwrap();
assert_eq!(typed.as_slice(), &[1.0, 2.0]);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.