Skip to content

Commit

Permalink
modifications for faster implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonu0305 committed Jan 11, 2025
1 parent f0b4a9d commit bcaafce
Showing 1 changed file with 7 additions and 3 deletions.
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 @@ def numba_cumulative_trapezoid(f, x):
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 @@ def cumulative_integrate_array_by_blocks(f, x, block_references):
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

0 comments on commit bcaafce

Please sign in to comment.