graphi.operators.interface module¶
-
graphi.operators.interface.graph_operator(prefix='graphi')¶ Implement a callable as a graph operator
Parameters: prefix – identifier to prepend to special method names Adds the operator lookup and fallback procedure to allow
Graphsubclasses to implement optimized algorithms. For example, a graph storing edges in a sorted data structure may prematurely end a search for neighbours given a maximum distance.A graph can influence the evaluation of a graph operator by providing an attribute named
__<prefix>_<operator name>__, e.g.__graphi_neighbours__for an operatorneighbours. If this is the case, the attribute is called with the provided arguments as a replacement for the operator implementation.-
graphi.operators.interface.operator(graph, *args, **kwargs)¶ The generic implementation of a graph operator.
-
graph.__graphi_operator__(*args, **kwargs)¶ The optimized implementation of a graph operator.
There are three special conditions to this procedure:
- attribute is
None The graph does not support the operation.
Attempting the operation on the graph raises
TypeError.- attribute is
NotImplemented - The graph does not overwrite the operation. The operator implementation is always used.
- calling the attribute returns
NotImplemented - The graph does not overwrite the operation for the specific parameters. The operator implementation is used.
The name of an operator is taken from
operator.__name__oroperator.__class__.__name__.-