brian-team/brian2 — pull request #253 by mstimberg (2014-05-06 16:47:03+00:00)
Title: Indices and references

This is another approach to the issues surrounding references that have been discussed in #235 and the previous pull request #239. This approach is only based on weak and strong references, but introduces a new object that is used for indexing and keeps strong references to the variables that are needed for basic indexing. Contrary to what I said in one of the last comments on #239, this does not support any string indexing if the original group is no longer available, not even for `i` or `j`. In principle, it would be possible, but it would need some major refactoring and I don't think it's worth it.

The basic approach is that all objects only hold weak references to the objects they depend on, but `VariableView` also holds strong references to the respective variable and to an `Indexing` object, which itself holds strong references to what is needed for basic indexing (e.g. the pre- and postsynaptic indices for synaptic variables).

It seems to be working and passes all the tests that I wrote for #239 (also under Python 3, yay). It needs better error messages, documentation and more tests before merging, though.

The branch also contains the dependency tracking (#92).