Skip to content

Commit

Permalink
adjusts unit test for compatibility between numpy 1.x and numpy 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
CSchoel committed Oct 1, 2024
1 parent 7f6d927 commit 5822026
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions nolds/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ def lorenz_euler(length, sigma, rho, beta, dt=0.01, start=[1,1,1]):
"""
def lorenz(state, sigma, rho, beta):
x, y, z = state
# NOTE: Numpy 1.x stores intermediate results as float64
# => to achieve consistency between numpy versions, we have to use
# float32 for all values that enter the formula to simulate numpy 1.x
# behavior with numpy 2.x.
return np.array([
sigma * (y - x),
rho * x - y - x * z,
x * y - beta * z
np.float32(sigma) * (y - x),
np.float32(rho) * x - y - x * z,
x * y - np.float32(beta) * z
], dtype="float32")
trajectory = np.zeros((length, 3), dtype="float32")
trajectory[0] = start
for i in range(1, length):
t = i * dt
# t = i * dt
trajectory[i] = trajectory[i-1] + lorenz(trajectory[i-1], sigma, rho, beta) * dt
return trajectory

Expand Down
2 changes: 1 addition & 1 deletion nolds/test_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def test_lorenz(self):
x = data[discard:,1]
rvals = nolds.logarithmic_r(1, np.e, 1.1) # determined experimentally
cd = nolds.corr_dim(x, emb_dim, fit="poly", rvals=rvals, lag=lag)
self.assertAlmostEqual(cd, 2.05, delta=0.1)
self.assertAlmostEqual(cd, 2.05, delta=0.2)

def test_logistic(self):
# TODO replicate tests with logistic map from grassberger-procaccia
Expand Down

0 comments on commit 5822026

Please sign in to comment.