You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Document traversal arrays and illustrate usage #1788
#1704 added numpy array versions of the basic tree traversal orders. Document these and provide an example of how they might be used. It would be neat if we could illustrate with some phylo algorithm that can be implemented directly with (non-obscure) numpy calls.
It would indeed be good to write the docstrings for these methods. Re examples, I've looked though the standard docs and we don't really document examples of using tree traversals there. The main text describing traversals is in the tutorials. I think we should describe an example there and provide a link from the docstring.
This is tricky though as we have to be careful about the branch lengths of the roots. That's possibly a good thing to warn people about if they're using these arrays though, as Python will quite happily use -1 indexes!
Activity
hyanwong commentedon Nov 25, 2021
It would indeed be good to write the docstrings for these methods. Re examples, I've looked though the standard docs and we don't really document examples of using tree traversals there. The main text describing traversals is in the tutorials. I think we should describe an example there and provide a link from the docstring.
hyanwong commentedon Nov 30, 2021
Here's a trivial example: count the average node arity of a tree
On a 100,000 tip tree this seems to be about 6 times faster than doing
A bit crap because it doesn't help with incremental calculations, but it is a very simple example, which is nice.
jeromekelleher commentedon Dec 1, 2021
That's a nice example @hyanwong, I like it. Might as well use
tree.preorder()though, as it's slightly faster and the ordering doesn't matter.jeromekelleher commentedon Dec 1, 2021
Simplest example I can think of is
This is tricky though as we have to be careful about the branch lengths of the roots. That's possibly a good thing to warn people about if they're using these arrays though, as Python will quite happily use
-1indexes!hyanwong commentedon Dec 1, 2021
Thanks. Example (with preorder) incorporated into #1963 with a "todo" to move to a reasonable location
hyanwong commentedon Dec 1, 2021
I think we can close this, as my example is in the docs, and @jeromekelleher 's example is linked to from tskit-dev/tutorials#150 (comment)