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

Functions

template<>
bool parse_ (bool &val, const std::string &raw_str)
 
template<>
bool parse_vector_ (std::vector< bool > &vals, const std::string &raw_str)
 
template<>
bool parse_ (VariableName &val, const std::string &raw_str)
 
template<>
bool parse_ (TensorShape &val, const std::string &raw_str)
 
template<>
Device parse (const std::string &raw_str)
 
template<>
bool parse_ (Device &val, const std::string &raw_str)
 
std::string demangle (const char *name)
 Demangle a piece of cxx abi type information.
 
std::string join (const std::vector< std::string > &strs, const std::string &delim)
 
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)
 
std::pair< std::vector< Tensor >, Sizealign_intmd_dim (TensorList tensors)
 
std::pair< std::vector< Tensor >, Sizealign_static_dim (TensorList tensors)
 
TraceableSize traceable_numel (const TraceableTensorShape &shape)
 Get the number of elements in a tensor shape.
 
TraceableTensorShape extract_traceable_sizes (const ATensor &tensor, std::size_t n, std::size_t m)
 
std::shared_ptr< jit::Graph > last_executed_optimized_graph ()
 Print last evaluated optimized graph.
 
Size normalize_dim (Size d, Size dl, Size du)
 Helper function to normalize a dimension index to be non-negative given the lower- and upper-bound of the context.
 
Size normalize_itr (Size d, Size dl, Size du)
 Helper function to normalize a iterator-like index to be non-negative given the lower- and upper-bound of the context.
 
Size numel (TensorShapeRef shape)
 Number of elements in a tensor with given shape.
 
TensorShape pad_prepend (TensorShapeRef s, Size dim, Size pad=1)
 Pad shape s to dimension dim by prepending sizes of pad.
 
TraceableTensorShape broadcast_dynamic_sizes (const std::vector< Tensor > &tensors)
 Find the broadcast dynamic shape of all the tensors The returned dynamic shape will be traceable.
 
template<typename T >
std::string parse_failure_message (const std::string &raw_str)
 
template<typename T >
bool parse_ (T &val, const std::string &raw_str)
 
template<typename T >
parse (const std::string &raw_str)
 
template<typename T >
bool parse_vector_ (std::vector< T > &vals, const std::string &raw_str)
 
template<typename T >
std::vector< T > parse_vector (const std::string &raw_str)
 
