Struct metatensor::Labels

source ·
pub struct Labels { /* private fields */ }
Expand description

A set of labels used to carry metadata associated with a tensor map.

This is similar to a list of named tuples, but stored as a 2D array of shape (labels.count(), labels.size()), with a of set names associated with the columns of this array. Each row/entry in this array is unique, and they are often (but not always) sorted in lexicographic order.

The main way to construct a new set of labels is to use a LabelsBuilder.

Labels are internally reference counted and immutable, so cloning a Labels should be a cheap operation.

Implementations§

source§

impl Labels

source

pub fn new<T, const N: usize>(names: [&str; N], values: &[[T; N]]) -> Labelswhere T: Copy + Into<LabelValue>,

Create a new set of Labels with the given names and values.

This is a convenience function replacing the manual use of LabelsBuilder. If you need more flexibility or incremental Labels construction, use LabelsBuilder.

Panics

If the set of names is not valid, or any of the value is duplicated

source

pub fn empty(names: Vec<&str>) -> Labels

Create a set of Labels with the given names, containing no entries.

source

pub fn single() -> Labels

Create a set of Labels containing a single entry, to be used when there is no relevant information to store.

source

pub fn size(&self) -> usize

Get the number of entries/named values in a single label

source

pub fn names(&self) -> Vec<&str>

Get the names of the entries/columns in this set of labels

source

pub fn count(&self) -> usize

Get the total number of entries in this set of labels

source

pub fn is_empty(&self) -> bool

Check if this set of Labels is empty (contains no entry)

source

pub fn contains(&self, label: &[LabelValue]) -> bool

Check whether the given label is part of this set of labels

source

pub fn position(&self, value: &[LabelValue]) -> Option<usize>

Get the position (i.e. row index) of the given label in the full labels array, or None.

source

pub fn union( &self, other: &Labels, first_mapping: Option<&mut [i64]>, second_mapping: Option<&mut [i64]> ) -> Result<Labels, Error>

Take the union of self with other.

If requested, this function can also give the positions in the union where each entry of the input Labels ended up.

If first_mapping (respectively second_mapping) is Some, it should contain a slice of length self.count() (respectively other.count()) that will be filled with the position of the entries in self (respectively other) in the union.

source

pub fn intersection( &self, other: &Labels, first_mapping: Option<&mut [i64]>, second_mapping: Option<&mut [i64]> ) -> Result<Labels, Error>

Take the intersection of self with other.

If requested, this function can also give the positions in the intersection where each entry of the input Labels ended up.

If first_mapping (respectively second_mapping) is Some, it should contain a slice of length self.count() (respectively other.count()) that will be filled by with the position of the entries in self (respectively other) in the intersection. If an entry in self or other are not used in the intersection, the mapping for this entry will be set to -1.

source

pub fn iter(&self) -> LabelsIter<'_>

Iterate over the entries in this set of labels

source

pub fn iter_fixed_size<const N: usize>(&self) -> LabelsFixedSizeIter<'_, N>

Iterate over the entries in this set of labels as fixed-size arrays

source§

impl Labels

source

pub unsafe fn from_raw(raw: mts_labels_t) -> Labels

Create a new set of Labels from a raw mts_labels_t.

This function takes ownership of the mts_labels_t and will call mts_labels_free on it.

Safety

The raw mts_labels_t must have been returned by one of the function returning mts_labels_t in metatensor-core

Trait Implementations§

source§

impl Clone for Labels

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Labels

source§

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

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

impl Drop for Labels

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Index<usize> for Labels

§

type Output = [LabelValue]

The returned type after indexing.
source§

fn index(&self, i: usize) -> &[LabelValue]

Performs the indexing (container[index]) operation. Read more
source§

impl<'a> IntoIterator for &'a Labels

§

type IntoIter = LabelsIter<'a>

Which kind of iterator are we turning this into?
§

type Item = &'a [LabelValue]

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl PartialEq<Labels> for Labels

source§

fn eq(&self, other: &Labels) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Send for Labels

source§

impl Sync for Labels

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.