kpm.misc

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.

Functions

kpm.misc.npc()

Return number of processor cores on this machine. Supported operating systems: Linux/Unix, MacOS, Windows.

kpm.misc.symmetric_interval()

If a scalar x is given, return the tuple (-|x|, |x|).

kpm.misc.set_num_threads()

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.

kpm.misc.opt2mathlist()
kpm.misc.ismath()

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.

kpm.misc.evalmath()

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.

kpm.misc.isiterable()

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.

Indices and tables

Table Of Contents

Previous topic

kpm.cf

This Page