cotengra.nodeops ================ .. py:module:: cotengra.nodeops Attributes ---------- .. autoapisummary:: cotengra.nodeops.nodeops_frozenset cotengra.nodeops.nodeops_bitsetint Classes ------- .. autoapisummary:: cotengra.nodeops.NodeOpsFrozenset cotengra.nodeops.BitSetInt cotengra.nodeops.NodeOpsBitSetInt cotengra.nodeops.NodeOpsSSA Functions --------- .. autoapisummary:: cotengra.nodeops.get_nodeops Module Contents --------------- .. py:class:: NodeOpsFrozenset Namespace for interacting with frozenset[int] as contraction tree nodes. .. py:attribute:: __slots__ :value: () .. py:method:: copy() .. py:attribute:: node_type The type used for nodes, to check isinstance with. .. py:attribute:: node_size Function to get the size of a node. .. py:attribute:: node_from_seq From a sequence of integers, construct node (``frozenset``). .. py:attribute:: new_node_for_seq .. py:method:: node_from_single(x) :staticmethod: From single integer ``x``, construct node (``frozenset``). .. py:method:: node_supremum(size) :staticmethod: Return the node containing all elements up to ``size``. .. py:method:: node_get_single_el(node) :staticmethod: Assuming ``node`` has one element, return it. .. py:method:: node_tie_breaker(x) :staticmethod: A tie breaker function for ordering nodes when they are the same size. Returns the negative of the smallest element in the node. Nodes with larger `node_tie_breaker` values get contracted first. .. py:method:: is_valid_node(node) :staticmethod: Check ``node`` is of type ``frozenset[int]``. .. py:method:: node_union(x, y) :staticmethod: Return the node given by the union of two nodes. .. py:method:: node_union_it(bs) :staticmethod: Return the node given by the union of an iterable of nodes. .. py:attribute:: new_node_for_union .. py:method:: node_issubset(x, y) :staticmethod: Check if node ``x`` is a subset of node ``y``. .. py:method:: is_leaf(node) :staticmethod: .. py:method:: is_supremum(node, N) :staticmethod: .. py:class:: BitSetInt Bases: :py:obj:`int` A bitset for keeping track of dense sets of integers. Subclass of ``int`` that overrides ``-``, ``&`` and ``|`` and provides ``__len__`` and ``__iter__``. As of python 3.8 doesn't seem much better than using frozenset[int] (slower and limited memory savings). :param it: If sequence of ``int``, treat these as the set members. If raw ``int`` interpret as bitset directly. :type it: Iterable[int] or int .. py:attribute:: __slots__ :value: () .. py:method:: __hash__() Return hash(self). .. py:method:: infimum() :classmethod: .. py:method:: supremum(size) :classmethod: .. py:method:: __len__() .. py:method:: iter_sparse() .. py:method:: iter_dense() .. py:method:: iter_numpy() .. py:method:: __iter__() .. py:method:: __contains__(i) .. py:method:: __sub__(i) Return self-value. .. py:method:: difference(i) .. py:method:: __and__(i) Return self&value. .. py:method:: intersection(i) .. py:method:: __or__(i) Return self|value. .. py:method:: union() .. py:method:: issubset(other) Check if this bitset is a subset of another bitset. x.issubset(y) returns True if all bits set in x are also set in y. Equivalent to: x & y == x .. py:method:: __repr__() Return repr(self). .. py:class:: NodeOpsBitSetInt Namespace for interacting with BitSetInt as contraction tree nodes. .. py:attribute:: __slots__ :value: () .. py:method:: copy() .. py:attribute:: node_type .. py:attribute:: node_size .. py:attribute:: node_from_seq .. py:attribute:: new_node_for_seq .. py:method:: node_from_single(x) :staticmethod: .. py:method:: node_supremum(size) :staticmethod: .. py:method:: node_get_single_el(node) :staticmethod: .. py:method:: node_tie_breaker(x) :staticmethod: .. py:method:: is_valid_node(node) :staticmethod: .. py:method:: node_union(x, y) :staticmethod: .. py:method:: node_union_it(bs) :staticmethod: .. py:attribute:: new_node_for_union .. py:method:: node_issubset(x, y) :staticmethod: .. py:method:: is_leaf(node) :staticmethod: .. py:method:: is_supremum(node, N) :staticmethod: .. py:class:: NodeOpsSSA(N) .. py:attribute:: __slots__ :value: ('ssa', 'N') .. py:attribute:: ssa .. py:attribute:: N .. py:method:: copy() .. py:method:: get_next_ssa() .. py:attribute:: node_type .. py:method:: node_size(node) :abstractmethod: .. py:method:: node_from_single(x) .. py:method:: node_supremum(size) .. py:method:: node_get_single_el(node) .. py:method:: node_tie_breaker(x) .. py:method:: is_valid_node(node) .. py:method:: node_union(x, y) :abstractmethod: .. py:method:: node_union_it(bs) :abstractmethod: .. py:method:: new_node_for_union(nodes) Get a new node label for the union of `nodes`. We use this rather than the above methods to be explicit that we can only create new node labels, not reconstruct labels from the constituent nodes. .. py:method:: node_from_seq(seq) :abstractmethod: .. py:method:: new_node_for_seq(seq) Get a new node for a sequence of raw input positions. We use this rather than the above method to be explicit that we can only create new node labels, not reconstruct labels from the constituent raw input positions. .. py:method:: node_issubset(x, y) :abstractmethod: .. py:method:: is_leaf(node) .. py:method:: is_supremum(node, N) .. py:data:: nodeops_frozenset .. py:data:: nodeops_bitsetint .. py:function:: get_nodeops(node_type_str: str, N=None) Get the node operations namespace for the given node type. :param node_type_str: The node type as a string. One of "frozenset[int]", "BitSetInt". :type node_type_str: str :returns: The corresponding node operations namespace. :rtype: NodeOpsFrozenset or NodeOpsBitSetInt