pub trait TensorValue:
Debug
+ Clone
+ PartialEq
+ PartialOrd
+ Send
+ Sync
+ 'static {
type Array: Array + Clone + 'static;
type Masked: TensorValue<Array = Self::Array>;
type Unmasked: TensorValue<Array = Self::Array>;
const TENSOR_TYPE: TensorType;
const NULLABLE: bool;
// Required methods
fn value(array: &Self::Array, i: usize) -> Self;
unsafe fn value_unchecked(array: &Self::Array, i: usize) -> Self;
fn to_masked(value: Self) -> Self::Masked;
fn to_unmasked(value: Self) -> Self::Unmasked;
fn from_iter_masked<I>(iter: I) -> Self::Array
where I: IntoIterator<Item = Self::Masked>;
fn from_vec(values: Vec<Self>) -> Self::Array;
unsafe fn from_trusted_len_iter_masked<I>(iter: I) -> Self::Array
where I: IntoIterator<Item = Self::Masked>;
fn slice(array: &Self::Array, offset: usize, length: usize) -> Self::Array;
fn from_array_data(data: ArrayData) -> Self::Array;
fn format(&self, f: &mut Formatter<'_>) -> Result;
// Provided methods
fn from_iter<I>(iter: I) -> Self::Array
where I: IntoIterator<Item = Self> { ... }
unsafe fn from_trusted_len_iter<I>(iter: I) -> Self::Array
where I: IntoIterator<Item = Self> { ... }
}
Expand description
A trait for data that can be stored as in a tensor.
Required Associated Constants§
const TENSOR_TYPE: TensorType
Required Associated Types§
Sourcetype Masked: TensorValue<Array = Self::Array>
type Masked: TensorValue<Array = Self::Array>
Masked value type. For Option<T>
this is Option<T>
.
For all other T
this should be Option<T>
.
Sourcetype Unmasked: TensorValue<Array = Self::Array>
type Unmasked: TensorValue<Array = Self::Array>
Unmasked value type. For Option<T>
this is T
. For all other T
this should be T
.
Required Methods§
Sourcefn value(array: &Self::Array, i: usize) -> Self
fn value(array: &Self::Array, i: usize) -> Self
Returns the value at index i
in array
.
Panics if i >= array.len()
.
Sourceunsafe fn value_unchecked(array: &Self::Array, i: usize) -> Self
unsafe fn value_unchecked(array: &Self::Array, i: usize) -> Self
Returns the value at index i
without bounds checking.
§Safety
Calling this method where i >= array.len()
is undefined behavior.
Sourcefn to_masked(value: Self) -> Self::Masked
fn to_masked(value: Self) -> Self::Masked
Wrap value
in its masked type.
For Option<T>
this is a no-op. For all other types this returns Some(T)
.
Sourcefn to_unmasked(value: Self) -> Self::Unmasked
fn to_unmasked(value: Self) -> Self::Unmasked
Unwrap the inner value from its masked type.
For Option<T>
this method panics unless value
is Some(T)
.
For all other types this is a no-op.
Sourcefn from_iter_masked<I>(iter: I) -> Self::Arraywhere
I: IntoIterator<Item = Self::Masked>,
fn from_iter_masked<I>(iter: I) -> Self::Arraywhere
I: IntoIterator<Item = Self::Masked>,
Constructs an array from an iterator of masked values.
fn from_vec(values: Vec<Self>) -> Self::Array
Sourceunsafe fn from_trusted_len_iter_masked<I>(iter: I) -> Self::Arraywhere
I: IntoIterator<Item = Self::Masked>,
unsafe fn from_trusted_len_iter_masked<I>(iter: I) -> Self::Arraywhere
I: IntoIterator<Item = Self::Masked>,
Constructs an array from an iterator of masked values.
iter
must implement ExactSizeIterator
.
§Safety
Calling this method with an iterator that doesn’t correctly report its length is undefined behavior.
Sourcefn slice(array: &Self::Array, offset: usize, length: usize) -> Self::Array
fn slice(array: &Self::Array, offset: usize, length: usize) -> Self::Array
Returns a slice of array
from offset
to offset + length
.
Panics if offset + length
> array.len()
.
Sourcefn from_array_data(data: ArrayData) -> Self::Array
fn from_array_data(data: ArrayData) -> Self::Array
Constructs an array from ArrayData
.
Panics if data
is not convertable to Self::Array
.
Provided Methods§
Sourcefn from_iter<I>(iter: I) -> Self::Arraywhere
I: IntoIterator<Item = Self>,
fn from_iter<I>(iter: I) -> Self::Arraywhere
I: IntoIterator<Item = Self>,
Constructs an array from an iterator of values.
Sourceunsafe fn from_trusted_len_iter<I>(iter: I) -> Self::Arraywhere
I: IntoIterator<Item = Self>,
unsafe fn from_trusted_len_iter<I>(iter: I) -> Self::Arraywhere
I: IntoIterator<Item = Self>,
Constructs an array from an iterator of values.
iter
must implement ExactSizeIterator
.
§Safety
Calling this method with an iterator that doesn’t correctly report its length is undefined behavior.
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.