NEML2 2.0.0
Loading...
Searching...
No Matches
LabeledAxisAccessor Class Reference

The accessor containing all the information needed to access an item in a LabeledAxis. More...

Detailed Description

The accessor containing all the information needed to access an item in a LabeledAxis.

The accessor consists of an arbitrary number of item names. The last item name can be either a variable name or a sub-axis name. All the other item names are considered to be sub-axis names.

The LabeledAxisAccessor stores the item labels and does not resolve the actual layout of the item. This way an accessor can be used access the same variable from different tensor layouts.

The item names cannot contain whitespace, ".", ",", ";", or "/".

#include <LabeledAxisAccessor.h>

Public Types

using iterator = c10::SmallVector<std::string>::iterator
 
using const_iterator = c10::SmallVector<std::string>::const_iterator
 

Public Member Functions

 LabeledAxisAccessor ()=default
 
template<typename... S>
 LabeledAxisAccessor (const char *name, S &&... names)
 
template<typename... S>
 LabeledAxisAccessor (const std::string &name, S &&... names)
 
template<typename Container , typename = typename std::enable_if_t< !std::is_convertible_v<Container, std::string> && std::is_convertible_v<typename std::iterator_traits< decltype(std::declval<Container>().begin())>::value_type, std::string> && std::is_convertible_v<typename std::iterator_traits< decltype(std::declval<Container>().end())>::value_type, std::string > > >
 LabeledAxisAccessor (const Container &c)
 
 operator std::vector< std::string > () const
 
const c10::SmallVector< std::string > & vec () const
 
bool empty () const
 
size_t size () const
 
const std::string & operator[] (size_t i) const
 
LabeledAxisAccessor with_suffix (const std::string &suffix) const
 Append a suffix to the final item name.
 
LabeledAxisAccessor append (const LabeledAxisAccessor &axis) const
 Append another accessor.
 
LabeledAxisAccessor prepend (const LabeledAxisAccessor &axis) const
 Prepend another accessor.
 
LabeledAxisAccessor slice (int64_t n) const
 Remove the leading n items from the labels.
 
LabeledAxisAccessor slice (int64_t n1, int64_t n2) const
 Extract out the labels from n1 to n2.
 
LabeledAxisAccessor remount (const LabeledAxisAccessor &axis, int64_t n=1) const
 A combination of slice and prepend.
 
bool start_with (const LabeledAxisAccessor &axis) const
 Check if this accessor begins with another accessor.
 
LabeledAxisAccessor current () const
 Returns the "current" counterpart.
 
LabeledAxisAccessor old () const
 Returns the "old" counterpart.
 
Iterators

Begin and end iterators for the underlying data.

iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
bool is_state () const
 
bool is_old_state () const
 
bool is_force () const
 
bool is_old_force () const
 
bool is_residual () const
 
bool is_parameter () const
 

Member Typedef Documentation

◆ const_iterator

using const_iterator = c10::SmallVector<std::string>::const_iterator

◆ iterator

using iterator = c10::SmallVector<std::string>::iterator

Constructor & Destructor Documentation

◆ LabeledAxisAccessor() [1/4]

LabeledAxisAccessor ( )
default

◆ LabeledAxisAccessor() [2/4]

template<typename... S>
LabeledAxisAccessor ( const char * name,
S &&... names )
inline

◆ LabeledAxisAccessor() [3/4]

template<typename... S>
LabeledAxisAccessor ( const std::string & name,
S &&... names )
inline

◆ LabeledAxisAccessor() [4/4]

template<typename Container , typename = typename std::enable_if_t< !std::is_convertible_v<Container, std::string> && std::is_convertible_v<typename std::iterator_traits< decltype(std::declval<Container>().begin())>::value_type, std::string> && std::is_convertible_v<typename std::iterator_traits< decltype(std::declval<Container>().end())>::value_type, std::string > > >
LabeledAxisAccessor ( const Container & c)
inline

Member Function Documentation

◆ append()

Append another accessor.

◆ begin() [1/2]

iterator begin ( )
inline

◆ begin() [2/2]

const_iterator begin ( ) const
inline

◆ current()

LabeledAxisAccessor current ( ) const

Returns the "current" counterpart.

◆ empty()

bool empty ( ) const

◆ end() [1/2]

iterator end ( )
inline

◆ end() [2/2]

const_iterator end ( ) const
inline

◆ is_force()

bool is_force ( ) const

◆ is_old_force()

bool is_old_force ( ) const

◆ is_old_state()

bool is_old_state ( ) const

◆ is_parameter()

bool is_parameter ( ) const

◆ is_residual()

bool is_residual ( ) const

◆ is_state()

bool is_state ( ) const

Check if the accessor is on a specific sub-axis

◆ old()

LabeledAxisAccessor old ( ) const

Returns the "old" counterpart.

◆ operator std::vector< std::string >()

operator std::vector< std::string > ( ) const
explicit

◆ operator[]()

const std::string & operator[] ( size_t i) const

◆ prepend()

Prepend another accessor.

◆ remount()

LabeledAxisAccessor remount ( const LabeledAxisAccessor & axis,
int64_t n = 1 ) const

A combination of slice and prepend.

◆ size()

size_t size ( ) const

◆ slice() [1/2]

LabeledAxisAccessor slice ( int64_t n) const

Remove the leading n items from the labels.

◆ slice() [2/2]

LabeledAxisAccessor slice ( int64_t n1,
int64_t n2 ) const

Extract out the labels from n1 to n2.

◆ start_with()

bool start_with ( const LabeledAxisAccessor & axis) const

Check if this accessor begins with another accessor.

◆ vec()

const c10::SmallVector< std::string > & vec ( ) const
inline

◆ with_suffix()

LabeledAxisAccessor with_suffix ( const std::string & suffix) const

Append a suffix to the final item name.