-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[Exp PyROOT] Add TCollection and TIter pythonisations and tests #3298
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
Conversation
|
Starting build on |
|
@phsft-bot build just on ROOT-performance-centos7-multicore/default, ROOT-fedora29/python3 with flags -Dpyroot_experimental=ON |
|
Starting build on |
|
@phsft-bot build just on ROOT-performance-centos7-multicore/default, ROOT-fedora29/python3 with flags -Dpyroot_experimental=ON -DCTEST_TEST_EXCLUDE_NONE=ON |
|
Starting build on |
|
just wanted to try out... |
dpiparo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great improvement. I suggested some changes. Do we perhaps need tutorials for this?
| # - c: collection to extend self with | ||
| lenc = c.GetEntries() | ||
| it = TIter(c) | ||
| for i in range(lenc): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good bot!
| # Python-list-like methods | ||
|
|
||
| def _remove_pyz(self, o): | ||
| # Parameters: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alignment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
| # - Number of occurrences of the object in the collection | ||
| n = 0 | ||
|
|
||
| it = TIter(self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe using range iteration (root collections have a begin and an end) is simpler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what you are suggesting, how are begin and end useful from Python?
| # - self: collection to be iterated | ||
| # Returns: | ||
| # - TIter iterator on collection | ||
| return TIter(self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as a curiosity: if you use just begin() and return the stl iterator, it works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean returning self.begin() here?
| # - c: collection to extend self with | ||
| lenc = c.GetEntries() | ||
| it = TIter(c) | ||
| for i in range(lenc): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| for i in range(lenc): | |
| for _ in range(lenc): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
| # Make TIter a Python iterator. | ||
| # This makes it possible to iterate over TCollections, since Cppyy | ||
| # injects on them an `__iter__` method that returns a TIter. | ||
| klass.__next__ = _next_pyz # Py3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need both for both versions or we can make the two cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is quite common to just assign both to the same function, and it does not harm anyway, see e.g. :
https://portingguide.readthedocs.io/en/latest/iterators.html#new-iteration-protocol-next
This PR mainly adds pythonisations for
TCollectionand its subclasses. It also adds a pythonisation forTIter, which is necessary to iterate overTCollections.The corresponding unit tests for every pythonisation are also proposed.