pathsim.utils.register module

class pathsim.utils.register.Register(size=None, mapping=None, dtype=<class 'numpy.float64'>)[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 and implemented as a numpy array for fast data transfer.

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

  • mapping (dict[str: int]) – string aliases for integer ports

_data

internal numpy array that holds the values

Type:

np.ndarray

_mapping

internal mapping for port aliases from string to int (index)

Type:

dict[str: int]

resize(size)[source]
reset()[source]

Set all stored values to zero.

to_array()[source]

Returns a copy of the internal array.

Returns:

arr – converted register as array

Return type:

np.ndarray

update_from_array(arr)[source]

Update the register values from an array in place.

Parameters:

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