# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import numpy as np
import networkx as nx


g = nx.chordal_cycle_graph(97)

g.nodes()

T = nx.dfs_tree(g, 0, depth_limit=3)

T.edges()

g[0]

tmp = [[0,u] for u in g[0]]

[ [1, *v] for v in tmp ]


def get_paths(graph, v, depth):
    if depth == 1:
        # return neighbors
        paths = [[v, u] for u in graph[v]]
        return(paths)
    else:
        # DFS
        paths = []
        for n in graph[v]:
            subpaths = get_paths(graph, n, depth-1)
            for u in subpaths:
                paths.append([v, *u])
        return(paths)


paths=[]
paths.extend(get_paths(g, 1, 2))

# +

paths
# -

paths.extend(get_paths(g, 0, 2))

paths

np.array(paths).shape

import sparse
sparse.COO(np.array(paths).T, )

n = g.number_of_nodes()

tuple([n for i in range(3)])

sparse.COO(np.array(paths).T, data=1, shape=tuple([n for i in range(3)]))

from maxnorm.graphs import *

mask = obs_mask_expander(g, 4)

mask



StarcoderdataJupyterScriptsDedupFiltered