template<typename T >
bool parse_vector_vector_ (std::vector< std::vector< T > > &vals, 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 > (bool &, const std::string &raw_str)
 
template<>
bool parse_vector_< bool > (std::vector< bool > &, const std::string &raw_str)
 This special one is for the evil std::vector<bool>!
 
template<>
bool parse_< TensorShape > (TensorShape &, const std::string &raw_str)
 
template<>
bool parse_< VariableName > (VariableName &, const std::string &raw_str)
 
template<>
Device parse< Device > (const std::string &raw_str)
 
template<>
bool parse_< Device > (Device &, const std::string &raw_str)
 
template<typename T , typename... Args>
void stream_all (std::ostringstream &ss, T &&val, Args &&... args)
 
template<typename T >
std::string stringify (const T &t)
 
template<>
std::string stringify (const bool &t)
 
template<typename T , typename... Ts>
std::tuple< T, Ts..., Sizealign_intmd_dim (const T &a, const Ts &... ts)
 
template<typename T , typename... Ts>
std::tuple< T, Ts..., Sizealign_static_dim (const T &a, const Ts &... ts)
 
template<typename... S>
TraceableTensorShape add_traceable_shapes (const S &... shape)
 
template<class... T>
bool sizes_broadcastable (const T &... shapes)
 Check if the shapes are broadcastable.
 
template<class... T>
bool broadcastable (const T &... tensors)
 
template<class... T>
bool dynamic_broadcastable (const T &... tensors)
 
template<class... T>
bool intmd_broadcastable (const T &... tensors)
 
template<class... T>
bool base_broadcastable (const T &... tensors)
 
template<class... T>
Size broadcast_dynamic_dim (const T &...)
 The dynamic dimension after broadcasting.
 
template<class... T>
Size broadcast_intmd_dim (const T &...)
 The intermediate dimension after broadcasting.
 
template<class... T>
Size broadcast_base_dim (const T &...)
 The base dimension after broadcasting.
 
template<class... T>
TensorShape broadcast_sizes (const T &... shapes)
 Return the broadcast shape of all the shapes.
 
template<typename... S>
TensorShape add_shapes (const S &...)
 
template<class... T>
Size broadcast_dynamic_dim (const T &... tensor)
 
template<class... T>
Size broadcast_intmd_dim (const T &... tensor)
 
template<class... T>
Size broadcast_base_dim (const T &... tensor)
 
template<typename... S>
TensorShape add_shapes (const S &... shape)
 

Function Documentation

◆ add_shapes() [1/2]

template<typename... S>
TensorShape add_shapes ( const S &... shape)

◆ add_shapes() [2/2]

template<typename... S>
TensorShape add_shapes ( const S & ...)

◆ add_traceable_shapes()

template<typename... S>
TraceableTensorShape add_traceable_shapes ( const S &... shape)

◆ align_intmd_dim() [1/2]

template<typename T , typename... Ts>
std::tuple< T, Ts..., Size > align_intmd_dim ( const T & a,
const Ts &... ts )

◆ align_intmd_dim() [2/2]

std::pair< std::vector< Tensor >, Size > align_intmd_dim ( TensorList tensors)

◆ align_static_dim() [1/2]

template<typename T , typename... Ts>
std::tuple< T, Ts..., Size > align_static_dim ( const T & a,
const Ts &... ts )

◆ align_static_dim() [2/2]

std::pair< std::vector< Tensor >, Size > align_static_dim ( TensorList tensors)

◆ base_broadcastable()

template<class... T>
bool base_broadcastable ( const T &... tensors)

Test if the tensors are base-broadcastable.

See also
sizes_broadcastable

◆ broadcast_base_dim() [1/2]

template<class... T>
Size broadcast_base_dim ( const T &... tensor)

◆ broadcast_base_dim() [2/2]

template<class... T>
Size broadcast_base_dim ( const T & ...)

The base dimension after broadcasting.

◆ broadcast_dynamic_dim() [1/2]

template<class... T>
Size broadcast_dynamic_dim ( const T &... tensor)

◆ broadcast_dynamic_dim() [2/2]

template<class... T>
Size broadcast_dynamic_dim ( const T & ...)

The dynamic dimension after broadcasting.

◆ broadcast_dynamic_sizes()

TraceableTensorShape broadcast_dynamic_sizes ( const std::vector< Tensor > & tensors)

Find the broadcast dynamic shape of all the tensors The returned dynamic shape will be traceable.

See also
neml2::TraceableTensorShape

Pre-pad ones to the shapes

Braodcast

◆ broadcast_intmd_dim() [1/2]

template<class... T>
Size broadcast_intmd_dim ( const T &... tensor)

◆ broadcast_intmd_dim() [2/2]

template<class... T>
Size broadcast_intmd_dim ( const T & ...)

The intermediate dimension after broadcasting.

◆ broadcast_sizes()

template<class... T>
TensorShape broadcast_sizes ( const T &... shapes)

Return the broadcast shape of all the shapes.

◆ broadcastable()

template<class... T>
bool broadcastable ( const T &... tensors)

Two tensors are said to be broadcastable if

  1. Base shapes are broadcastable
  2. Intermediate shapes are broadcastable
  3. Dynamic shapes are broadcastable

◆ demangle()

std::string demangle ( const char * name)

Demangle a piece of cxx abi type information.

◆ dynamic_broadcastable()

template<class... T>
bool dynamic_broadcastable ( const T &... tensors)

Test if the tensors are dynamic-broadcastable.

See also
sizes_broadcastable

◆ end_with()

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

◆ extract_traceable_sizes()

TraceableTensorShape extract_traceable_sizes ( const ATensor & tensor,
std::size_t n,
std::size_t m )

Extract m sizes starting from dimension n of a tensor The extracted shape will be traceable.

See also
neml2::TraceableTensorShape

◆ intmd_broadcastable()

template<class... T>
bool intmd_broadcastable ( const T &... tensors)

Test if the tensors are intermediate-broadcastable.

See also
sizes_broadcastable

◆ join()

std::string join ( const std::vector< std::string > & strs,
const std::string & delim )

◆ last_executed_optimized_graph()

std::shared_ptr< jit::Graph > last_executed_optimized_graph ( )

Print last evaluated optimized graph.

◆ normalize_dim()

Size normalize_dim ( Size d,
Size dl,
Size du )

Helper function to normalize a dimension index to be non-negative given the lower- and upper-bound of the context.

Parameters
dThe dimension index to normalize
dlThe lower-bound (inclusive)
duThe upper-bound (exclusive)
Returns
Size The normalized dimension index

◆ normalize_itr()

Size normalize_itr ( Size d,
Size dl,
Size du )

Helper function to normalize a iterator-like index to be non-negative given the lower- and upper-bound of the context.

Parameters
dThe iterator index to normalize
dlThe lower-bound (inclusive)
duThe upper-bound (exclusive)
Returns
Size The normalized iterator index

◆ numel()

Size numel ( TensorShapeRef shape)

Number of elements in a tensor with given shape.

For example,

numel({}) == 1;
numel({0}) == 0;
numel({1}) == 1;
numel({1, 2, 3}) == 6;
numel({5, 1, 1}) == 5;
Size numel(TensorShapeRef shape)
Number of elements in a tensor with given shape.
Definition shape_utils.cxx:64

◆ pad_prepend()

TensorShape pad_prepend ( TensorShapeRef s,
Size dim,
Size 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
TensorShape The padded shape with dimension dim

◆ parse() [1/2]

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

◆ parse() [2/2]

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

◆ parse< Device >()

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

◆ parse_() [1/5]

template<>
bool parse_ ( bool & val,
const std::string & raw_str )

◆ parse_() [2/5]

template<>
bool parse_ ( Device & val,
const std::string & raw_str )

◆ parse_() [3/5]

template<typename T >
bool parse_ ( T & val,
const std::string & raw_str )

◆ parse_() [4/5]

template<>
bool parse_ ( TensorShape & val,
const std::string & raw_str )

◆ parse_() [5/5]

template<>
bool parse_ ( VariableName & val,
const std::string & raw_str )

◆ parse_< bool >()

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

◆ parse_< Device >()

template<>
bool parse_< Device > ( Device & ,
const std::string & raw_str )

◆ parse_< TensorShape >()

template<>
bool parse_< TensorShape > ( TensorShape & ,
const std::string & raw_str )

◆ parse_< VariableName >()

template<>
bool parse_< VariableName > ( VariableName & ,
const std::string & raw_str )

◆ parse_failure_message()

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

◆ parse_vector()

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

◆ parse_vector_() [1/2]

template<>
bool parse_vector_ ( std::vector< bool > & vals,
const std::string & raw_str )

◆ parse_vector_() [2/2]

template<typename T >
bool parse_vector_ ( std::vector< T > & vals,
const std::string & raw_str )

◆ parse_vector_< bool >()

template<>
bool parse_vector_< bool > ( std::vector< bool > & ,
const std::string & raw_str )

This special one is for the evil std::vector<bool>!

◆ parse_vector_vector()

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

◆ parse_vector_vector_()

template<typename T >
bool parse_vector_vector_ ( std::vector< std::vector< T > > & vals,
const std::string & raw_str )

◆ sizes_broadcastable()

template<class... T>
bool sizes_broadcastable ( const 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.

◆ 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 )

◆ stream_all()

template<typename T , typename... Args>
void stream_all ( std::ostringstream & ss,
T && val,
Args &&... args )

◆ stringify() [1/2]

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

◆ stringify() [2/2]

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

◆ traceable_numel()

TraceableSize traceable_numel ( const TraceableTensorShape & shape)

Get the number of elements in a tensor shape.

◆ trim()

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