Skip to content

Commit

Permalink
Merge pull request #1531 from pints-team/numpy-2
Browse files Browse the repository at this point in the history
Updates for numpy 2 compatibility
  • Loading branch information
MichaelClerx authored Jul 8, 2024
2 parents 3f2f153 + f5f1a37 commit a4fc16e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 4 additions & 4 deletions pints/_optimisers/_nelder_mead.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ def ask(self):
self._xs[1 + i][i] *= x_grow

# Ask for initial points
return np.array(self._xs, copy=True)
return np.copy(self._xs)

# Shrink operation
if self._shrink:
for i in range(self._n_parameters):
self._xs[1 + i] = \
self._xs[0] + self._ys * (self._xs[1 + i] - self._xs[0])

return np.array(self._xs[1:], copy=True)
return np.copy(self._xs[1:])

# Start of normal iteration, ask for reflection point
if self._xr is None:
Expand Down Expand Up @@ -240,7 +240,7 @@ def tell(self, fx):

# Initialise
if self._fs is None:
fx = np.array(fx, copy=True)
fx = np.copy(fx)
if np.prod(fx.shape) != self._n_parameters + 1:
raise ValueError(
'Expecting a vector of length (1 + n_parameters).')
Expand All @@ -251,7 +251,7 @@ def tell(self, fx):

# Shrink
if self._shrink:
fx = np.array(fx, copy=False)
fx = np.asarray(fx)
if np.prod(fx.shape) != self._n_parameters:
raise ValueError(
'Expecting a vector of length n_parameters.')
Expand Down
11 changes: 9 additions & 2 deletions pints/tests/test_mcmc_relativistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
#
import unittest
import numpy as np
from scipy.integrate import cumtrapz, quad
from scipy.integrate import quad
from scipy.interpolate import interp1d
import pints
import pints.toy

from shared import StreamCapture

# For compatibility with scipy<1.12, released 2024-01-20
try:
from scipy.integrate import cumulative_trapezoid
except ImportError: # pragma: no cover
from scipy.integrate import cumtrapz as cumulative_trapezoid


class TestRelativisticMCMC(unittest.TestCase):
"""
Expand Down Expand Up @@ -238,7 +244,8 @@ def pdf(u):
# in this test, the values of m and c are nice enough that this
# function can be used for the comparison, and we check that the
# results are the same.
cdf = cumtrapz(1 / c * pdf(integration_grid), x=integration_grid)
cdf = cumulative_trapezoid(
1 / c * pdf(integration_grid), x=integration_grid)

# Interpolate to get approximate inverse
inv_cdf = interp1d([0.0] + list(cdf), integration_grid)
Expand Down

0 comments on commit a4fc16e

Please sign in to comment.