Skip to main content

NamedTensor

Struct NamedTensor 

Source
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,

Source

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).

Source

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.

Source

pub fn tensor(&self) -> &Tensor<T>

Borrow the underlying float tensor. Use this at op boundaries where the named annotation isn’t propagated.

Source

pub fn into_tensor(self) -> Tensor<T>

Consume and return the inner tensor (drops names).

Source

pub fn names(&self) -> &[Option<String>]

Per-dim names (length = ndim).

Source

pub fn shape(&self) -> &[usize]

Logical shape (alias for tensor().shape()).

Source

pub fn ndim(&self) -> usize

Number of dimensions.

Source

pub fn numel(&self) -> usize

Total elements.

Source

pub fn dim_index(&self, name: &str) -> Option<usize>

Index of the dim with the given name, if any.

Source

pub fn size_of(&self, name: &str) -> Option<usize>

Size of the dim with the given name, or None if not found.

Source

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.

Source

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.

Source

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>
where T: Clone + Float,

Source§

fn clone(&self) -> NamedTensor<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for NamedTensor<T>
where T: Debug + Float,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> Display for NamedTensor<T>
where T: Float,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,