Skip to content
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

Tree.num_samples() inefficient in common case #598

Closed
jeromekelleher opened this issue Aug 29, 2018 · 0 comments
Closed

Tree.num_samples() inefficient in common case #598

jeromekelleher opened this issue Aug 29, 2018 · 0 comments

Comments

@jeromekelleher
Copy link
Member

The current implementation is

 def num_samples(self, u=None):
        roots = [u]
        if u is None:
            roots = self.roots
        return sum(self._ll_sparse_tree.get_num_samples(u) for u in roots)

This is elegant, but the sum and iterator can make tight loops that call num_samples take significantly longer than calling _ll_sparse_tree.get_num_samples(u).

Separate into two different code paths.

@jeromekelleher jeromekelleher added this to the Release 0.6.2 milestone Aug 29, 2018
jeromekelleher added a commit to mcveanlab/msprime that referenced this issue Sep 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant