Skip to content
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

Use vectorize instead of jit in EOS #66

Merged
merged 2 commits into from
Dec 4, 2020
Merged

Conversation

rabernat
Copy link
Contributor

@rabernat rabernat commented Sep 28, 2020

This PR replaces the use of the @jit numba decorator with the @vectorize decorator in the eos calculation. According to the numba docs, @vectorize is the recommended way to create a numpy ufunc, which I believe is what is wanted here.

The speedup on my laptop is about 3x:

import numpy as np
from pop_tools import eos

N = 10_000_000
salt = 30 + 10 * np.random.random_sample(N)
theta = -2 + 30 * np.random.random_sample(N)
pres = 5000 * np.random.random_sample(N)

%timeit eos(salt, theta, pressure=pres)
# master -> 326 ms ± 2.65 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
# this PR -> 92.2 ms ± 855 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

I also removed what seems to be an unnecessary if clause regarding xarray.apply_ufunc.

Copy link
Contributor

@dcherian dcherian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Ryan

@dcherian dcherian closed this Dec 4, 2020
@dcherian dcherian reopened this Dec 4, 2020
@xdev-bot xdev-bot closed this Dec 4, 2020
@xdev-bot xdev-bot reopened this Dec 4, 2020
@dcherian dcherian merged commit 0440104 into NCAR:master Dec 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants