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

Modified fast_array_util.py for faster implementation #2940

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions tardis/plasma/properties/continuum_processes/fast_array_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@njit(**njit_dict)
def numba_cumulative_trapezoid(f, x):
"""
Cumulatively integrate f(x) using the composite trapezoidal rule.
Cumulatively integrate f(x) using the composite trapezoidal rule using a loop.

Parameters
----------
Expand All @@ -23,7 +23,11 @@
numpy.ndarray, dtype float
The result of cumulative integration of f along x
"""
integ = (np.diff(x) * (f[1:] + f[:-1]) / 2.0).cumsum()
n = len(f)
integ = np.zeros(n, dtype=np.float64)
for i in range(1, n):
dx = x[i] - x[i-1]
integ[i] = integ[i-1] + (f[i] + f[i-1]) * dx / 2.0

Check warning on line 30 in tardis/plasma/properties/continuum_processes/fast_array_util.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/properties/continuum_processes/fast_array_util.py#L26-L30

Added lines #L26 - L30 were not covered by tests
return integ / integ[-1]


Expand Down Expand Up @@ -59,7 +63,7 @@
for j in prange(n_rows): # rows
start = block_references[j]
stop = block_references[j + 1]
integrated[start + 1 : stop, i] = numba_cumulative_trapezoid(
integrated[start : stop, i] = numba_cumulative_trapezoid(

Check warning on line 66 in tardis/plasma/properties/continuum_processes/fast_array_util.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/properties/continuum_processes/fast_array_util.py#L66

Added line #L66 was not covered by tests
f[start:stop, i], x[start:stop]
)
return integrated
Loading