-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from jrenaud90/fix-bad-array-returns
Fix bad array returns
- Loading branch information
Showing
8 changed files
with
97 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import numpy as np | ||
from CyRK import pysolve_ivp | ||
import gc | ||
|
||
|
||
def diffeq(dy, t, y): | ||
dy[0] = (1. - 0.01 * y[1]) * y[0] | ||
dy[1] = (0.02 * y[0] - 1.) * y[1] | ||
|
||
initial_conds = np.asarray((20., 20.), dtype=np.float64, order='C') | ||
time_span = (0., 10.) | ||
time_span_large = (0., 1000.) | ||
rtol = 1.0e-4 | ||
atol = 1.0e-7 | ||
|
||
def run_diffeq_array_return(): | ||
result = pysolve_ivp(diffeq, time_span, initial_conds, method="RK45", rtol=rtol, atol=atol, pass_dy_as_arg=True) | ||
|
||
t = result.t | ||
y = result.y | ||
del result | ||
gc.collect() | ||
return t, y | ||
|
||
def run_diffeq_result_return(): | ||
result = pysolve_ivp(diffeq, time_span, initial_conds, method="RK45", rtol=rtol, atol=atol, pass_dy_as_arg=True) | ||
return result | ||
|
||
def test_pysolve_array_lifetimes(): | ||
""" Tests that the underlying arrays returned by the WrapCySolverResult class can outlive the class instance. """ | ||
|
||
# Run in a loop because sometimes memory corruptions can take a while to appear | ||
for i in range(50): | ||
# Get result from the result instance class | ||
result = run_diffeq_result_return() | ||
|
||
# Get arrays from the array return | ||
t, y = run_diffeq_array_return() | ||
|
||
# Check that they contain the same data | ||
assert result.y.size == y.size | ||
assert result.t.size == t.size | ||
|
||
assert np.allclose(result.y, y) | ||
assert np.allclose(result.t, t) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters