-
Notifications
You must be signed in to change notification settings - Fork 65
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
Implement separate __eq__
methods
#1033
Conversation
Pull Request Test Coverage Report for Build 4719168322
💛 - Coveralls |
Just like with |
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.
Some comments. Will look at core.py next, then tests
@damonge all done, back to you now and we can move on with the rest if you are happy with the changes. |
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 one (maybe major) comment for core.py
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.
Final comments on tests
@damonge back to you |
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.
OK, we're done. Merge when the tests pass.
As @rmjarvis and @marcpaterno correctly pointed out, we can save loads of time comparing
CCLObjects
if we compare parameters instead of strings. To that end, I extended some functionality that was already there to do parameter comparisons for most objects.Just like the
__repr_attrs__
class variable, which automatically builds a repr using a list of specified arguments,__eq_attrs__
now makes sure that the default__eq__
is overridden and that the individual attributes are compared one-by-one.For example, in the
Cosmology
object, we only need to add this line in the beginning:There are only 3 classes where this is not possible (because we have to check the C-level objects):
Pk2D
,Tk3D
,Tracer
. For these, I implemented full__eq__
methods as per the usual way.Timings show that this way is indeed much faster (
bld
is therepr
):Note, however, that with the current implementation in
master
, the first computation of_repr
might be slow, but every new call to__eq__
is of the order of nanoseconds (compare to microseconds with this PR proposal). It is a trade-off. So, if we compare objects sequentially (and discard the old one if they are not equal, like in an MCMC) this PR wins. But if we compare one object with several others, the currently implemented way wins.