Skip to content

Enable edge/path sorting #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 7, 2018
Merged

Enable edge/path sorting #22

merged 4 commits into from
Jun 7, 2018

Conversation

dhimmel
Copy link
Member

@dhimmel dhimmel commented Jun 7, 2018

Enable deterministic extract_metapaths ordering

dhimmel added 2 commits June 7, 2018 11:56
Enable deterministic extract_metapaths ordering
hetio/hetnet.py Outdated
@@ -200,6 +203,13 @@ def __hash__(self):
def __eq__(self, other):
return (type(other) is type(self)) and (self.edges == other.edges)

def __lt__(self, other):
if len(self) < len(other):
Copy link
Member

Choose a reason for hiding this comment

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

Would this be clear enough?

def __lt__(self, other):
    if len(self) != len(other):
        return len(self) < len(other)
    return self.edges < other.edges

What you have is fine too, though.

metapaths_with_inverses.add(covered_metapath)
return metapaths
if exclude_inverts:
metapath, _ = sorted([metapath, metapath.inverse])
Copy link
Member

Choose a reason for hiding this comment

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

Nice

# Test metapaths are sorted
abbreviations = [str(metapath) for metapath in metapaths]
assert abbreviations[:4] == [
'CtD',
Copy link
Member

Choose a reason for hiding this comment

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

Top two should be swapped

@dhimmel dhimmel merged commit f2e525a into master Jun 7, 2018
@dhimmel dhimmel deleted the edge-sort branch June 7, 2018 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants