ctn-waterloo/nengo — pull request #326 by drasmuss (2014-04-11 21:37:03+00:00)
Title: Nodes can handle functions that don't return a value.

Fix for Issue #324; it shouldn't be necessary for Node functions to return a value (e.g. if they are modifying some state in the script, or outputting to screen/file). This is an attempt to make that work.

The basic idea is that if `size_out` of the Node is 0, then the simulator just calls the Node function and doesn't do anything with the returned value.

Right now I have it so that it will try to guess if `size_out` should be 0 at creation time. When it calls the function to determine the `size_out`, if it gets back `None`, it sets `size_out` to 0. Another option would be to force the user to explicitly specify the `size_out`.

The only weird case is if the user's function returns `None` in some cases, but not in others (e.g. see the first test in `test_node.test_none`). Then you get different outcomes depending on whether it returns `None` during the automatic check designed above. If it does return `None`, then this will just assume that the function always returns `None` and ignore whatever values it returns later on. If it does not return `None` initially, then the system will expect a proper value to be returned all the time, and when it returns `None` later on you'll get an error (this was how it worked all the time prior to this commit).

This ambiguity, although somewhat of an edge case, may be an argument for forcing the user to specify `size_out=0` if they don't want to return a value. It just depends whether people think avoiding that ambiguity is worth having to include `size_out=0` for any Node that returns `None`.