{"action":"created","issue":{"url":"https://api.github.com/repos/brian-team/brian2/issues/388","labels_url":"https://api.github.com/repos/brian-team/brian2/issues/388/labels{/name}","comments_url":"https://api.github.com/repos/brian-team/brian2/issues/388/comments","events_url":"https://api.github.com/repos/brian-team/brian2/issues/388/events","html_url":"https://github.com/brian-team/brian2/issues/388","id":54801339,"number":388,"title":"Allow explicit array access in string syntax","user":{"login":"thesamovar","id":2903870,"avatar_url":"https://avatars.githubusercontent.com/u/2903870?v=3","gravatar_id":"","url":"https://api.github.com/users/thesamovar","html_url":"https://github.com/thesamovar","followers_url":"https://api.github.com/users/thesamovar/followers","following_url":"https://api.github.com/users/thesamovar/following{/other_user}","gists_url":"https://api.github.com/users/thesamovar/gists{/gist_id}","starred_url":"https://api.github.com/users/thesamovar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thesamovar/subscriptions","organizations_url":"https://api.github.com/users/thesamovar/orgs","repos_url":"https://api.github.com/users/thesamovar/repos","events_url":"https://api.github.com/users/thesamovar/events{/privacy}","received_events_url":"https://api.github.com/users/thesamovar/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/brian-team/brian2/labels/enhancement","name":"enhancement","color":"207de5"},{"url":"https://api.github.com/repos/brian-team/brian2/labels/proposal","name":"proposal","color":"fbca04"},{"url":"https://api.github.com/repos/brian-team/brian2/labels/syntax","name":"syntax","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-01-19T19:12:48Z","updated_at":"2015-01-20T10:47:21Z","closed_at":null,"body":"A use case was suggested to me for explicit array access within strings. This is when you want to combine mathematically defined and recorded data into a model. For example, you might have recorded local connectivity structures, but join them up globally via a mathematical model. I think it would be sufficient to allow string syntax like the following: ``arr[i%N]*f(i,j)``. In other words, we'd allow flat 1D arrays and ``[]`` syntax. Thoughts?"},"comment":{"url":"https://api.github.com/repos/brian-team/brian2/issues/comments/70635714","html_url":"https://github.com/brian-team/brian2/issues/388#issuecomment-70635714","issue_url":"https://api.github.com/repos/brian-team/brian2/issues/388","id":70635714,"user":{"login":"mstimberg","id":1381982,"avatar_url":"https://avatars.githubusercontent.com/u/1381982?v=3","gravatar_id":"","url":"https://api.github.com/users/mstimberg","html_url":"https://github.com/mstimberg","followers_url":"https://api.github.com/users/mstimberg/followers","following_url":"https://api.github.com/users/mstimberg/following{/other_user}","gists_url":"https://api.github.com/users/mstimberg/gists{/gist_id}","starred_url":"https://api.github.com/users/mstimberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mstimberg/subscriptions","organizations_url":"https://api.github.com/users/mstimberg/orgs","repos_url":"https://api.github.com/users/mstimberg/repos","events_url":"https://api.github.com/users/mstimberg/events{/privacy}","received_events_url":"https://api.github.com/users/mstimberg/received_events","type":"User","site_admin":false},"created_at":"2015-01-20T10:47:21Z","updated_at":"2015-01-20T10:47:21Z","body":"To be clear, we are talking about using an externally defined array, right? So something like:\r\n```Python\r\narr = np.arange(10)\r\nG = NeuronGroup(20, 'v:1')\r\nG.v = 'arr[i % N]*mV'\r\n```\r\nWe can already do something like this in a complicated way with a dummy `NeuronGroup` and an index linked variable, but this is certainly not very convenient. It makes me think though whether we should use the same syntax in both cases, i.e. allow replacing the following example from the docs:\r\n```Python\r\n# two inputs with different phases\r\ninp = NeuronGroup(2, '''phase : 1\r\n                        dx/dt = 1*mV/ms*sin(2*pi*100*Hz*t-phase) : volt''')\r\ninp.phase = [0, pi/2]\r\n\r\nneurons = NeuronGroup(100, '''inp : volt (linked)\r\n                              dv/dt = (-v + inp) / tau : volt''')\r\n# Half of the cells get the first input, other half gets the second\r\nneurons.inp = linked_var(inp, 'x', index=repeat([0, 1], 50))\r\n```\r\nby \r\n```Python\r\n# two inputs with different phases\r\ninp = NeuronGroup(2, '''phase : 1\r\n                        dx/dt = 1*mV/ms*sin(2*pi*100*Hz*t-phase) : volt''')\r\ninp.phase = [0, pi/2]\r\n\r\nneurons = NeuronGroup(100, '''inp : volt (linked)\r\n                              dv/dt = (-v + inp[i%2]) / tau : volt''')\r\n```\r\nIt's nice to have the indexing as part of the equations, on the other hand we can't really do error checking any more if we allow arbitrary expressions for the indexing, and this could lead to segmentation faults in weave/cython/standalone.\r\n\r\nAlternatives I could think of:\r\n* Allow \"linking\" external arrays in the same way as a state variable of another group, i.e. with an explicit indexing array\r\n* An extension of the above, allow string expressions for the `index` argument of `linked_var` (with some restrictions?)"}}