Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

[BUG] finding leaf modules #2241

Merged
merged 15 commits into from
Mar 27, 2020
Merged

Conversation

QuanluZhang
Copy link
Contributor

No description provided.

@QuanluZhang QuanluZhang linked an issue Mar 26, 2020 that may be closed by this pull request
Copy link
Contributor

@ultmaster ultmaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be polished, but it looks bug-free to me.

if node.sname[-1] == ']':
leaf_nodes.append(sn)
else:
for key in node.childs:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for child in node.children.values():
    traverse_tree(child, sn)

for key in node.childs:
traverse_tree(node.childs[key], sn)
traverse_tree(root, '')
return leaf_nodes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm right, what this is doing is actually: finding all leaf nodes that ends with ]. If so, there is a simpler way to do it:

all_names = [node.scopeName() for node in graph.nodes()]
all_names = list(filter(lambda x: x, all_names))  # filter out non-empty strings
all_names.sort()
leaf_nodes = []
for i, name in enumerate(all_names):
    if (i + 1 >= len(all_names) or not all_names[i + 1].startswith(name)) and name.endswith("]"):
        leaf_nodes.append(name)
return leaf_nodes

Since I didn't get enough context, I might be wrong...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I test both your functions, they can generate same results.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ultmaster too complex, I am not sure whether the logic is correct or not...

@QuanluZhang QuanluZhang merged commit 6e62990 into microsoft:master Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

can't speed up the model
3 participants