NEML2 1.4.0
Loading...
Searching...
No Matches
neml2::utils Namespace Reference

Functions

std::stringstream & operator>> (std::stringstream &in, torch::Tensor &)
 This is a dummy to prevent compilers whining about not know how to >> torch::Tensor.
 
std::string demangle (const char *name)
 
std::vector< std::string > split (const std::string &str, const std::string &delims)
 
std::string trim (const std::string &str, const std::string &white_space)
 
bool start_with (std::string_view str, std::string_view prefix)
 
bool end_with (std::string_view str, std::string_view suffix)
 
template<>
bool parse< bool > (const std::string &raw_str)
 
template<>
VariableName parse< VariableName > (const std::string &raw_str)
 
template<>
TorchShape parse< TorchShape > (const std::string &raw_str)
 
TorchSize storage_size (TorchShapeRef shape)
 The flattened storage size of a tensor with given shape.
 
TorchShape pad_prepend (TorchShapeRef s, TorchSize dim, TorchSize pad=1)
 Pad shape s to dimension dim by prepending sizes of pad.
 
TorchShape pad_append (TorchShapeRef s, TorchSize dim, TorchSize pad=1)
 Pad shape s to dimension dim by appending sizes of pad.
 
std::string indentation (int level, int indent)
 
bool allclose (const LabeledVector &a, const LabeledVector &b, Real rtol, Real atol)
 
template<typename T >
parse (const std::string &raw_str)
 
template<typename T >
std::vector< T > parse_vector (const std::string &raw_str)
 
template<typename T >
std::vector< std::vector< T > > parse_vector_vector (const std::string &raw_str)
 
template<>
bool parse< bool > (const std::string &raw_str)
 
template<>
TorchShape parse< TorchShape > (const std::string &raw_str)
 
template<>
VariableName parse< VariableName > (const std::string &raw_str)
 
template<class... T>
bool sizes_same (T &&... shapes)
 Check if all shapes are the same.
 
template<class... T>
bool sizes_broadcastable (T &&... shapes)
 Check if the shapes are broadcastable.
 
template<class... T>
TorchShape broadcast_sizes (T &&... shapes)
 Return the broadcast shape of all the shapes.
 
template<typename... S>
TorchShape add_shapes (S &&... shape)
 
template<typename T >
std::string stringify (const T &t)
 
template<>
std::string stringify (const bool &t)
 

Function Documentation

◆ add_shapes()

template<typename... S>
TorchShape add_shapes ( S &&... shape)

◆ allclose()

bool allclose ( const LabeledVector & a,
const LabeledVector & b,
Real rtol,
Real atol )

◆ broadcast_sizes()

template<class... T>
TorchShape broadcast_sizes ( T &&... shapes)

Return the broadcast shape of all the shapes.

◆ demangle()

std::string demangle ( const char * name)

◆ end_with()

bool end_with ( std::string_view str,
std::string_view suffix )

◆ indentation()

std::string indentation ( int level,
int indent )

◆ operator>>()

std::stringstream & operator>> ( std::stringstream & in,
torch::Tensor &  )

This is a dummy to prevent compilers whining about not know how to >> torch::Tensor.

◆ pad_append()

TorchShape pad_append ( TorchShapeRef s,
TorchSize dim,
TorchSize pad = 1 )

Pad shape s to dimension dim by appending sizes of pad.

Parameters
sThe original shape to pad
dimThe resulting dimension
padThe values used to pad the shape, default to 1
Returns
TorchShape The padded shape with dimension dim

◆ pad_prepend()

TorchShape pad_prepend ( TorchShapeRef s,
TorchSize dim,
TorchSize pad = 1 )

Pad shape s to dimension dim by prepending sizes of pad.

Parameters
sThe original shape to pad
dimThe resulting dimension
padThe values used to pad the shape, default to 1
Returns
TorchShape The padded shape with dimension dim

◆ parse()

template<typename T >
T parse ( const std::string & raw_str)

◆ parse< bool >() [1/2]

template<>
bool parse< bool > ( const std::string & raw_str)

◆ parse< bool >() [2/2]

template<>
bool parse< bool > ( const std::string & raw_str)

◆ parse< TorchShape >() [1/2]

template<>
TorchShape parse< TorchShape > ( const std::string & raw_str)

◆ parse< TorchShape >() [2/2]

template<>
TorchShape parse< TorchShape > ( const std::string & raw_str)

◆ parse< VariableName >() [1/2]

template<>
VariableName parse< VariableName > ( const std::string & raw_str)

◆ parse< VariableName >() [2/2]

template<>
VariableName parse< VariableName > ( const std::string & raw_str)

◆ parse_vector()

template<typename T >
std::vector< T > parse_vector ( const std::string & raw_str)

◆ parse_vector_vector()

template<typename T >
std::vector< std::vector< T > > parse_vector_vector ( const std::string & raw_str)

◆ sizes_broadcastable()

template<class... T>
bool sizes_broadcastable ( T &&... shapes)

Check if the shapes are broadcastable.

Shapes are said to be broadcastable if, starting from the trailing dimension and iterating backward, the dimension sizes either are equal, one of them is 1, or one of them does not exist.

◆ sizes_same()

template<class... T>
bool sizes_same ( T &&... shapes)

Check if all shapes are the same.

◆ split()

std::vector< std::string > split ( const std::string & str,
const std::string & delims )

◆ start_with()

bool start_with ( std::string_view str,
std::string_view prefix )

◆ storage_size()

TorchSize storage_size ( TorchShapeRef shape)

The flattened storage size of a tensor with given shape.

For example,

storage_size({}) == 1;
storage_size({0}) == 0;
storage_size({1}) == 1;
storage_size({1, 2, 3}) == 6;
storage_size({5, 1, 1}) == 5;
TorchSize storage_size(TorchShapeRef shape)
The flattened storage size of a tensor with given shape.
Definition utils.cxx:32

◆ stringify() [1/2]

template<>
std::string stringify ( const bool & t)
inline

◆ stringify() [2/2]

template<typename T >
std::string stringify ( const T & t)

◆ trim()

std::string trim ( const std::string & str,
const std::string & white_space )