Skip to content
Snippets Groups Projects
Commit 6695ba17 authored by Joseph Weston's avatar Joseph Weston
Browse files

Merge branch '96--accept-lists' into 'master'

Resolve "Learner1D fails when function returns a list instead of a numpy.array"

Closes #96

See merge request !101
parents 0dacb0e1 b18bfc1b
No related branches found
No related tags found
1 merge request!101Resolve "Learner1D fails when function returns a list instead of a numpy.array"
Pipeline #12070 passed
......@@ -219,6 +219,10 @@ class Learner1D(BaseLearner):
real = y is not None
if real:
# either it is a float/int, if not, try casting to a np.array
if not isinstance(y, (float, int)):
y = np.asarray(y, dtype=float)
# Add point to the real data dict
self.data[x] = y
# remove from set of pending points
......
......@@ -188,6 +188,19 @@ def test_uniform_sampling2D(learner_type, f, learner_kwargs):
assert max(distances) < math.sqrt(dx**2 + dy**2)
@pytest.mark.parametrize('learner_type, bounds', [
(Learner1D, (-1, 1)),
(Learner2D, [(-1, 1), (-1, 1)]),
(LearnerND, [(-1, 1), (-1, 1), (-1, 1)]),
])
def test_learner_accepts_lists(learner_type, bounds):
def f(x):
return [0, 1]
learner = learner_type(f, bounds=bounds)
simple(learner, goal=lambda l: l.npoints > 10)
@run_with(xfail(Learner1D), Learner2D, LearnerND)
def test_adding_existing_data_is_idempotent(learner_type, f, learner_kwargs):
"""Adding already existing data is an idempotent operation.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment