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 A and t : E B representing a bipartite graph G : A B, return the sparse B×A adjacency matrix representing G.

yarrow.numpy.layer.operation_adjacency(d: Diagram)

Construct the underlying graph of operation adjacency from a diagram. An operation x is adjacent to an operation y if there is a directed path from x to y going 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 node v, and visited[v] is 1 if and only if v was visited while traversing the graph.

If not all vertices were visited, the graph had a cycle.

yarrow.numpy.layer.layer(d: Diagram)

Assign a layering to a diagram d. This computes a FiniteFunction f : G(X) K, mapping ○-nodes of d.G to a natural number in the range(0, K). This mapping is ‘dense’ in the sense that for each i {0..K}, there is always some ○-node v for which f(v) = i.