priops.node

priops.Node

class priops.node.Node(item=None, items=None, node=None)[source]

Nodes define nodes in the graph, by giving a specification of a list of objects. A node contains a list, each element describes the category of an operand. (For technical reason if cannot be a list: Overloading __getitem__() in that case doesn’t work.)

This class is abstract. Derived classes should provide:

  • .fulfils_specification(self, other_node): Gives True if objects of specification self fulfil also the specification other_node. Should accept None entries in other_node, where None is a wildcard for “any item”.
__init__(item=None, items=None, node=None)[source]

Initialises the Node from either one item or many items. One of item or items must be given, but not both. If both item and items are None, it is assumed that item is given as None, and that items is not specified.

Alternatively, the Node can be initialised from another Node instance node. This is needed by derived classes in some cases to provide e.g. slicing operations based on this class’es slicing operation. If node is given, it overrides all other parameters.

frominter(data)[source]

Processes given data to match the scalar/vector specification of the node. This is defined at initialisation time.

data is always assumed to be a list. If self is scalar, the length must be unity, and the first element is returned. Else, the list is returned unchanged.

tointer(data)[source]

Processes the output of an edge according to the scalar/vector specification of the node to match the inter-node data flow specification (which is lists).

If self is scalar, the data is wrapped into a list, else, the data is returned unchanged.

__str__()[source]
__add__(other_node)[source]

Combines two nodes by combining them into a CombinedNode.

__getitem__(key)[source]

If a slice is requested, returns a portion of this Node as a Node. If an element is requested (technically, everything that’s not a slice), then the element of self.elements is returned.

priops.EmptyNode

class priops.node.EmptyNode[source]

Bases: priops.node.Node

A node without elements. Needed as initial element for summing up nodes via sum().

__init__()[source]

Initialises the emptiness of the node.

__str__()[source]
__add__(other_node)[source]

Returns the other node other_node, since this node is empty and doesn’t matter.

fulfils_specification(other_node)[source]

If the other node other_node is empty too, returns True, else False.

__getitem__(key)[source]

Under slicing always returns itself, else (if non-slicing getitem operation occurs), raises IndexError.

priops.CombinedNode

class priops.node.CombinedNode(constituents)[source]

Bases: priops.node.Node

Combined nodes combine a number of Node objects into one big node. The elements of the combined node are the sum of all constituents, seeing the constituents as list objects.

If a combined node fulfils another specification depends on the constituents.

__init__(constituents)[source]
__str__()[source]
fulfils_specification(other_node)[source]

Checks if self, defined by its constituents, fulfils the specification other_node. If the lengthes mismatch, False is returned.

__getitem__(key)[source]

If key is a slice, the constituents are sliced accordingly. Else, the element is returned. Steps in slices are ignored.

Table Of Contents

Previous topic

API

Next topic

priops.edge

This Page