NEML2 1.4.0
Loading...
Searching...
No Matches
LabeledAxis Class Reference

A labeled axis used to associate layout of a tensor with human-interpretable names. More...

Detailed Description

A labeled axis used to associate layout of a tensor with human-interpretable names.

A logically one-dimensional tensor requires one LabeledAxis, two-dimensional tensor requires two LabeledAxis, and so on. See Tensor labeling for a detailed explanation of tensor labeling.

All the LabeledAxis modifiers can only be used during the setup stage. Calling any modifiers after the setup stage is forbidden and will result in a runtime error in Debug mode.

All the modifiers return the modified LabeledAxis by reference, so modifiers can be chained. For example

LabeledAxis labels = input().clone();
labels.add<SR2>("stress").rename("stress", "stress1").remove("stress1");
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
A labeled axis used to associate layout of a tensor with human-interpretable names.
Definition LabeledAxis.h:55
LabeledAxis & rename(const std::string &original, const std::string &rename)
Change the label of an item.
Definition LabeledAxis.cxx:68
LabeledAxis & remove(const std::string &name)
Remove an item.
Definition LabeledAxis.cxx:94
The (logical) symmetric second order tensor.
Definition SR2.h:46

#include <LabeledAxis.h>

Public Types

typedef std::unordered_map< std::string, std::pair< TorchSize, TorchSize > > AxisLayout
 

Public Member Functions

 LabeledAxis ()
 Empty constructor.
 
 LabeledAxis (const LabeledAxis &other)
 (Shallow) copy constructor
 
template<typename T >
LabeledAxisadd (const LabeledAxisAccessor &accessor)
 Add a variable or subaxis.
 
LabeledAxisadd (const LabeledAxisAccessor &accessor, TorchSize sz)
 Add an arbitrary variable using a LabeledAxisAccessor
 
LabeledAxisrename (const std::string &original, const std::string &rename)
 Change the label of an item.
 
LabeledAxisremove (const std::string &name)
 Remove an item.
 
LabeledAxisclear ()
 Clear everything.
 
std::vector< LabeledAxisAccessormerge (LabeledAxis &other)
 Merge with another LabeledAxis.
 
void setup_layout ()
 
size_t nitem () const
 Number of items.
 
size_t nvariable () const
 Number of variables.
 
size_t nsubaxis () const
 Number of subaxes.
 
bool has_item (const LabeledAxisAccessor &name) const
 Does the item exist?
 
template<typename T >
bool has_variable (const LabeledAxisAccessor &var) const
 Does the variable of a given primitive type exist?
 
bool has_variable (const LabeledAxisAccessor &var) const
 Check the existence of a variable by its LabeledAxisAccessor.
 
bool has_subaxis (const LabeledAxisAccessor &s) const
 Check the existence of a subaxis by its LabeledAxisAccessor.
 
TorchSize storage_size () const
 Get the (total) storage size of this axis.
 
TorchSize storage_size (const LabeledAxisAccessor &accessor) const
 Get the storage size of an item by its LabeledAxisAccessor.
 
const AxisLayoutlayout () const
 Get the layout.
 
TorchIndex indices (const LabeledAxisAccessor &accessor) const
 Get the indices of a specific item by a LabeledAxisAccessor
 
TorchIndex indices (const LabeledAxis &other, bool recursive=true, bool inclusive=true) const
 Get the indices using another LabeledAxis.
 
std::vector< std::pair< TorchIndex, TorchIndex > > common_indices (const LabeledAxis &other, bool recursive=true) const
 Get the common indices of two LabeledAxiss.
 
std::vector< std::string > item_names () const
 Get the item names.
 
const std::map< std::string, TorchSize > & variables () const
 Get the variables.
 
const std::map< std::string, std::shared_ptr< LabeledAxis > > & subaxes () const
 Get the subaxes.
 
std::set< LabeledAxisAccessorvariable_accessors (bool recursive=false, const LabeledAxisAccessor &subaxis={}) const
 Get the variable accessors.
 
const LabeledAxissubaxis (const std::string &name) const
 Get a sub-axis.
 
LabeledAxissubaxis (const std::string &name)
 Get a sub-axis.
 
bool equals (const LabeledAxis &other) const
 Check to see if two LabeledAxis objects are equivalent.
 
void to_dot (std::ostream &os, int &id, std::string name="", bool subgraph=false, bool node_handle=false) const
 Write this object in dot format.
 

Friends

std::ostream & operator<< (std::ostream &os, const LabeledAxis &info)
 

Member Typedef Documentation

◆ AxisLayout

typedef std::unordered_map<std::string, std::pair<TorchSize, TorchSize> > AxisLayout

Constructor & Destructor Documentation

◆ LabeledAxis() [1/2]

Empty constructor.

◆ LabeledAxis() [2/2]

(Shallow) copy constructor

Member Function Documentation

◆ add() [1/2]

template<typename T >
LabeledAxis & add ( const LabeledAxisAccessor & accessor)
inline

Add a variable or subaxis.

◆ add() [2/2]

LabeledAxis & add ( const LabeledAxisAccessor & accessor,
TorchSize sz )

Add an arbitrary variable using a LabeledAxisAccessor

◆ clear()

LabeledAxis & clear ( )

Clear everything.

◆ common_indices()

std::vector< std::pair< TorchIndex, TorchIndex > > common_indices ( const LabeledAxis & other,
bool recursive = true ) const

Get the common indices of two LabeledAxiss.

◆ equals()

bool equals ( const LabeledAxis & other) const

Check to see if two LabeledAxis objects are equivalent.

◆ has_item()

bool has_item ( const LabeledAxisAccessor & name) const
inline

Does the item exist?

◆ has_subaxis()

bool has_subaxis ( const LabeledAxisAccessor & s) const

Check the existence of a subaxis by its LabeledAxisAccessor.

◆ has_variable() [1/2]

template<typename T >
bool has_variable ( const LabeledAxisAccessor & var) const
inline

Does the variable of a given primitive type exist?

◆ has_variable() [2/2]

bool has_variable ( const LabeledAxisAccessor & var) const

Check the existence of a variable by its LabeledAxisAccessor.

◆ indices() [1/2]

TorchIndex indices ( const LabeledAxis & other,
bool recursive = true,
bool inclusive = true ) const

Get the indices using another LabeledAxis.

◆ indices() [2/2]

TorchIndex indices ( const LabeledAxisAccessor & accessor) const

Get the indices of a specific item by a LabeledAxisAccessor

◆ item_names()

std::vector< std::string > item_names ( ) const

Get the item names.

◆ layout()

const AxisLayout & layout ( ) const
inline

Get the layout.

◆ merge()

std::vector< LabeledAxisAccessor > merge ( LabeledAxis & other)

Merge with another LabeledAxis.

◆ nitem()

size_t nitem ( ) const
inline

Number of items.

◆ nsubaxis()

size_t nsubaxis ( ) const
inline

Number of subaxes.

◆ nvariable()

size_t nvariable ( ) const
inline

Number of variables.

◆ remove()

LabeledAxis & remove ( const std::string & name)

Remove an item.

◆ rename()

LabeledAxis & rename ( const std::string & original,
const std::string & rename )

Change the label of an item.

◆ setup_layout()

void setup_layout ( )

Setup the layout of all items recursively. The layout of each item is contiguous in memory.

◆ storage_size() [1/2]

TorchSize storage_size ( ) const
inline

Get the (total) storage size of this axis.

◆ storage_size() [2/2]

TorchSize storage_size ( const LabeledAxisAccessor & accessor) const

Get the storage size of an item by its LabeledAxisAccessor.

◆ subaxes()

const std::map< std::string, std::shared_ptr< LabeledAxis > > & subaxes ( ) const
inline

Get the subaxes.

◆ subaxis() [1/2]

LabeledAxis & subaxis ( const std::string & name)

Get a sub-axis.

◆ subaxis() [2/2]

const LabeledAxis & subaxis ( const std::string & name) const

Get a sub-axis.

◆ to_dot()

void to_dot ( std::ostream & os,
int & id,
std::string name = "",
bool subgraph = false,
bool node_handle = false ) const

Write this object in dot format.

◆ variable_accessors()

std::set< LabeledAxisAccessor > variable_accessors ( bool recursive = false,
const LabeledAxisAccessor & subaxis = {} ) const

Get the variable accessors.

◆ variables()

const std::map< std::string, TorchSize > & variables ( ) const
inline

Get the variables.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const LabeledAxis & info )
friend