yarrow.numpy.layer
Layered decomposition for numpy-backed diagrams. Note that this (currently) uses SciPy sparse arrays, so it can’t be used for diagrams backed by other array libraries (e.g., CuPy).
Use the layer function to assign a layering to operations in the diagram.
This is like a topological sort, except multiple operations can be assigned to
the same layering.
- yarrow.numpy.layer.make_sparse(s: FiniteFunction, t: FiniteFunction)
Given finite functions
s : E → Aandt : E → Brepresenting a bipartite graphG : A → B, return the sparseB×Aadjacency matrix representingG.
- yarrow.numpy.layer.operation_adjacency(d: Diagram)
Construct the underlying graph of operation adjacency from a diagram. An operation
xis adjacent to an operationyif there is a directed path fromxtoygoing through a single ■-node.
- yarrow.numpy.layer.kahn(adjacency: <MagicMock name='mock.sparse.csr_array' id='140439857614704'>)
A version of Kahn’s algorithm which assigns a layering to each ○-node, but where multiple nodes can have the same layering.
Returns a pair of arrays
(order, visited).order[v]is a natural number indicating the computed ordering of nodev, andvisited[v]is 1 if and only ifvwas visited while traversing the graph.If not all vertices were visited, the graph had a cycle.