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

Matrix gain results in cryptic error with encoders #1651

Open
hunse opened this issue Nov 6, 2020 · 1 comment
Open

Matrix gain results in cryptic error with encoders #1651

hunse opened this issue Nov 6, 2020 · 1 comment

Comments

@hunse
Copy link
Collaborator

hunse commented Nov 6, 2020

Describe the bug

Creating an ensemble with a gain/bias distribution that results in a matrix (e.g. nengo.dists.Choice([[1.0]])) results in a cryptic build error (because the encoders end up being a 3-tensor):

  File "workspace/nengo/nengo/builder/operator.py", line 539, in reshape_dot
    "shape mismatch in %s: %s x %s -> %s" % (tag, A.shape, X.shape, Y.shape)
nengo.exceptions.BuildError: shape mismatch in <Ensemble (unlabeled) at 0x7fdb36501f98> encoding: (100, 100, 1) x (1,) -> (100,)

To reproduce

import nengo

with nengo.Network() as net:
    u = nengo.Node([0])
    a = nengo.Ensemble(
        100, 1, gain=nengo.dists.Choice([[1.0]]), bias=nengo.dists.Choice([[0.0]])
    )
    nengo.Connection(u, a)

with nengo.Simulator(net) as sim:
    sim.step()

Expected behavior

Ideally, we should catch this before build. Either way, the resulting error should clearly point to the problem.

We could also consider fixing this so the case where a 1-D vector is passed to Choice (as above) works.

@drasmuss
Copy link
Member

This has come up a few different places recently, we should add some better validation for Distributions in general (e.g. sample something from the dist and check the shape in the same way we do if a direct ndarray is used).

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

No branches or pull requests

2 participants