diff --git a/pints/_optimisers/_nelder_mead.py b/pints/_optimisers/_nelder_mead.py index 50631e07e..799f6155d 100644 --- a/pints/_optimisers/_nelder_mead.py +++ b/pints/_optimisers/_nelder_mead.py @@ -186,7 +186,7 @@ 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: @@ -194,7 +194,7 @@ def ask(self): 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: @@ -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).') @@ -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.') diff --git a/pints/tests/test_mcmc_relativistic.py b/pints/tests/test_mcmc_relativistic.py index d5893a8c0..3fcd5d90a 100755 --- a/pints/tests/test_mcmc_relativistic.py +++ b/pints/tests/test_mcmc_relativistic.py @@ -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): """ @@ -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)