From 34a3ac1cf48a88fbbe8028220ff2ea6bb750d2f0 Mon Sep 17 00:00:00 2001 From: jdsteve2 Date: Mon, 18 May 2020 21:02:45 -0500 Subject: [PATCH 1/3] import compute_sccs from pytools instead of loopy --- loopy/preprocess.py | 2 +- loopy/type_inference.py | 2 +- test/test_misc.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/loopy/preprocess.py b/loopy/preprocess.py index 4e00eab7d..de81815a8 100644 --- a/loopy/preprocess.py +++ b/loopy/preprocess.py @@ -1979,7 +1979,7 @@ def find_idempotence(kernel): # Find SCCs of dep_graph. These are used for checking if the instruction is # in a dependency cycle. - from loopy.tools import compute_sccs + from pytools.graph import compute_sccs sccs = dict((item, scc) for scc in compute_sccs(dep_graph) diff --git a/loopy/type_inference.py b/loopy/type_inference.py index 010a0658f..32f039a22 100644 --- a/loopy/type_inference.py +++ b/loopy/type_inference.py @@ -532,7 +532,7 @@ def infer_unknown_types(kernel, expect_completion=False): if read_var in names_for_type_inference)) for written_var in names_for_type_inference) - from loopy.tools import compute_sccs + from pytools.graph import compute_sccs # To speed up processing, we sort the variables by computing the SCCs of the # type dependency graph. Each SCC represents a set of variables whose types diff --git a/test/test_misc.py b/test/test_misc.py index 7a834a6f5..258bbc35e 100644 --- a/test/test_misc.py +++ b/test/test_misc.py @@ -36,7 +36,7 @@ from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_2 # noqa def test_compute_sccs(): - from loopy.tools import compute_sccs + from pytools.graph import compute_sccs import random rng = random.Random(0) -- GitLab From 1c4f0dca4cc9da6a21b6a4484dbaeb28fb086ac7 Mon Sep 17 00:00:00 2001 From: jdsteve2 Date: Mon, 18 May 2020 21:05:56 -0500 Subject: [PATCH 2/3] remove compute_sccs and corresponding test (moved to pytools) --- loopy/tools.py | 59 ----------------------------------------------- test/test_misc.py | 45 ------------------------------------ 2 files changed, 104 deletions(-) diff --git a/loopy/tools.py b/loopy/tools.py index f7e9997c1..a1cd5e108 100644 --- a/loopy/tools.py +++ b/loopy/tools.py @@ -355,65 +355,6 @@ def empty_aligned(shape, dtype, order='C', n=64): # }}} -# {{{ compute SCCs with Tarjan's algorithm - -def compute_sccs(graph): - to_search = set(graph.keys()) - visit_order = {} - scc_root = {} - sccs = [] - - while to_search: - top = next(iter(to_search)) - call_stack = [(top, iter(graph[top]), None)] - visit_stack = [] - visiting = set() - - scc = [] - - while call_stack: - top, children, last_popped_child = call_stack.pop() - - if top not in visiting: - # Unvisited: mark as visited, initialize SCC root. - count = len(visit_order) - visit_stack.append(top) - visit_order[top] = count - scc_root[top] = count - visiting.add(top) - to_search.discard(top) - - # Returned from a recursion, update SCC. - if last_popped_child is not None: - scc_root[top] = min( - scc_root[top], - scc_root[last_popped_child]) - - for child in children: - if child not in visit_order: - # Recurse. - call_stack.append((top, children, child)) - call_stack.append((child, iter(graph[child]), None)) - break - if child in visiting: - scc_root[top] = min( - scc_root[top], - visit_order[child]) - else: - if scc_root[top] == visit_order[top]: - scc = [] - while visit_stack[-1] != top: - scc.append(visit_stack.pop()) - scc.append(visit_stack.pop()) - for item in scc: - visiting.remove(item) - sccs.append(scc) - - return sccs - -# }}} - - # {{{ pickled container value class _PickledObject(object): diff --git a/test/test_misc.py b/test/test_misc.py index 258bbc35e..dc5045fe0 100644 --- a/test/test_misc.py +++ b/test/test_misc.py @@ -24,7 +24,6 @@ THE SOFTWARE. import six # noqa import pytest -from six.moves import range import sys @@ -35,50 +34,6 @@ logger = logging.getLogger(__name__) from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_2 # noqa -def test_compute_sccs(): - from pytools.graph import compute_sccs - import random - - rng = random.Random(0) - - def generate_random_graph(nnodes): - graph = dict((i, set()) for i in range(nnodes)) - for i in range(nnodes): - for j in range(nnodes): - # Edge probability 2/n: Generates decently interesting inputs. - if rng.randint(0, nnodes - 1) <= 1: - graph[i].add(j) - return graph - - def verify_sccs(graph, sccs): - visited = set() - - def visit(node): - if node in visited: - return [] - else: - visited.add(node) - result = [] - for child in graph[node]: - result = result + visit(child) - return result + [node] - - for scc in sccs: - scc = set(scc) - assert not scc & visited - # Check that starting from each element of the SCC results - # in the same set of reachable nodes. - for scc_root in scc: - visited.difference_update(scc) - result = visit(scc_root) - assert set(result) == scc, (set(result), scc) - - for nnodes in range(10, 20): - for i in range(40): - graph = generate_random_graph(nnodes) - verify_sccs(graph, compute_sccs(graph)) - - def test_SetTrie(): from loopy.kernel.tools import SetTrie -- GitLab From 9b8ca5cc54e8b836af1196ef2b34c9df273d6cc6 Mon Sep 17 00:00:00 2001 From: jdsteve2 Date: Mon, 18 May 2020 21:07:10 -0500 Subject: [PATCH 3/3] bump pytools version dependency --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 92c16a0f5..72145fd1b 100644 --- a/setup.py +++ b/setup.py @@ -89,7 +89,7 @@ setup(name="loo.py", ], install_requires=[ - "pytools>=2020.1", + "pytools>=2020.2", "pymbolic>=2019.2", "genpy>=2016.1.2", "cgen>=2016.1", -- GitLab