-
Notifications
You must be signed in to change notification settings - Fork 737
Add convenience function qml.math.ceil_log2
#8972
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
|
Hello. You may have forgotten to update the changelog!
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #8972 +/- ##
=======================================
Coverage 99.44% 99.44%
=======================================
Files 601 601
Lines 64754 64759 +5
=======================================
+ Hits 64393 64398 +5
Misses 361 361 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Oh thanks for catching those! The first two I overlooked because they are in n = 0
a = np.log2(n) # -np.inf
b = np.ceil(a) # -np.inf
c = 2**b # 0.0I know, it's a bit of an unconventional computational path, but there actually is a test taking it (which is why I know, heh.) |
Glad to be of service. Sounds interesting, while I don't understand why we want to do that with the negative infinities etc. |
Unfortunately I am missing the context here myself, but it seems to be a supported case that |
comp-phys-marc
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.
Looks great! Good QoL improvement.
andrijapau
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.
Thanks 🚀 !

Context:$\lceil \log_2(n)\rceil$ of an integer $n$ .
We often want to compute the integer
This currently requires three function calls if we want to receive an
intas output:out = int(np.ceil(np.log2(n)))In various places in the codebase, the call to
intis actually skipped, so that variables that conceptually describe integers remain float values in code.Description of the Change:
Add a convenience function
qml.math.ceil_log2that bundles the three function calls into one.Benefits:
Declutter code base.
Make sure we are using
intvalues where applicable.Possible Drawbacks:
N/A
Related GitHub Issues: