Miscellaneous function definitions, used in many places throughout the KPM package.
This is a Cython package, as some of the functions are called by Cython functions.
Return number of processor cores on this machine. Supported operating systems: Linux/Unix, MacOS, Windows.
If num_threads is not None, set the number of OpenMP threads. If the number is smaller than 1, determine and use the number of processor cores.
Check if the given string is a mathematical expression (containing only mathematical operators like ‘+’, ‘-‘, ‘*’, or ‘/’, and of course digits). Can be used to check if “eval” is needed to evaluate an expression in a given string.
Note: This function does not check if the numerical expression is actually valid. It just gives a hint if the given string should be passed to eval or not.
Cast value to the given data type (dtype). If value is a string, assume that it contains a mathematical expression, and evaluate it with eval before casting it to the specified type.
The function could always use eval, but this is assumed to be slower for values that do not have to be evaluated.
Check if an object is iterable. Return True for lists, tuples, dictionaries and numpy arrays (all objects that possess an __iter__ method). Return False for scalars (float, int, etc.), strings, bool and None.