aGrUM 3.3.2
a C++ library for (probabilistic) graphical models

About aGrUM utilities. More...

Collaboration diagram for Utilities:

Topics

 Math
 All the maths you'll need.
 Configuration
 About aGrUM configuration.
 Smart Pointers
 RefPtr are a replacement for the usual pointers: they keep track of the number of "smart" pointers pointing to a given element.

Classes

class  gum::Configuration
 Sectioned key/value configuration with typed and documented keys. More...
class  gum::dot::DotOptions
 The options given to a toDot(const DotOptions&). More...
class  gum::dot::DotStyle
 The look shared by all the graphs: size, direction, layout, colors of the arcs and of the nodes. More...
class  gum::dot::DotWriter
 Writes a graph in the dot language, statement after statement, in the order of the calls. More...
template<typename T1, typename T2>
using gum::forbidden_type = typename std::enable_if< !std::is_same< T1, T2 >::value, int >::type
 Forbidden_type<T1,T2> return the "int" type if T1 and T2 are of the same type, else nothing.
bool gum::Memcmp (const void *const in_, const void *const out_, unsigned long size)
 Cross-platform replacement for memcmp.
void gum::_atexit_ ()
 Used for debug purpose.
double gum::almostDifferentEpsilon ()
 The tolerance of AlmostDifferent : the key core.epsilonStandard of the configuration.
template<typename T1, typename T2>
ostream & std::operator<< (ostream &stream, const pair< T1, T2 > &val)
 'std::cout<<' operator for pairs.
template<typename T0, typename... T>
std::ostream & std::operator<< (std::ostream &os, const std::tuple< T0, T... > &t)
 'std::cout<<' operator for vectors.
template<typename T>
ostream & std::operator<< (ostream &stream, const vector< T > &val)
 'std::cout<<' operator for vectors.
template<typename T>
bool std::hasUniqueElts (std::vector< T > const &x)
 

GUM_SHARED_PUBLIC Idx gum::randomValue (const Size max=2)
 Returns a random Idx between 0 and max-1 included.
