pub struct NamedTensor<T>where
T: Float,{ /* private fields */ }Expand description
A Tensor<T> paired with one optional dim name per axis.
names.len() always equals inner.ndim(). Each entry is either
Some(String) (the axis has a name) or None (anonymous).
Implementations§
Source§impl<T> NamedTensor<T>where
T: Float,
impl<T> NamedTensor<T>where
T: Float,
Sourcepub fn new(
inner: Tensor<T>,
names: Vec<Option<String>>,
) -> Result<NamedTensor<T>, FerrotorchError>
pub fn new( inner: Tensor<T>, names: Vec<Option<String>>, ) -> Result<NamedTensor<T>, FerrotorchError>
Wrap a tensor with explicit per-dim names.
Errors if names.len() != inner.ndim() or two names are equal
(and not both None).
Sourcepub fn refined(
inner: Tensor<T>,
names: &[&str],
) -> Result<NamedTensor<T>, FerrotorchError>
pub fn refined( inner: Tensor<T>, names: &[&str], ) -> Result<NamedTensor<T>, FerrotorchError>
Wrap with a flat &[&str] of names; convenient for the common
fully-named case. Use "" to leave a dim anonymous.
Sourcepub fn tensor(&self) -> &Tensor<T>
pub fn tensor(&self) -> &Tensor<T>
Borrow the underlying float tensor. Use this at op boundaries where the named annotation isn’t propagated.
Sourcepub fn into_tensor(self) -> Tensor<T>
pub fn into_tensor(self) -> Tensor<T>
Consume and return the inner tensor (drops names).
Sourcepub fn dim_index(&self, name: &str) -> Option<usize>
pub fn dim_index(&self, name: &str) -> Option<usize>
Index of the dim with the given name, if any.
Sourcepub fn size_of(&self, name: &str) -> Option<usize>
pub fn size_of(&self, name: &str) -> Option<usize>
Size of the dim with the given name, or None if not found.
Sourcepub fn rename(
&self,
mapping: &[(&str, &str)],
) -> Result<NamedTensor<T>, FerrotorchError>
pub fn rename( &self, mapping: &[(&str, &str)], ) -> Result<NamedTensor<T>, FerrotorchError>
Replace some dim names according to mapping: [(old, new), ...].
Names not in the mapping are kept as-is. None names are unchanged.
Sourcepub fn align_to(
&self,
target_names: &[&str],
) -> Result<NamedTensor<T>, FerrotorchError>
pub fn align_to( &self, target_names: &[&str], ) -> Result<NamedTensor<T>, FerrotorchError>
Return a new NamedTensor whose dims are permuted to match
target_names. target_names must contain every named dim of
self (and only those); anonymous dims are not allowed in
target_names since the permutation is name-driven.
Sourcepub fn detached(&self) -> NamedTensor<T>
pub fn detached(&self) -> NamedTensor<T>
Drop names and return an unnamed NamedTensor (i.e. all None).
Useful before passing into ops that don’t preserve names.
Trait Implementations§
Source§impl<T> Clone for NamedTensor<T>
impl<T> Clone for NamedTensor<T>
Source§fn clone(&self) -> NamedTensor<T>
fn clone(&self) -> NamedTensor<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> Debug for NamedTensor<T>
impl<T> Debug for NamedTensor<T>
Auto Trait Implementations§
impl<T> Freeze for NamedTensor<T>
impl<T> !RefUnwindSafe for NamedTensor<T>
impl<T> Send for NamedTensor<T>
impl<T> Sync for NamedTensor<T>
impl<T> Unpin for NamedTensor<T>
impl<T> UnsafeUnpin for NamedTensor<T>
impl<T> !UnwindSafe for NamedTensor<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more