Esempio n. 1
0
def test_natsorted():
    from pytools import natsorted, natorder

    assert natorder("1.001") < natorder("1.01")

    assert natsorted(["x10", "x1", "x9"]) == ["x1", "x9", "x10"]
    assert natsorted(map(str, range(100))) == list(map(str, range(100)))
    assert natsorted(["x10", "x1", "x9"], reverse=True) == ["x10", "x9", "x1"]
    assert natsorted([10, 1, 9], key=lambda d: "x%d" % d) == [1, 9, 10]
Esempio n. 2
0
    def print_stmt(stmt):
        if stmt.id in printed_stmt_ids:
            return
        printed_stmt_ids.add(stmt.id)

        for dep_id in natsorted(stmt.depends_on):
            print_stmt(id_to_stmt[dep_id])

        lines.append("{}{{{}}} {}".format(
            prefix, stmt.id,
            str(stmt).replace("\n", "\n        ")))
Esempio n. 3
0
    def __str__(self):
        lines = []
        for phase_name, phase in sorted(self.phases.items()):
            phase_title = 'PHASE "%s"' % phase_name
            if phase_name == self.initial_phase:
                phase_title += " (initial_phase)"
            lines.append(phase_title)

            for root_id in natsorted(phase.depends_on):
                lines.extend(
                    _stringify_statements([phase.id_to_stmt[root_id]],
                                          phase.id_to_stmt,
                                          prefix="    "))

            lines.append('    -> (next phase) "%s"' % phase.next_phase)
            lines.append("")

        return "\n".join(lines)
Esempio n. 4
0
def get_dot_dependency_graph(code, use_stmt_ids=False):
    """Return a string in the `dot <http://graphviz.org/>`_ language depicting
    dependencies among kernel statements.
    """

    from pymbolic.imperative.utils import get_dot_dependency_graph

    def additional_lines_hook():
        for i, (name, phase) in enumerate(code.phases.items()):
            yield 'subgraph cluster_%d { label="%s"' % (i, name)
            yield from natsorted(phase.depends_on)
            yield "}"

    statements = [
        stmt if use_stmt_ids else stmt.copy(id=stmt.id)
        for phase_name, phase in code.phases.items()
        for stmt in natsorted(phase.statements, key=lambda stmt: stmt.id)
    ]

    return get_dot_dependency_graph(
        statements,
        use_stmt_ids=use_stmt_ids,
        additional_lines_hook=additional_lines_hook)
Esempio n. 5
0
 def additional_lines_hook():
     for i, (name, phase) in enumerate(code.phases.items()):
         yield 'subgraph cluster_%d { label="%s"' % (i, name)
         yield from natsorted(phase.depends_on)
         yield "}"