Remove use of NumPy for scalar math in jellium.py#1358
Conversation
Previously, NumPy functions were used for scalar math. Changing to Python standard math library could yield to slight speedups.
There was a problem hiding this comment.
Code Review
This pull request replaces usages of the numpy library with the standard library math module for basic mathematical operations (such as pi, sqrt, cos, and floor) in jellium.py, allowing the removal of the numpy import. Additionally, a docstring has been converted to a raw string to properly handle LaTeX escape sequences. There are no review comments, and I have no further feedback to provide.
mhucka
left a comment
There was a problem hiding this comment.
This looks good, with one possible issue. The math.cos function may given an error if momenta.dot() returns an array (even a 1-D array).
math.cos(momenta.dot(differences))(Credit goes to Gemini for flagging this.) I didn't trace the code carefully to see if that can actually happen, but if there's a chance of that, maybe cast the dot product output explicitly to a scalar float before passing it to math.cos:
math.cos(float(momenta.dot(differences)))Otherwise LGTM.
Previously, NumPy functions were used for scalar math in
jellium.py. Using the Python standard math library instead should yield slight speedups.