-
Notifications
You must be signed in to change notification settings - Fork 175
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
NengoObject should error on iteration #1176
Comments
Accidentally iterating over a NengoObject could be the source of infinite loops. Fixes #1176.
I think it might be better to check the dimensions in the |
Be my guest! Personally, I'm not sure if there's a lot of use for iterating over these things, but if you think it's worthwhile and not too difficult to implement and won't cause confusion, then go ahead. If that's something that can be done soon, then it can supercede #1177. Otherwise, I'd suggest going ahead with #1177 until iteration is implemented. |
Interstingly |
Actually it is not entirely clear to me what the desired behaviour in some cases should be. Assume we have a three-dimensional ensemble Integer indexingValid indices like Slice indexingFor slices in range like e = nengo.Ensemble(50, 2)
c = nengo.Connection(e[1:], post)
e.dimensions = 4 Will Currently neither of these things might happen. It seems that the code might fail because the slice will not get truncated, but |
First off, I think That being the case, then I agree that out-of-range integer indices should raise an |
I don't think |
Decisions from the dev meeting:
|
Re-thinking about the read-only question, I think it's probably fine to keep them as not read-only. In all our examples, I think we're pretty good about setting parameters when we make objects, either in the constructor or on the attributes right after creation. Maybe we want to add something to the documentation (I'm not sure where, we've talked about a style guide/best practices section before), but I think for the most part all attributes can be set right around creation time, and in that case all validation would work fine. The one situation where I could see a problem is if someone makes a model and runs it with some number of neurons, and then wants to try it again with a different number of neurons, and in making those changes directly on the model breaks something. But hopefully that's not too common, and the errors will eventually be caught in the builder. And there would be lots of times that wouldn't break anything and would be a useful feature, so might as well allow it. We can always re-consider pre-build validation, too. Maybe there's an easy way to do that by re-calling the "validate" functions on all the parameters, or maybe just the ones we're worried about. |
Integer indices out of bounds should raises an IndexError, whereas slices should get truncated silently. This has the added benefit of allowing iteration over Nengo objects. Fixes #1176.
Integer indices out of bounds should raises an IndexError, whereas slices should get truncated silently. This has the added benefit of allowing iteration over Nengo objects. Fixes #1176.
Integer indices out of bounds should raises an IndexError, whereas slices should get truncated silently. This has the added benefit of allowing iteration over Nengo objects. Fixes nengo#1176.
A
NengoObject
should raise an error if you iterate over it. Right now, something like this causes an infinite loop:This infinite loop will also occur if you try to multiply (or add, etc)
u
with a Numpy array. This can cause annoying bugs if one accidentally uses justprobe
instead ofsim.data[probe]
.I recommend we just raise an error in the
__iter__
function forNengoObject
.The text was updated successfully, but these errors were encountered: