diff --git a/pySOT/surrogate/surrogate.py b/pySOT/surrogate/surrogate.py index 89edafd..107fc6c 100644 --- a/pySOT/surrogate/surrogate.py +++ b/pySOT/surrogate/surrogate.py @@ -56,11 +56,10 @@ def add_points(self, xx, fx): :param xx: Points to add :type xx: numpy.ndarray :param fx: The function values of the point to add - :type fx: numpy.array or float + :type fx: array-like or scalar """ xx = np.atleast_2d(xx) - if isinstance(fx, float): - fx = np.array([fx]) + fx = np.asarray(fx) if fx.ndim == 0: fx = np.expand_dims(fx, axis=0) if fx.ndim == 1: diff --git a/tests/test_surrogates.py b/tests/test_surrogates.py index 3cfbf97..f6ae282 100644 --- a/tests/test_surrogates.py +++ b/tests/test_surrogates.py @@ -163,6 +163,15 @@ def test_rbf(): assert la.norm(df(np.atleast_2d(X[0, :])) - dfhx) < 1e-1 +def test_add_points_accepts_integer_function_value(): + rbf = RBFInterpolant(dim=2, lb=np.zeros(2), ub=np.ones(2)) + + rbf.add_points(np.array([0.25, 0.75]), 1) + + assert rbf.fX.shape == (1, 1) + np.testing.assert_allclose(rbf.fX, np.array([[1.0]])) + + def test_gp(): X = make_grid(30) # Make uniform grid with 30 x 30 points gp = GPRegressor(dim=2, lb=np.zeros(2), ub=np.ones(2))