-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
add assumption benchmark of core #73
base: master
Are you sure you want to change the base?
Conversation
self.z_0.is_commutative is True | ||
self.z_0.is_integer is True | ||
self.z_0.is_rational is True | ||
self.z_0.is_algebraic is True |
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 don't think it's necessary to test all of these. Benchmarks should be as narrow as possible (they should time precisely one thing). Also After checking z_0.is_integer
the results of the other operations will be cached for any Basic instance anyway e.g.:
In [1]: a = Add(2, 2, evaluate=False)
In [2]: a._assumptions
Out[2]: {}
In [3]: a.is_integer
Out[3]: True
In [4]: a._assumptions
Out[4]:
{'integer': True,
'algebraic': True,
'rational': True,
'hermitian': True,
'commutative': True,
'irrational': False,
'complex': True,
'infinite': False,
'imaginary': False,
'transcendental': False,
'finite': True,
'extended_real': True,
'noninteger': False,
'real': True}
The examples you have picked mostly have precomputed cached assumptions: In [5]: S.One._assumptions
Out[5]:
{'commutative': True,
'real': True,
'imaginary': False,
'infinite': False,
'complex': True,
'hermitian': True,
'finite': True,
'extended_real': True,
'integer': True,
'algebraic': True,
'rational': True,
'irrational': False,
'transcendental': False,
'noninteger': False,
'zero': False,
'extended_nonzero': True,
'nonzero': True,
'even': False,
'odd': True,
'extended_negative': False,
'negative': False,
'extended_positive': True,
'nonpositive': False,
'extended_nonpositive': False,
'extended_nonnegative': True,
'positive': True,
'nonnegative': True} It's reasonable to time the performance of this but I don't think we would need to do it exhaustively. It would be better to time some things that are slow or have the potential to be slow e.g.: In [17]: x = Symbol('x', positive=True)
In [18]: p = random_poly(x, 10, -10, 10)
In [19]: p
Out[19]:
10 9 8 7 5 4 3 2
- 4⋅x + 8⋅x + 9⋅x + 3⋅x + 5⋅x - 7⋅x - 6⋅x - 8⋅x + 2⋅x + 1
In [20]: %time p.is_positive
CPU times: user 396 ms, sys: 1.68 ms, total: 398 ms
Wall time: 403 ms
In [21]: %time p.is_positive
CPU times: user 8 µs, sys: 0 ns, total: 8 µs
Wall time: 13.1 µs Note that the second run of is_positive here is instantaneous because the result is cached on the instance: In [22]: p._assumptions
Out[22]:
{'positive': None,
'finite': True,
'infinite': False,
'extended_positive': None,
'extended_real': True,
'commutative': True,
'imaginary': False,
'real': True,
'complex': True,
'hermitian': True,
'extended_nonpositive': None,
'negative': None,
'extended_negative': None,
'zero': None,
'odd': None,
'irrational': None,
'rational': None,
'algebraic': None,
'integer': None,
'extended_nonnegative': None} |
Okay, got it. I can close this pr, or may I will keep only one benchmark from each function. But I think it is not necessary to benchmark these assumptions. So whatever suitable you can tell me. |
I think it's good to keep a small number of these benchmarks just to make sure that something like
|
There's also no point to doing the |
ok, I will try to add like this. |
I have added assumption benchmarks. I will add a few more commits to the assumption bench.
Then we can merge it. Also, if anything you want to modify in the code, then please tell.