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

Numpy2 #56

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 != '' }}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
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
4 changes: 2 additions & 2 deletions nolds/test_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down 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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def run(self):
],
test_suite='nolds.test_measures',
install_requires=[
'numpy<2.0',
'numpy>1.0,<3.0',
'future',
'setuptools'
],
Expand Down