pathsim.utils.register module

class pathsim.utils.register.Register(size=1)[source]

Bases: object

This class is a intended to be used for the inputs and outputs of blocks.

Its basic functionality is similar to a dict but with some additional methods. The core functionality is that values can be added dynamically and the size of the register doesnt have to be specified. It also implements some methods to interact with numpy arrays and to streamline convergence checks.

Parameters:

size (int, optional) – initial size of the register

_values

internal dict that stores the values of the register

Type:

dict[int, float]

_sorted_keys

internal sorted list of port keys for fast ordered iterations of _values

Type:

list[int]

reset()[source]

Set all stored values of the register to zero.

to_array()[source]

Convert the register to a numpy array with entries sorted by ports.

Note

This method is performance critical, since it gets called A LOT and makes up a siginificant portion of all function calls during the main simulation loop! Its already profiled and optimized, so be careful with premature improvements.

Returns:

arr – converted register as array

Return type:

numpy.ndarray

update_from_array(arr)[source]

Update the register values from an array in place.

Note

This method is performance critical, since it gets called A LOT and makes up a siginificant portion of all function calls during the main simulation loop! Its already profiled and optimized, so be careful with premature improvements.

Parameters:

arr (numpy.ndarray, float) – array or scalar that is used to update internal register values

update_from_array_max_err(arr)[source]

Update the register values from an array in place and compute the maximum absolute deviation, which is used in the main simulation loop for convergencechecks of the fixed point iterations.

Note

This method is performance critical, since it gets called A LOT and makes up a siginificant portion of all function calls during the main simulation loop! Its already profiled and optimized, so be careful with premature improvements.

Parameters:

arr (numpy.ndarray, float) – array or scalar that is used to update internal register values

Returns:

err – maximum absolute deviation from previous register values

Return type:

float