brian-team/brian2 — pull request #264 by mstimberg (2014-06-12 16:50:31+00:00)
Title: Linked variables

This implements what we discussed in #189 and a bit more. Syntax-wise, I basically stayed with the Brian1 syntax, except for the explicit `(linked)` flag in the equations:
```Python
inp = NeuronGroup(10, 'dx/dt = ... : 1')
g = NeuronGroup(10, 'y : 1 (linked)')
g.y = linked_var(inp, 'x')
# alternative syntax
g.y = linked_var(inp.x)
```

Regarding the size of the groups, there are three possibilities (last one did not exist in Brian1):
1. The two groups have the same size
2. The source group has size 1 (this is the only use case in the Brian1 examples, it is useful e.g. to model shared noise)
3. The two groups have different sizes, but an explicit indexing array (or the name of a state variable) is provided

The last option allows to model repeating/tiling:
```Python
inp = NeuronGroup(2, 'dx/dt = ... : 1')
g = NeuronGroup(10, 'y : 1 (linked)')
g.y = linked_var(inp, 'x', index=np.arange(2).repeat(5))
```

For now, linked variables are only allowed for `NeuronGroup` (even though you can link to a synaptic variable...). There are a few tricky issues around using it with synapses, given that the number of synapses may change. Maybe postpone this feature until we have a clear use case for it?

Oh, and while you *can* link to linked variables, you cannot link to linked variables that have an indexing scheme in place -- we don't support arbitrarily deeply nested indices. This means that while you can link to a variable in a subgroup (effectively linking to the variable of the original group but with the appropriate indices), you cannot use explicit indices in this case.

I'll write some more documentation but from my side this is otherwise ready to merge.