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

adaptive.Learner2D does not allow return of 2D array #205

Open
tomlaeven opened this issue Jul 15, 2019 · 3 comments
Open

adaptive.Learner2D does not allow return of 2D array #205

tomlaeven opened this issue Jul 15, 2019 · 3 comments

Comments

@tomlaeven
Copy link

The following code causes the 2D learner to break, whereas the 1D learner works fine.

import adaptive
import numpy as np
adaptive.notebook_extension()


def f(x):
    return np.array([[x, x**2], [-x, 1/(1+x**2)]])


def g(xy):
    x, y = xy
    return np.array([[x, x**2], [-x, 1/(1+x**2)]])

learner1d = adaptive.Learner1D(f, [0, 1])
learner2d = adaptive.Learner2D(g, [[0, 1], [0, 1]])

runner1d = adaptive.Runner(learner1d, goal=lambda l: l.npoints > 1000)
runner1d.live_info()

runner2d = adaptive.Runner(learner2d, goal=lambda l: l.npoints > 1000)
runner2d.live_info()
@akhmerov
Copy link
Contributor

I don't think learner 1D is meant to work with 2D arrays. You may reshape your outputs to be a 1D array and then reshape them back though. Would that be a satisfactory solution?

@tomlaeven
Copy link
Author

The datasaver also allows for any data format, so it isn't really an issue anyway. The only thing is that because it works for a 1D learner, I also expected it to work for the 2D learner, which took me some time to figure out.

I think it might be nice to make it consistent, perhaps even by making it also break in the 1D case.

@akhmerov
Copy link
Contributor

I think the documentation is already stating what the learners expect, and it's uncommon in Python packages to do anything other than duck-typing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants