NEML2 1.4.0
Loading...
Searching...
No Matches
CrossRef< T > Class Template Reference

The wrapper (decorator) for cross-referencing unresolved values at parse time. More...

Detailed Description

template<typename T>
class neml2::CrossRef< T >

The wrapper (decorator) for cross-referencing unresolved values at parse time.

All tokens in the input files are essentially strings, and it is not always possible to represent all quantities as strings. For example, more sophisticated tensor manufacturing methods require inputs like batch size, device type, etc., and cannot be specified with a single string literal. In such scenarios, it is preferable to interpret the string literal as a "label" cross-referencing another object. This wrapper provides cross-referencing capabilities to most input file types. The object name is used as the label, and the object value is not resolved until implicit conversion occurs.

Template Parameters
TThe final resolved type

#include <CrossRef.h>

Public Member Functions

 CrossRef ()=default
 
CrossRef< T > & operator= (const std::string &other)
 Assignment operator.
 
 operator T () const
 Implicit conversion operator.
 
bool operator== (const CrossRef< T > &other) const
 Test equality.
 
const std::string & raw () const
 Get the raw string literal.
 
 operator torch::Tensor () const
 
 operator BatchTensor () const
 

Friends

std::stringstream & operator>> (std::stringstream &in, CrossRef< T > &)
 

Constructor & Destructor Documentation

◆ CrossRef()

template<typename T >
CrossRef ( )
default

Member Function Documentation

◆ operator BatchTensor()

operator BatchTensor ( ) const

◆ operator T()

template<typename T >
operator T ( ) const

Implicit conversion operator.

The underlying string is parsed and used to resolve the cross-reference. It is assumed that the cross-referenced object has already been manufactured at this point.

◆ operator torch::Tensor()

operator torch::Tensor ( ) const

◆ operator=()

template<typename T >
CrossRef< T > & operator= ( const std::string & other)

Assignment operator.

This simply assigns the string without parsing and resolving the cross-reference

◆ operator==()

template<typename T >
bool operator== ( const CrossRef< T > & other) const
inline

Test equality.

◆ raw()

template<typename T >
const std::string & raw ( ) const
inline

Get the raw string literal.

Returns
const std::string& The raw string literal.

Friends And Related Symbol Documentation

◆ operator>>

template<typename T >
std::stringstream & operator>> ( std::stringstream & in,
CrossRef< T > & cr )
friend