GUM_SHARED_PUBLIC double gum::randomProba ()
 Returns a random double between 0 and 1 included (i.e.
template<GUM_Numeric GUM_SCALAR>
std::vector< GUM_SCALAR > gum::randomDistribution (Size n)
 Return a random discrete distribution.
GUM_SHARED_PUBLIC unsigned int gum::randomGeneratorSeed ()
 Returns the aGrUM's seed used by the std::generators.
GUM_SHARED_PUBLIC unsigned int gum::currentRandomGeneratorValue ()
 returns the current generator's value
GUM_SHARED_PUBLIC void gum::initRandom (unsigned int seed=0)
 Initialize random generator seed.
GUM_SHARED_PUBLIC std::mt19937 & gum::randomGenerator ()
 define a random_engine with correct seed
std::string gum::getUniqueFileName ()
 Returns a path to a unique file name.
bool gum::endsWith (const std::string_view &value, const std::string_view &ending)
 Returns true if value ends with ending.
std::vector< std::string > gum::split (std::string_view orig, std::string_view delimiter)
 Split str using the delimiter.
std::string gum::replace (std::string_view s, std::string_view val, std::string_view new_val)
 Replace val by new_val in s.
bool gum::isIntegerWithResult (std::string_view val, int *res)
 return true is a string contains an integer value
bool gum::isNumericalWithResult (std::string_view val, double *res)
 return true is a string contains a numerical (double) value
bool gum::parseDecimal (std::string_view val, double &res)
 parse a decimal number, whatever the locale of the program
GUM_SHARED_PUBLIC std::string gum::toLower (std::string_view str)
 Returns the lowercase version of str.
GUM_SHARED_PUBLIC bool gum::contains (std::string_view s, std::string_view needle)
 true if needle in s
GUM_SHARED_PUBLIC bool gum::isInteger (std::string_view val)
 return true is a string contains an integer value
GUM_SHARED_PUBLIC bool gum::isNumerical (std::string_view val)
 return true is a string contains a numerical (double) value
GUM_SHARED_PUBLIC void gum::ltrim (std::string &s)
 trim from start (in place)
GUM_SHARED_PUBLIC void gum::rtrim (std::string &s)
 trim from end (in place)
GUM_SHARED_PUBLIC void gum::trim (std::string &s)
 trim from both ends (in place)
GUM_SHARED_PUBLIC std::string gum::trim_copy (std::string_view s)
 trim from both ends (copying)
GUM_SHARED_PUBLIC std::string gum::remove_newline (std::string_view s)
 remove all newlines in a string
template<typename T>
std::string gum::compact_tostr (T value)
 Returns a path to a unique file name.

Detailed Description

About aGrUM utilities.

Typedef Documentation

◆ forbidden_type

template<typename T1, typename T2>
using gum::forbidden_type = typename std::enable_if< !std::is_same< T1, T2 >::value, int >::type

Forbidden_type<T1,T2> return the "int" type if T1 and T2 are of the same type, else nothing.

Use it as a guard in template specification :

// Creates a template except if T is int or char
template<T,forbidden_type<T,int> =0,forbidden_type<T,char> =0> // ...
Parameters
T1The type to test for.
T2The expected type.

Definition at line 143 of file utils_misc.h.

Function Documentation

◆ _atexit_()

void gum::_atexit_ ( )

Used for debug purpose.

Definition at line 71 of file utils_misc.cpp.

71 {
72#ifdef GUM_DEBUG_MODE
73 gum::__debug__::_atexit_();
74#endif
75 }

References _atexit_().

Referenced by _atexit_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ almostDifferentEpsilon()

GUM_SHARED_PUBLIC double gum::almostDifferentEpsilon ( )

The tolerance of AlmostDifferent : the key core.epsilonStandard of the configuration.

It is a function (and not a direct access to the configuration) because the configuration itself includes this header.

Definition at line 59 of file utils_misc.cpp.

59{ return config().epsilonStandard(); }
double epsilonStandard() const noexcept
Configuration & config()
A short name for Configuration::instance() : gum::config().epsilonStandard(). It is not inline so tha...

References almostDifferentEpsilon(), config(), and gum::Configuration::epsilonStandard().

Referenced by almostDifferentEpsilon().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compact_tostr()

template<typename T>
std::string gum::compact_tostr ( T value)

Returns a path to a unique file name.

Returns
Returns a path to a unique file name.

Definition at line 51 of file utils_string_tpl.h.

51 {
52 std::ostringstream s;
53 s.precision(7);
54 s << value;
55 return s.str();
56 }

References compact_tostr().

Referenced by compact_tostr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ contains()

INLINE bool gum::contains ( std::string_view s,
std::string_view needle )

true if needle in s

Parameters
s
needle*
Returns

Definition at line 67 of file utils_string_inl.h.

67 {
68 return s.find(needle) != std::string_view::npos;
69 }

References contains().

Referenced by gum::learning::IKTBNLearner< GUM_SCALAR >::_checkBaseIsTemporal_(), gum::learning::IKTBNLearner< GUM_SCALAR >::_determineNode_(), gum::CausalModel< GUM_SCALAR >::_toDot_(), contains(), gum::MonteCarloSampling< GUM_SCALAR >::draw_(), gum::WeightedSampling< GUM_SCALAR >::draw_(), gum::Configuration::grep(), gum::MarginalTargetedInference< GUM_SCALAR >::posterior(), and gum::MarginalTargetedMRFInference< GUM_SCALAR >::posterior().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ currentRandomGeneratorValue()

INLINE unsigned int gum::currentRandomGeneratorValue ( )

returns the current generator's value

Definition at line 87 of file utils_random_inl.h.

87{ return _rand_namespace_::generator()(); }
std::mt19937 & generator()

References currentRandomGeneratorValue(), and gum::_rand_namespace_::generator().

Referenced by gum::credal::MultipleInferenceEngine< GUM_SCALAR, LazyPropagation< GUM_SCALAR > >::_updateThreadCredalSets_(), and currentRandomGeneratorValue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ endsWith()

GUM_SHARED_PUBLIC bool gum::endsWith ( const std::string_view & value,
const std::string_view & ending )

Returns true if value ends with ending.

Returns
Returns true if value ends with ending.

Definition at line 83 of file utils_string.cpp.

83 {
84 if (ending.size() > value.size()) return false;
85 return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
86 }

References endsWith().

Referenced by endsWith(), gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveClass(), gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveClassElement(), gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveInterface(), gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveSlotType(), and gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getUniqueFileName()

GUM_SHARED_PUBLIC std::string gum::getUniqueFileName ( )

Returns a path to a unique file name.

Returns
Returns a path to a unique file name.

Definition at line 63 of file utils_string.cpp.

63 {
64 // Get the temporary directory path
65 std::filesystem::path temp_dir = std::filesystem::temp_directory_path();
66
67 // Generate a unique file name using a timestamp and a random number
68 auto now = std::chrono::system_clock::now();
69 auto timestamp
70 = std::chrono::duration_cast< std::chrono::milliseconds >(now.time_since_epoch()).count();
71
72 auto dis = gum::randomValue(1000);
73
74 std::string filename
75 = "tempfile_" + std::to_string(timestamp) + "_" + std::to_string(dis) + ".tmp";
76
77 // Combine the directory path and the file name
78 std::filesystem::path temp_file_path = temp_dir / filename;
79
80 return temp_file_path.string();
81 }
GUM_SHARED_PUBLIC Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.

References getUniqueFileName(), and randomValue().

Referenced by gum::credal::CredalNet< GUM_SCALAR >::_H2Vlrs_(), and getUniqueFileName().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasUniqueElts()

template<typename T>
bool std::hasUniqueElts ( std::vector< T > const & x)

check if a vector consists in unique values (no duplicate).

Template Parameters
TThe vector's elements type.
Parameters
xthe vector
Returns
Returns true if the vector has no duplicate.

Definition at line 109 of file utils_misc_tpl.h.

109 {
110 if (x.size() <= 1) return true;
111 if (x.size() == 2) return x[0] != x[1];
112
113 auto refless = [](T const* l, T const* r) { return *l < *r; };
114 auto refeq = [](T const* l, T const* r) { return *l == *r; };
115
116 std::vector< T const* > vp;
117 vp.reserve(x.size());
118 for (size_t i = 0; i < x.size(); ++i)
119 vp.push_back(&x[i]);
120 sort(vp.begin(), vp.end(), refless); // O(N log N)
121 // if no adjacent pair (vp_n,vp_n+1) has *vp_n == *vp_n+1
122 return std::adjacent_find(vp.begin(), vp.end(), refeq) == vp.end();
123 }

References hasUniqueElts().

Referenced by hasUniqueElts().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initRandom()

INLINE void gum::initRandom ( unsigned int seed = 0)

Initialize random generator seed.

Definition at line 79 of file utils_random_inl.h.

79 {
80 if (seed == 0) seed = (unsigned int)std::chrono::system_clock::now().time_since_epoch().count();
81 std::seed_seq seq{seed + 1, seed + 2, seed + 3, seed + 4, seed + 5};
83 }

References gum::_rand_namespace_::generator(), and initRandom().

Referenced by initRandom().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isInteger()

INLINE bool gum::isInteger ( std::string_view val)

return true is a string contains an integer value

Parameters
sA string
Returns
true if s exactly contains an int (s can start with "-" or "+")

Definition at line 99 of file utils_string_inl.h.

99{ return isIntegerWithResult(val, nullptr); }
bool isIntegerWithResult(std::string_view val, int *res)
return true is a string contains an integer value

References isInteger(), and isIntegerWithResult().

Referenced by fastVariable(), and isInteger().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isIntegerWithResult()

GUM_SHARED_PUBLIC bool gum::isIntegerWithResult ( std::string_view val,
int * res )

return true is a string contains an integer value

Parameters
sA string
Returns
true if s exactly contains an int (s can start with "-" or "+")

Definition at line 113 of file utils_string.cpp.

113 {
114 if (val.empty()) return false;
115 std::size_t pos = 0;
116 if ((val[0] == '+') || (val[0] == '-')) { pos = 1; }
117 if (val.find_first_not_of("0123456789", pos) != std::string_view::npos) return false;
118
119 if (res != nullptr) {
120 // from_chars handles '-' natively but not '+'
121 const std::size_t from_pos = (val[0] == '+') ? 1 : 0;
122 std::from_chars(val.data() + from_pos, val.data() + val.size(), *res);
123 }
124 return true;
125 }

References isIntegerWithResult().

Referenced by gum::detail::fastGraphBuildNode(), gum::detail::fastGraphIsNodeIdToken(), isInteger(), and isIntegerWithResult().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isNumerical()

INLINE bool gum::isNumerical ( std::string_view val)

return true is a string contains a numerical (double) value

Parameters
sA string
Returns
true if s exactly contains a double

Definition at line 102 of file utils_string_inl.h.

102{ return isNumericalWithResult(val, nullptr); }
bool isNumericalWithResult(std::string_view val, double *res)
return true is a string contains a numerical (double) value

References isNumerical(), and isNumericalWithResult().

Referenced by gum::Tensor< GUM_ELEMENT >::expectedValue(), fastVariable(), and isNumerical().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isNumericalWithResult()

GUM_SHARED_PUBLIC bool gum::isNumericalWithResult ( std::string_view val,
double * res )

return true is a string contains a numerical (double) value

Parameters
sA string *
Returns
true if s exactly contains a double

Definition at line 127 of file utils_string.cpp.

127 {
128 std::string s(val);
129 char* endptr = nullptr;
130 const char* str = s.c_str();
131 double d = std::strtod(str, &endptr);
132
133 if (*endptr != '\0' || endptr == str) return false;
134 if (res != nullptr) *res = d;
135
136 return true;
137 }

References isNumericalWithResult().

Referenced by isNumerical(), and isNumericalWithResult().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ltrim()

INLINE void gum::ltrim ( std::string & s)

trim from start (in place)

Parameters
sA string

Definition at line 72 of file utils_string_inl.h.

72 {
73 s.erase(s.begin(),
74 std::ranges::find_if_not(s, [](unsigned char ch) { return std::isspace(ch); }));
75 }

References ltrim().

Referenced by ltrim(), and trim().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Memcmp()

bool gum::Memcmp ( const void *const in_,
const void *const out_,
unsigned long size )

Cross-platform replacement for memcmp.

Parameters
in_A pointer to the block of memory to copy.
out_A pointer to the block of memory receiving copy.
sizeNumber of bytes to copy.
Returns
Returns true if OK.

Definition at line 61 of file utils_misc.cpp.

61 {
62 unsigned char* in = (unsigned char*)in_;
63 unsigned char* out = (unsigned char*)out_;
64
65 for (unsigned long i = 0; i < size; ++i)
66 if (*(in++) != *(out++)) return false;
67
68 return true;
69 }

References Memcmp().

Referenced by Memcmp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator<<() [1/3]

template<typename T1, typename T2>
ostream & std::operator<< ( ostream & stream,
const pair< T1, T2 > & val )

'std::cout<<' operator for pairs.

Template Parameters
T1The pair's first's type.
T2The pair's second's type.
Parameters
streamThe stream to print to.
valThe pair to print to stream.
Returns
Returns stream.

Definition at line 79 of file utils_misc_tpl.h.

79 {
80 stream << "(" << val.first << "," << val.second << ")";
81 return stream;
82 }

References operator<<().

Here is the call graph for this function:

◆ operator<<() [2/3]

template<typename T>
ostream & std::operator<< ( ostream & stream,
const vector< T > & val )

'std::cout<<' operator for vectors.

Template Parameters
TThe vector's elements type.
Parameters
streamThe stream to print to.
valThe std::vector to print to stream.
Returns
Returns stream.

Definition at line 63 of file utils_misc_tpl.h.

63 {
64 bool deja = false;
65 stream << "[";
66
67 for (const auto& v: val) {
68 if (deja) stream << " , ";
69 else deja = true;
70 stream << v;
71 }
72
73 stream << "]";
74
75 return stream;
76 }

References operator<<().

Here is the call graph for this function:

◆ operator<<() [3/3]

template<typename T0, typename... T>
std::ostream & std::operator<< ( std::ostream & os,
const std::tuple< T0, T... > & t )

'std::cout<<' operator for vectors.

Parameters
streamThe stream to print to.
Template Parameters
tThe std::tuple
Parameters
valThe std::vector to print to stream.
Returns
Returns stream.

Definition at line 101 of file utils_misc_tpl.h.

101 {
102 char quote = (std::is_convertible< T0, std::string >::value) ? '"' : 0;
103 os << '(' << quote << std::get< 0 >(t) << quote;
105 return os << ')';
106 }
static std::enable_if<(N< sizeof...(T))>::type print(std::ostream &os, const std::tuple< T... > &t)

References operator<<(), and std::_auxiliary_print_tuple_< N >::print().

Here is the call graph for this function:

◆ parseDecimal()

GUM_SHARED_PUBLIC bool gum::parseDecimal ( std::string_view val,
double & res )

parse a decimal number, whatever the locale of the program

Unlike isNumerical(), only the decimal notation (with a '.') and the scientific notation are accepted: hexadecimal, "inf" and "nan" are refused, on every platform.

Parameters
valA string, without leading or trailing space
resThe parsed value (unspecified if the function returns false)
Returns
true if val exactly contains a finite decimal number

Definition at line 139 of file utils_string.cpp.

139 {
140 // the standard library accepts more than that (hexadecimal, inf, nan) on some platforms
141 if (val.empty() || val.find_first_not_of("0123456789+-.eE") != std::string_view::npos) {
142 return false;
143 }
144 std::istringstream in{std::string(val)};
145 in.imbue(std::locale::classic());
146 in >> res;
147 return !in.fail() && in.peek() == std::istringstream::traits_type::eof();
148 }

References parseDecimal().

Referenced by gum::Configuration::_refreshEpsilons_(), gum::Configuration::_validate_(), gum::Configuration::getValue(), parseDecimal(), and gum::Configuration::typed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ randomDistribution()

template<GUM_Numeric GUM_SCALAR>
std::vector< GUM_SCALAR > gum::randomDistribution ( Size n)

Return a random discrete distribution.

Parameters
nThe number of modalities for the ditribution.
Returns
Return a random discrete distribution.
Template Parameters
GUM_SCALARThe type used for representing probabilities.

Definition at line 57 of file utils_random_tpl.h.

57 {
58 if (n < 2) n = 2;
59
60 if (n == std::numeric_limits< Size >::max()) {
61 GUM_ERROR(OutOfBounds, "randomDistribution: n is too large (SIZE_MAX would overflow n+1)")
62 }
63
64 // using sort method for uniformly distributed distributions
65 // https://doi.org/10.1016/0377-2217(82)90161-8
66 std::vector< GUM_SCALAR > v(n + 1);
67 std::vector< GUM_SCALAR > res(n);
68 v[0] = (GUM_SCALAR)0.0;
69 v[n] = (GUM_SCALAR)1.0;
70 for (Idx i = 1; i < n; i++) {
71 v[i] = (GUM_SCALAR)randomProba();
72 }
73 std::sort(v.begin(), v.end());
74
75 for (Idx i = 0; i < n; i++) {
76 res[i] = v[i + 1] - v[i];
77 }
78
79 return res;
80 }
Exception : out of bound.
#define GUM_ERROR(type, msg)
Definition exceptions.h:76
Size Idx
Type for indexes.
Definition types.h:79
GUM_SHARED_PUBLIC double randomProba()
Returns a random double between 0 and 1 included (i.e.

References GUM_ERROR, randomDistribution(), and randomProba().

Referenced by gum::Tensor< GUM_SCALAR >::randomCPT(), randomDistribution(), and gum::Tensor< GUM_SCALAR >::randomDistribution().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ randomGenerator()

INLINE std::mt19937 & gum::randomGenerator ( )

define a random_engine with correct seed

Definition at line 98 of file utils_random_inl.h.

References gum::_rand_namespace_::generator(), and randomGenerator().

Referenced by gum::MultiDimFunctionGraphGenerator::_generateVarPos_(), gum::Dirichlet::operator()(), gum::Dirichlet::operator()(), randomGenerator(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::setRandomVarOrder(), and gum::learning::KTBNDatabaseGenerator< GUM_SCALAR >::setVarOrderRandomized().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ randomGeneratorSeed()

INLINE unsigned int gum::randomGeneratorSeed ( )

Returns the aGrUM's seed used by the std::generators.

Returns
Returns the aGrUM's seed used by the std::generators.

Definition at line 91 of file utils_random_inl.h.

91 {
92 return (unsigned int)((GUM_RANDOMSEED == 0)
93 ? std::chrono::system_clock::now().time_since_epoch().count()
94 : GUM_RANDOMSEED);
95 }

References randomGeneratorSeed().

Referenced by randomGeneratorSeed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ randomProba()

INLINE double gum::randomProba ( )

Returns a random double between 0 and 1 included (i.e.

a proba).

Returns
Returns a random double between 0 and 1 included (i.e. a proba).

Definition at line 73 of file utils_random_inl.h.

73 {
74 std::uniform_real_distribution uni_real(0.0, 1.0);
75 return uni_real(_rand_namespace_::generator());
76 }

References gum::_rand_namespace_::generator(), and randomProba().

Referenced by gum::MultiDimFunctionGraphGenerator::_createLeaf_(), gum::learning::KTBNDatabaseGenerator< GUM_SCALAR >::_drawVar_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClassDag_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClassDag_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateSystem_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateSystem_(), gum::MCBayesNetGenerator< GUM_SCALAR, SimpleCPTGenerator, SimpleCPTDisturber >::disturbReducCPT(), gum::Tensor< GUM_SCALAR >::draw(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::drawSamples(), gum::MultiDimFunctionGraphGenerator::generate(), gum::SimpleBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::generateBN(), gum::InfluenceDiagramGenerator< GUM_SCALAR >::generateID(), gum::SimpleUTGenerator::generateUT(), gum::SimpleUTGenerator::generateUT(), gum::FMDPSimulator::perform(), gum::Tensor< GUM_SCALAR >::random(), randomDistribution(), randomProba(), and gum::E_GreedyDecider::stateOptimalPolicy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ randomValue()

INLINE Idx gum::randomValue ( const Size max = 2)

Returns a random Idx between 0 and max-1 included.

Returns
Returns a random idx between 0 and max-1 included . By default, max=2

Definition at line 66 of file utils_random_inl.h.

66 {
67 if (max == 0) { GUM_ERROR(OutOfBounds, "randomValue: max must be > 0") }
68 std::uniform_int_distribution< Idx > uni_int(0, int(max) - 1);
69 return uni_int(_rand_namespace_::generator());
70 }

References gum::_rand_namespace_::generator(), GUM_ERROR, and randomValue().

Referenced by gum::MCBayesNetGenerator< GUM_SCALAR, SimpleCPTGenerator, SimpleCPTDisturber >::MCBayesNetGenerator(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::_chooseCloseNodes_(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::_createPartTree_(), gum::MCBayesNetGenerator< GUM_SCALAR, SimpleCPTGenerator, SimpleCPTDisturber >::_createPartTree_(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::_createTree_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClass_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClassDag_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClassDag_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClasses_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateCluster_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateSystem_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateSystem_(), gum::KTBNGenerator< GUM_SCALAR >::_shuffle_(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::_verticesSampling_(), gum::IBayesNetGenerator< GUM_SCALAR, SimpleCPTGenerator >::fillCPT(), gum::MultiDimFunctionGraphGenerator::generate(), gum::MCBayesNetGenerator< GUM_SCALAR, SimpleCPTGenerator, SimpleCPTDisturber >::generateBN(), gum::SimpleBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::generateBN(), gum::InfluenceDiagramGenerator< GUM_SCALAR >::generateID(), gum::KTBNGenerator< GUM_SCALAR >::generateKTBN(), getUniqueFileName(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::makeInferenceByRandomOrder_(), gum::GibbsOperator< GUM_SCALAR >::nextSample(), gum::AbstractSimulator::randomState_(), randomValue(), randomValue(), and gum::SDYNA::takeAction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_newline()

INLINE std::string gum::remove_newline ( std::string_view s)

remove all newlines in a string

Parameters
sA string
Returns
the new string with no newline

Definition at line 91 of file utils_string_inl.h.

91 {
92 std::string res{s};
93 std::erase(res, '\n');
94 std::erase(res, '\r');
95 return res;
96 }

References remove_newline().

Referenced by fastGraph(), gum::BayesNet< GUM_SCALAR >::fastPrototype(), gum::InfluenceDiagram< GUM_SCALAR >::fastPrototype(), and remove_newline().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ replace()

GUM_SHARED_PUBLIC std::string gum::replace ( std::string_view s,
std::string_view val,
std::string_view new_val )

Replace val by new_val in s.

Parameters
sA string.
valThe value to replace in s.
new_valThe new value to replace val in s.
Returns
A new string with val replaced by new_val.

Definition at line 101 of file utils_string.cpp.

101 {
102 std::string retVal(s);
103 auto pos = retVal.find(val);
104 while (pos != std::string::npos) {
105 std::stringstream sBuff;
106 sBuff << retVal.substr(0, pos) << new_val << retVal.substr(pos + val.size());
107 retVal = sBuff.str();
108 pos = retVal.find(val);
109 }
110 return retVal;
111 }

References replace().

Referenced by gum::prm::o3prm::O3prmReader< double >::O3prmReader(), gum::prm::o3prm::O3prmReader< double >::~O3prmReader(), gum::prm::o3prm::O3prmReader< GUM_SCALAR >::_clean_(), gum::prm::o3prm::O3prmReader< double >::operator=(), gum::prm::o3prm::O3prmReader< double >::parseStream(), gum::prm::o3prm::O3prmReader< double >::readFile(), gum::prm::o3prm::O3prmReader< double >::readString(), replace(), and gum::prm::o3prm::O3prmReader< double >::setClassPath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rtrim()

INLINE void gum::rtrim ( std::string & s)

trim from end (in place)

Parameters
sA string

Definition at line 78 of file utils_string_inl.h.

78 {
79 auto it = std::ranges::find_if_not(s | std::views::reverse,
80 [](unsigned char ch) { return std::isspace(ch); });
81 s.erase(it.base(), s.end());
82 }

References rtrim().

Referenced by rtrim(), and trim().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ split()

GUM_SHARED_PUBLIC std::vector< std::string > gum::split ( std::string_view orig,
std::string_view delimiter )

Split str using the delimiter.

Parameters
origsearched string
delimiterstring
Returns
Vector of splitted strings

Definition at line 88 of file utils_string.cpp.

88 {
89 std::vector< std::string > tokens;
90 size_t prev = 0, pos = 0;
91 do {
92 pos = str.find(delim, prev);
93 if (pos == std::string::npos) pos = str.length();
94 std::string token(str.substr(prev, pos - prev));
95 if (!token.empty()) tokens.push_back(token);
96 prev = pos + delim.length();
97 } while (pos < str.length() && prev < str.length());
98 return tokens;
99 }

References split().

Referenced by fastGraph(), gum::BayesNet< GUM_SCALAR >::fastPrototype(), gum::InfluenceDiagram< GUM_SCALAR >::fastPrototype(), fastVariable(), gum::KTBN< GUM_SCALAR >::load(), and split().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toLower()

INLINE std::string gum::toLower ( std::string_view str)

Returns the lowercase version of str.

Returns
Returns the lowercase version of str.

Definition at line 60 of file utils_string_inl.h.

60 {
61 std::string result{str};
62 std::ranges::transform(result, result.begin(), [](unsigned char c) { return std::tolower(c); });
63 return result;
64 }

References toLower().

Referenced by gum::BayesNet< GUM_SCALAR >::_addAggregator_(), gum::Configuration::_indexKey_(), gum::Configuration::_parse_(), gum::Configuration::_validate_(), gum::Configuration::grep(), gum::Configuration::load(), gum::dot::parseColor(), gum::dot::resolveFgColor(), gum::prm::PRMAggregate< GUM_SCALAR >::str2enum(), and toLower().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ trim()

INLINE void gum::trim ( std::string & s)

trim from both ends (in place)

Parameters
sA string

Definition at line 85 of file utils_string_inl.h.

85 {
86 ltrim(s);
87 rtrim(s);
88 }
GUM_SHARED_PUBLIC void ltrim(std::string &s)
trim from start (in place)
GUM_SHARED_PUBLIC void rtrim(std::string &s)
trim from end (in place)

References ltrim(), rtrim(), and trim().

Referenced by fastVariable(), trim(), and trim_copy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ trim_copy()

INLINE std::string gum::trim_copy ( std::string_view s)

trim from both ends (copying)

Parameters
sA string
Returns
the new string trimmed from start

Definition at line 105 of file utils_string_inl.h.

105 {
106 std::string res{s};
107 trim(res);
108 return res;
109 }
GUM_SHARED_PUBLIC void trim(std::string &s)
trim from both ends (in place)

References trim(), and trim_copy().

Referenced by gum::Configuration::_parse_(), gum::Configuration::_validate_(), fastGraph(), gum::detail::fastGraphTokenize(), gum::Configuration::load(), and trim_copy().

Here is the call graph for this function:
Here is the caller graph for this function: