Containers¶
Currently the following container types are supported:
ROUNDING_CONTAINER,PLAIN_CONTAINER.
Interface¶
Protocol RootContainer from the package pyzeal_utils. This module defines an interface to container types which are meant to hold root data. The underlying strategy used in cases where e.g. almost identical roots are added or the precision of roots is changed between add operations is up to the concrete container implementation (and transparent to the user). Additional checks could also be implemented in subclasses, e.g. checking if a root is contained in a certain region.
Authors:
Philipp Schuette
- class pyzeal.utils.containers.root_container.RootContainer(*args, **kwargs)[source]¶
Structural interface for container classes meant to hold root data.
- addRoot(root, context)[source]¶
Add a root to the container.
- Parameters:
root (
Tuple[complex,int]) – the root to be added to the containercontext (
FilterContext) – the number of valid decimal places of root
- Return type:
None
- getRootOrders()[source]¶
Returns the orders of all roots currently held in this container as a vector which is parallel to the vector returned by getRoots.
- Returns:
ndarray[Any,dtype[int32]] – a vector of integer root orders (multiplicities)
- getRoots()[source]¶
Returns all roots currently held in this container as a vector.
- Returns:
ndarray[Any,dtype[complex128]] – a vector of complex roots
- registerFilter(filterPredicate, key)[source]¶
Add a new filter predicate to this container instance. The filtering applies to all roots added after the filter is registered. To guarantee a consistent set of roots any implementation should clear its internal root buffer before/after registering a filter.
- Parameters:
filterPredicate (
Callable[[Tuple[complex,int],FilterContext],bool]) – the predicate used to filter rootskey (
str) – a (unique) key under which the filter is registered
- Return type:
None
Rounding container¶
Implementation RoundingContainer of the RootContainer protocol from the pyzeal_utils package. The concrete container class implemented here automatically rounds added roots to a fixed number of decimal places.
Authors:
Philipp Schuette
- class pyzeal.utils.containers.rounding_container.RoundingContainer(precision)[source]¶
This simple container implementation rounds every added root to a given number of decimal places and simple ignores any attempts to add additional roots which coincide with a previously added root after rounding. The multiplicity is not taken into account when comparing old and new roots. Changing the desired accuracy automatically removes all calculated roots to preserve consistency.
- __init__(precision)[source]¶
Initialize a rounding RootContainer. If no precision is given, default precision is used.
- Parameters:
precision (
Optional[Tuple[int,int]]) – expected accuracy of roots to be added
- addRoot(root, context)[source]¶
Add a new root with given accuracy to the container. If the accuracy differs from the accuracy of roots already added then all previous roots are removed.
- Parameters:
root (
Tuple[complex,int]) – the root to be added to the containercontext (
FilterContext) – the context of the new root, required for filtering
- Return type:
None
- getRootOrders()[source]¶
Returns the orders of all roots currently held in this container as a vector which is parallel to the vector returned by getRoots.
- Returns:
ndarray[Any,dtype[int32]] – a vector of integer root orders (multiplicities)
- getRoots()[source]¶
Returns all roots currently held in this container as a vector.
- Returns:
ndarray[Any,dtype[complex128]] – a vector of complex roots
- registerFilter(filterPredicate, key)[source]¶
Register a new filter to check possible roots against
- Parameters:
filterPredicate (
Callable[[Tuple[complex,int],FilterContext],bool]) – New filter to registerkey (
str) – A key to identify this filter
- Return type:
None
- removeRoot(root)[source]¶
Remove a given root from the container. Return value indicates success.
- Parameters:
root (
Tuple[complex,int]) – the root to be removed from the container- Returns:
bool– a boolean flag indicating if a removal happened
- static roundRoot(root, precision)[source]¶
Round a given root to a given number of decimal places.
- Parameters:
root (
Tuple[complex,int]) – a root to be roundedprecision (
Tuple[int,int]) – the number of decimal places to round to
- Returns:
Tuple[complex,int] – the rounded root (multiplicity stays constant)
Plain container¶
Implementation PlainContainer of the RootContainer protocol from the pyzeal_utils package. The concrete container class implemented here simply adds roots to an internal buffer without any further action. Its main use is the collection of potential roots in subprocesses during parallel calculations.
Authors:
Philipp Schuette
- class pyzeal.utils.containers.plain_container.PlainContainer(queue)[source]¶
Minimal container implementation. Simply adds roots to an internal buffer of type tQueue without any further action.
This class is mainly designed for application with a queue instance obtained from a multiprocessing.Manager. With this particular choice of root buffer it can serve as shared memory for several distinct processes each running their own instance of a FinderAlgorithm.
- __init__(queue)[source]¶
Initialize a new PlainContainer.
- Parameters:
queue (
Optional[tQueue]) – the internal buffer used for root storage
- addRoot(root, context)[source]¶
Add a new root to the internal buffer, ignoring the filter context.
- Parameters:
root (
Tuple[complex,int]) – the root to be added to the containercontext (
FilterContext) – the context of the new root, ignored
- Return type:
None
- getRootOrders()[source]¶
Returns the orders of all roots currently held in this container as a vector which is parallel to the vector returned by getRoots.
- Returns:
ndarray[Any,dtype[int32]] – a vector of integer root orders (multiplicities)
- getRoots()[source]¶
Returns all roots currently held in this container as a vector.
- Returns:
ndarray[Any,dtype[complex128]] – a vector of complex roots
- registerFilter(filterPredicate, key)[source]¶
Cannot register filters with an instance of PlainContainer.
- Parameters:
filterPredicate (
Callable[[Tuple[complex,int],FilterContext],bool]) – New filter to registerkey (
str) – A key to identify this filter
- Return type:
None