The Operation class contains methods for numeric operations, string manipulation, and other functions, all of which are also accessible via fl::Op. More...
#include <Operation.h>
Public Member Functions | |
template<> | |
FL_API std::string | str (const std::string &x, int decimals, std::ios_base::fmtflags scalarFormat) |
template<> | |
FL_API std::string | join (const std::vector< std::string > &x, const std::string &separator) |
template<> | |
FL_API std::string | join (int items, const std::string &separator, float first,...) |
template<> | |
FL_API std::string | join (int items, const std::string &separator, const char *first,...) |
Static Public Member Functions | |
template<typename T > | |
static T | min (T a, T b) |
Returns the minimum between the two parameters. More... | |
template<typename T > | |
static T | max (T a, T b) |
Returns the maximum between the two parameters. More... | |
template<typename T > | |
static T | bound (T x, T min, T max) |
Returns \(x\) bounded in \([\min,\max]\). More... | |
template<typename T > | |
static bool | in (T x, T min, T max, bool geq=true, bool leq=true) |
Indicates whether \(x\) is within the boundaries (open or closed) More... | |
template<typename T > | |
static bool | isInf (T x) |
Indicates whether \(x\) is infinity. More... | |
template<typename T > | |
static bool | isNaN (T x) |
Indicates whether \(x\) is not-a-number (NaN) More... | |
template<typename T > | |
static bool | isFinite (T x) |
Indicates whether \(x\) is finite, that is, \(x \not\in \{\pm\infty, \mathrm{NaN}\}\). More... | |
static bool | isLt (scalar a, scalar b, scalar macheps=fuzzylite::_macheps) |
Returns whether \(a\) is less than \(b\) at the given tolerance. More... | |
static bool | isLE (scalar a, scalar b, scalar macheps=fuzzylite::_macheps) |
Returns whether \(a\) is less than or equal to \(b\) at the given tolerance. More... | |
static bool | isEq (scalar a, scalar b, scalar macheps=fuzzylite::_macheps) |
Returns whether \(a\) is equal to \(b\) at the given tolerance. More... | |
static bool | isGt (scalar a, scalar b, scalar macheps=fuzzylite::_macheps) |
Returns whether \(a\) is greater than \(b\) at the given tolerance. More... | |
static bool | isGE (scalar a, scalar b, scalar macheps=fuzzylite::_macheps) |
Returns whether \(a\) is greater than or equal to \(b\) at the given tolerance. More... | |
static scalar | scale (scalar x, scalar fromMin, scalar fromMax, scalar toMin, scalar toMax) |
Linearly interpolates the parameter \(x\) in range [fromMin,fromMax] to a new value in the range [toMin,toMax] More... | |
static scalar | scale (scalar x, scalar fromMin, scalar fromMax, scalar toMin, scalar toMax, bool bounded) |
Linearly interpolates the parameter \(x\) in range [fromMin,fromMax] to a new value in the range [toMin,toMax] , truncated to the range [toMin,toMax] if bounded is true . More... | |
static scalar | add (scalar a, scalar b) |
Adds two values. More... | |
static scalar | subtract (scalar a, scalar b) |
Subtracts two values. More... | |
static scalar | multiply (scalar a, scalar b) |
Multiplies two values. More... | |
static scalar | divide (scalar a, scalar b) |
Divides two values. More... | |
static scalar | modulo (scalar a, scalar b) |
Computes the modulo. More... | |
static scalar | logicalAnd (scalar a, scalar b) |
Computes the logical AND. More... | |
static scalar | logicalOr (scalar a, scalar b) |
Computes the logical OR. More... | |
static scalar | logicalNot (scalar a) |
Returns the complement of the value. More... | |
static scalar | negate (scalar a) |
Negates the value. More... | |
static scalar | round (scalar x) |
Rounds the value to the nearest integer. More... | |
static scalar | gt (scalar a, scalar b) |
Returns whether \(a\) is greater than or equal to \(b\) at the default tolerance. More... | |
static scalar | ge (scalar a, scalar b) |
Returns whether \(a\) is greater than or equal to \(b\) at the default tolerance. More... | |
static scalar | eq (scalar a, scalar b) |
Returns whether \(a\) is equal to \(b\) at the default tolerance. More... | |
static scalar | neq (scalar a, scalar b) |
Returns whether \(a\) is different from \(b\) at the default tolerance. More... | |
static scalar | le (scalar a, scalar b) |
Returns whether \(a\) is less than or equal to \(b\) at the default tolerance. More... | |
static scalar | lt (scalar a, scalar b) |
Returns whether \(a\) is less than \(b\) at the default tolerance. More... | |
static int | random () |
Returns a random number. More... | |
static bool | increment (std::vector< int > &x, std::vector< int > &min, std::vector< int > &max) |
Increments \(x\) by the unit, treating the entire vector as a number. More... | |
static bool | increment (std::vector< int > &x, int position, std::vector< int > &min, std::vector< int > &max) |
Increments \(x\) by the unit at the given position, treating the entire vector as a number. More... | |
template<typename T > | |
static T | sum (const std::vector< T > &x) |
Computes the sum of the vector. More... | |
template<typename T > | |
static scalar | mean (const std::vector< T > &x) |
Computes the mean of the vector. More... | |
template<typename T > | |
static scalar | variance (const std::vector< T > &x) |
Computes the variance of the vector. More... | |
template<typename T > | |
static scalar | variance (const std::vector< T > &x, scalar mean) |
Computes the variance of the vector using the given mean. More... | |
template<typename T > | |
static scalar | standardDeviation (const std::vector< T > &x) |
Computes the standard deviation of the vector. More... | |
template<typename T > | |
static scalar | standardDeviation (const std::vector< T > &x, scalar mean) |
Computes the standard deviation of the vector using the given mean. More... | |
static std::string | validName (const std::string &name) |
Returns a valid name for variables. More... | |
static std::string | findReplace (const std::string &str, const std::string &find, const std::string &replace, bool replaceAll=true) |
Replaces the substrings that are equal to the given expression. More... | |
static std::string | replaceFirst (const std::string &str, const std::string &find, const std::string &replace) |
Replaces the first substring that is equal to the given expression. More... | |
static std::string | replaceAll (const std::string &str, const std::string &find, const std::string &replace) |
Replaces the every substring that is equal to the given expression. More... | |
static std::vector< std::string > | split (const std::string &str, const std::string &delimiter=" ", bool ignoreEmpty=true) |
Splits the string around the given delimiter. More... | |
static std::string | trim (const std::string &text) |
Removes whitespace at the beginning and end of the text. More... | |
static std::string | format (const std::string &text, int matchesChar(int), const std::string &replacement="") |
Replaces every matching character in the text with the given replacement. More... | |
static scalar | toScalar (const std::string &x) |
Parses the given string into a scalar value. More... | |
static scalar | toScalar (const std::string &x, scalar alternative, bool *ok=fl::null) FL_INOEXCEPT |
Parses the given string into a scalar value without throwing an exception. More... | |
static std::vector< scalar > | toScalars (const std::string &x) |
Parses the given string into a vector of scalar values. More... | |
static std::vector< scalar > | toScalars (const std::string &x, scalar alternative, bool *ok=fl::null) FL_INOEXCEPT |
Parses the given string into a vector of scalar values. More... | |
static bool | isNumeric (const std::string &x) |
Indicates whether the string can be converted to a numeric value. More... | |
template<typename T > | |
static std::string | str (T x, int decimals=fuzzylite::_decimals, std::ios_base::fmtflags scalarFormat=fuzzylite::_scalarFormat) |
Returns a string representation of the given value. More... | |
template<typename T > | |
static std::string | join (const std::vector< T > &x, const std::string &separator) |
Joins a vector of elements by the given separator into a single string. More... | |
template<typename T > | |
static std::string | join (int items, const std::string &separator, T first,...) |
Joins a variadic number of elements by the given separator into a single string. More... | |
The Operation class contains methods for numeric operations, string manipulation, and other functions, all of which are also accessible via fl::Op.
Definition at line 37 of file Operation.h.
|
inlinestatic |
Returns \(x\) bounded in \([\min,\max]\).
x | is the value to be bounded |
min | is the minimum value of the range |
max | is the maximum value of the range |
Definition at line 608 of file Operation.h.
Referenced by scale().
Returns whether \(a\) is equal to \(b\) at the default tolerance.
a | |
b |
Definition at line 713 of file Operation.h.
References isEq().
|
inlinestatic |
Replaces the substrings that are equal to the given expression.
str | is the target string |
find | is the string to find |
replace | is the string to replace the findings |
replaceAll | whether all the substrings are to be replaced or just the first string |
Definition at line 813 of file Operation.h.
Referenced by replaceAll(), and replaceFirst().
|
inlinestatic |
Replaces every matching character in the text with the given replacement.
text | is the string to have replacements |
matchesChar | is a pointer to a method that indicates whether the given character is a match |
replacement | a string to replace a matching character |
Definition at line 874 of file Operation.h.
Returns whether \(a\) is greater than or equal to \(b\) at the default tolerance.
a | |
b |
Definition at line 709 of file Operation.h.
References isGE().
Returns whether \(a\) is greater than or equal to \(b\) at the default tolerance.
a | |
b |
Definition at line 705 of file Operation.h.
References isGt().
|
inlinestatic |
Indicates whether \(x\) is within the boundaries (open or closed)
x | is the value |
min | is the minimum of the range |
max | is the maximum of the range |
geq | determines whether the maximum is a closed interval |
leq | determines whether the minimum is a closed interval |
Definition at line 615 of file Operation.h.
References isGE(), isGt(), isLE(), and isLt().
|
inlinestatic |
Increments \(x\) by the unit, treating the entire vector as a number.
For example, incrementing a few times \(x_0=\{0,0\}\) within boundaries \([0,1]\) results in: \(x_1=\{0,1\}\), \(x_2=\{1,0\}\), \(x_3=\{1,1\}\), \(x_4=\{0,0\}\).
x | is the vector to increment |
min | is the minimum value of the dimension |
max | is the maximum value of the dimension |
true
if \(x\) was incremented, false
otherwise (e.g., incrementing \(x_3\) returns false
). In earlier versions to 6.0, the result was the inverse and indicated whether the counter had overflown (most sincere apologies for this change). Definition at line 733 of file Operation.h.
Referenced by increment().
|
inlinestatic |
Increments \(x\) by the unit at the given position, treating the entire vector as a number.
For example, incrementing \(x_0=\{0,0,0\}\) within boundaries \([0,1]\) at the second position results in: \(x_1=\{0,1,0\}\), \(x_2=\{1,0,0\}\), \(x_3=\{1,1,0\}\), \(x_4=\{0,0,0\}\).
x | is the vector to increment |
position | is the position of the vector to increment, where smaller values lead to higher significance digits |
min | is the minimum value of the dimension |
max | is the maximum value of the dimension |
true
if \(x\) was incremented, false
otherwise (e.g., incrementing \(x_3\) returns false
). In earlier versions to 6.0, the result was the inverse and indicated whether the counter had overflown (most sincere apologies for this change). Definition at line 737 of file Operation.h.
References increment().
Returns whether \(a\) is equal to \(b\) at the given tolerance.
a | |
b | |
macheps | is the minimum difference upon which two floating-point values are considered equivalent |
Definition at line 644 of file Operation.h.
Referenced by eq(), logicalAnd(), logicalNot(), logicalOr(), neq(), and str().
|
inlinestatic |
Indicates whether \(x\) is finite, that is, \(x \not\in \{\pm\infty, \mathrm{NaN}\}\).
x | is the value |
Definition at line 632 of file Operation.h.
Returns whether \(a\) is greater than or equal to \(b\) at the given tolerance.
a | |
b | |
macheps | is the minimum difference upon which two floating-point values are considered equivalent |
Definition at line 652 of file Operation.h.
Returns whether \(a\) is greater than \(b\) at the given tolerance.
a | |
b | |
macheps | is the minimum difference upon which two floating-point values are considered equivalent |
Definition at line 648 of file Operation.h.
|
inlinestatic |
Indicates whether \(x\) is infinity.
x | is the value |
Definition at line 622 of file Operation.h.
Referenced by str().
Returns whether \(a\) is less than or equal to \(b\) at the given tolerance.
a | |
b | |
macheps | is the minimum difference upon which two floating-point values are considered equivalent |
Definition at line 640 of file Operation.h.
Returns whether \(a\) is less than \(b\) at the given tolerance.
a | |
b | |
macheps | is the minimum difference upon which two floating-point values are considered equivalent |
Definition at line 636 of file Operation.h.
|
inlinestatic |
Indicates whether \(x\) is not-a-number (NaN)
x | is the value |
Definition at line 627 of file Operation.h.
Referenced by max(), min(), and str().
|
inlinestatic |
Indicates whether the string can be converted to a numeric value.
x |
Definition at line 966 of file Operation.h.
References toScalar().
|
inlinestatic |
Joins a vector of elements by the given separator into a single string.
The elements are represented as strings utilizing the Operation::str() method on each element
x | is the vector of elements |
separator | is the string to add between the elements |
Definition at line 1001 of file Operation.h.
|
inlinestatic |
Joins a variadic number of elements by the given separator into a single string.
The elements are represented as strings utilizing the Operation::str() method on each element
items | is the number of elements to join |
separator | is the string to add between the elements |
first | is the first element, which defines the type of the subsequent elements |
... | are the remaining elements to join |
Definition at line 1023 of file Operation.h.
|
inline |
Definition at line 1012 of file Operation.h.
|
inline |
|
inline |
Definition at line 1054 of file Operation.h.
Returns whether \(a\) is less than or equal to \(b\) at the default tolerance.
a | |
b |
Definition at line 721 of file Operation.h.
References isLE().
Computes the logical AND.
a | |
b |
Definition at line 685 of file Operation.h.
References isEq().
Returns the complement of the value.
a |
Definition at line 693 of file Operation.h.
References isEq().
Computes the logical OR.
a | |
b |
Definition at line 689 of file Operation.h.
References isEq().
Returns whether \(a\) is less than \(b\) at the default tolerance.
a | |
b |
Definition at line 725 of file Operation.h.
References isLt().
|
inlinestatic |
Returns the maximum between the two parameters.
a | |
b |
Definition at line 601 of file Operation.h.
References isNaN().
Referenced by bound().
|
inlinestatic |
Computes the mean of the vector.
x | is the vector |
Definition at line 764 of file Operation.h.
References sum().
Referenced by standardDeviation(), and variance().
|
inlinestatic |
Returns the minimum between the two parameters.
a | |
b |
Definition at line 594 of file Operation.h.
References isNaN().
Referenced by bound().
Multiplies two values.
a | |
b |
Definition at line 673 of file Operation.h.
Returns whether \(a\) is different from \(b\) at the default tolerance.
a | |
b |
Definition at line 717 of file Operation.h.
References isEq().
|
inlinestatic |
Returns a random number.
Definition at line 729 of file Operation.h.
|
inlinestatic |
Replaces the every substring that is equal to the given expression.
str | is the target string |
find | is the string to find |
replace | is the string to replace |
Definition at line 832 of file Operation.h.
References findReplace().
|
inlinestatic |
Replaces the first substring that is equal to the given expression.
str | is the target string |
find | is the string to find |
replace | is the string to replace |
Definition at line 827 of file Operation.h.
References findReplace().
Rounds the value to the nearest integer.
x |
Definition at line 701 of file Operation.h.
|
inlinestatic |
Linearly interpolates the parameter \(x\) in range [fromMin,fromMax]
to a new value in the range [toMin,toMax]
x | is the source value to interpolate |
fromMin | is the minimum value of the source range |
fromMax | is the maximum value of the source range |
toMin | is the minimum value of the target range |
toMax | is the maximum value of the target range |
Definition at line 656 of file Operation.h.
|
inlinestatic |
Linearly interpolates the parameter \(x\) in range [fromMin,fromMax]
to a new value in the range [toMin,toMax]
, truncated to the range [toMin,toMax]
if bounded is true
.
x | is the source value to interpolate |
fromMin | is the minimum value of the source range |
fromMax | is the maximum value of the source range |
toMin | is the minimum value of the target range |
toMax | is the maximum value of the target range |
bounded | determines whether the resulting value is bounded to the range |
Definition at line 660 of file Operation.h.
References bound().
|
inlinestatic |
Splits the string around the given delimiter.
str | is the string to split |
delimiter | is the substrings on which the string will be split |
ignoreEmpty | whether the empty strings are discarded |
Definition at line 837 of file Operation.h.
|
inlinestatic |
Computes the standard deviation of the vector.
x |
Definition at line 769 of file Operation.h.
References mean().
|
inlinestatic |
Computes the standard deviation of the vector using the given mean.
x | |
mean | is the mean value of x |
Definition at line 774 of file Operation.h.
References variance().
|
inlinestatic |
Returns a string representation of the given value.
x | is the value |
decimals | is the number of decimals to display |
scalarFormat | are the flags for the underlying std::ostringstream |
Definition at line 976 of file Operation.h.
References FL_API, isEq(), isInf(), and isNaN().
Referenced by join().
|
inline |
Definition at line 993 of file Operation.h.
References FL_IUNUSED.
|
inlinestatic |
Computes the sum of the vector.
Definition at line 755 of file Operation.h.
Referenced by mean().
|
inlinestatic |
Parses the given string into a scalar value.
x | is the string to parse |
fl::Exception | if the string does not contain a scalar value |
Definition at line 889 of file Operation.h.
References FL_AT.
Referenced by isNumeric(), and toScalars().
|
inlinestatic |
Parses the given string into a scalar value without throwing an exception.
x | is the string to parse |
alternative | is the value to return if the string does not contain a scalar value |
ok | contains whether the operation was successful (optional) |
Definition at line 914 of file Operation.h.
|
inlinestatic |
Parses the given string into a vector of scalar values.
x | is the string containing space-separated values to parse |
fl::Exception | if the string contains an invalid scalar value |
Definition at line 941 of file Operation.h.
References toScalar().
|
inlinestatic |
Parses the given string into a vector of scalar values.
x | is the string containing space-separated values to parse |
alternative | is the value to use if an invalid value is found |
ok | contains whether the operation was successful (optional) |
Definition at line 951 of file Operation.h.
References toScalar().
|
inlinestatic |
Removes whitespace at the beginning and end of the text.
text |
Definition at line 858 of file Operation.h.
Referenced by validName().
|
inlinestatic |
Returns a valid name for variables.
name |
[a-zA-Z_0-9.]
Definition at line 801 of file Operation.h.
References trim().
|
inlinestatic |
Computes the variance of the vector.
x | is the vector |
Definition at line 781 of file Operation.h.
References mean().
Referenced by standardDeviation().
|
inlinestatic |
Computes the variance of the vector using the given mean.
x | is the vector |
mean | is the mean value of the vector |
Definition at line 786 of file Operation.h.
References mean().