diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bdc6637..f5715af 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,8 +19,8 @@ jobs: python-version: ${{ matrix.python }} - run: pip install ".${{ matrix.extras }}" - run: pip install codecov . - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - run: coverage run -m unittest nolds.test_measures - run: codecov + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} if: ${{ matrix.python == '3.10' && matrix.extras != '' }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 43fbfef..8a781f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). * Regression tests for all major algorithms that check for small changes in the main output value. ### Changed + +* Nolds now supports numpy 2.x as well as 1.x. + ### Fixed ## [0.6.0] diff --git a/nolds/datasets.py b/nolds/datasets.py index 739403c..65489a9 100644 --- a/nolds/datasets.py +++ b/nolds/datasets.py @@ -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 diff --git a/nolds/test_measures.py b/nolds/test_measures.py index 914e785..28a1acf 100644 --- a/nolds/test_measures.py +++ b/nolds/test_measures.py @@ -36,7 +36,7 @@ def assert_array_equals(self, expected, actual, print_arrays=False): print("==") print(expected) print() - self.assertTrue(np.alltrue(actual == expected)) + self.assertTrue(np.all(actual == expected)) def test_delay_embed_lag2(self): data = np.arange(10, dtype="float32") @@ -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 diff --git a/setup.py b/setup.py index ac929d4..6421510 100644 --- a/setup.py +++ b/setup.py @@ -57,7 +57,7 @@ def run(self): ], test_suite='nolds.test_measures', install_requires=[ - 'numpy<2.0', + 'numpy>1.0,<3.0', 'future', 'setuptools' ],