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 np.lcm #4904
Implement np.lcm #4904
Conversation
@esc, I think this is ready for review – though that might be easier once the gcd branch merges. The only relevant commits here are the most recent two. Two notes:
Also, here is a quick benchmark: import numpy as np
from numba import njit
def lcm(a, b):
np.lcm(a, b)
nlcm = njit(lcm)
plcm = njit(parallel=True)(lcm)
a = np.random.randint(0, 10000000, 10000)
b = np.random.randint(0, 10000000, 10000)
# warmups
nlcm(a, b)
plcm(a, b)
%timeit lcm(a, b)
1.45 ms ± 22.4 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
%timeit nlcm(a, b)
591 µs ± 6.99 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
%timeit plcm(a, b)
133 µs ± 14.4 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each) |
@ivirshup thanks for updating this, I have changed the label of the PR accordingly. The benchmarks look impressive from a first glance. 👍 |
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
@stuartarchibald, done rebasing |
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 for the PR. Looks good.
Building on #4780, this PR implements
np.lcm
as a ufunc. It's very similar to that PR, and uses much of the same boiler-plate.