registry module

Full Documentation for hippynn.graphs.indextypes.registry module. Click here for a summary page.

Storage for the logical relationships between index states, and a cache reduce redundant computations. Also includes the indextransformer decorator which registers computations that change index states. The index transformers do not live here because they are themselves nodes, and this package should be minimally dependent on the nodes themselves.

assign_index_aliases(*nodes)[source]

Store the input set of nodes in the index cache as index aliases of each other.

Errors if the nodes contain two different nodes with the same index state.

Parameters:

nodes

Returns:

None

clear_index_cache()[source]

Remove any cached index types for nodes.

The index cache holds global references to nodes that have been transformed automatically, so these nodes won’t be garbage collected automatically. Clearing the cache will free any reference to them.

If you modify the index dispatch table or type comparison table on the fly, you may want to clear the cache to remove references to nodes created using the old rules.

register_index_transformer(input_idxstate, output_idxstate)[source]

Decorator for registering a transformer from one IdxType to another.

An index transformer should have a signature:

f(node) -> (parents, child_node_type)

with types:

node: Node
parents : Tuple[Node]
child_node_type : Union[Type[Node],Callable[[str,Tuple[node]],[node]]]

That is, the child_node_type can be a class of node, or a factory function which acts with the same signature as a node constructor. If f supports additional arguments, they must have default values, as it will be invoked by the automatic index transformation system as f(node).

The decorator results in a new function of type:

f(node: Node) -> Node

which is cached so that the same index transformation may be repeatedly applied to yield the same output node, and registered with the dispatch table for index transformations. No two functions may be registered for the same index type conversion simultaneously.