General utilities#

Common routines for Colossus modules.

Module contents#

printLine()

Print a line to the console.

getHomeDir()

Finds the home directory on this system.

getCodeDir()

Returns the path to this code file.

isArray(var)

Tests whether a variable is iterable or not.

getArray(var)

Convert a variable to a numpy array, whether it already is one or not.

safeLog(x)

Natural log with check for overrun.

safeExp(x)

Natural exp with check for overrun.

Module reference#

utils.utilities.max_float_exp = 100.0#

Highest exponent that is safe for the log/exp functions in numpy. Overflows can occur when higher exponentials are called.

utils.utilities.printLine()#

Print a line to the console.

utils.utilities.parseVersionString(version_str)#

Parse a version string into numbers.

There are more official functions to parse version numbers that use regular expressions and can handle more formats according to PEP 440. Since Colossus versions are always composed of three numbers and no letters, we implement a comparison manually to avoid needing to include non-standard libraries.

Parameters:
version_str: str

The version string to be converted.

Returns:
nums: array_like

A list of the three version numbers.

utils.utilities.versionIsOlder(v1, v2)#

Compare two version strings.

Parameters:
v1: str

A version string.

v2: str

A second version string.

Returns:
is_older: bool

True if v2 is older than v1, False otherwise.

utils.utilities.getHomeDir()#

Finds the home directory on this system.

Returns:
pathstring

The home directory, or None if home cannot be found.

utils.utilities.getCodeDir()#

Returns the path to this code file.

Returns:
path: string

The code directory.

utils.utilities.isArray(var)#

Tests whether a variable is iterable or not.

Parameters:
var: array_like

Variable to be tested.

Returns:
is_array: boolean

Whether var is a numpy array or not.

utils.utilities.getArray(var)#

Convert a variable to a numpy array, whether it already is one or not.

Parameters:
var: array_like

Variable to be converted to an array.

Returns:
var_ret: numpy array

A numpy array with one or more entries.

is_array: boolean

Whether var is a numpy array or not.

utils.utilities.safeLog(x)#

Natural log with check for overrun.

This function checks whether any elements in a given numpy array are larger than the maximum (positive or negative) exponent. If so, the corresponding elements are set to the min and max floats that are allowed.

Parameters:
x: array_like

Variable to be taken the log of.

Returns:
log: array_like

Log of x

utils.utilities.safeExp(x)#

Natural exp with check for overrun.

This function checks whether any elements in a given numpy array are larger than the maximum (positive or negative) exponent. If so, the corresponding elements are set to the min and max floats that are allowed.

Parameters:
x: array_like

Variable to be taken the exponential of.

Returns:
log: array_like

Exponential of x