Changeset 993

Show
Ignore:
Timestamp:
10/03/11 15:07:08 (8 months ago)
Author:
apdavison
Message:

Fixed bug when using connect() with single cell IDs (ticket:195)

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/common.py

    r991 r993  
    234234        self.parent._set_cell_initial_value(self, variable, value) 
    235235 
     236    def as_view(self): 
     237        """Return a PopulationView containing just this cell.""" 
     238        index = self.parent.id_to_index(self) 
     239        return self.parent[index:index+1] 
     240 
    236241 
    237242# ============================================================================= 
     
    329334        """ 
    330335        if isinstance(source, IDMixin): 
    331             source = source.parent 
     336            source = source.as_view() 
    332337        if isinstance(target, IDMixin): 
    333             target = target.parent 
     338            target = target.as_view() 
    334339        connector = connector_class(p_connect=p, weights=weight, delays=delay) 
    335340        return projection_class(source, target, connector, target=synapse_type, rng=rng) 
  • trunk/test/system/scenarios.py

    r917 r993  
    492492 
    493493    sim.end() 
     494 
     495@register() 
     496def ticket195(sim): 
     497    """ 
     498    Check that the `connect()` function works correctly with single IDs (see 
     499    http://neuralensemble.org/trac/PyNN/ticket/195) 
     500    """ 
     501    sim.setup(timestep=0.01) 
     502    pre = sim.Population(10, sim.SpikeSourceArray, cellparams={'spike_times':range(1,10)}) 
     503    post = sim.Population(10, sim.IF_cond_exp) 
     504    sim.connect(pre[0], post[0], weight=0.01, delay=0.1, p=1) 
     505    post.record() 
     506    sim.run(100.0) 
     507    assert_arrays_almost_equal(post.getSpikes(), numpy.array([[0.0, 13.4]]), 0.5) 
     508 
  • trunk/test/unittests/test_lowlevelapi.py

    r858 r993  
    2424     
    2525    class MockID(common.IDMixin): 
    26         def __init__(self): 
    27             self.parent = "parent" 
    28          
     26       def as_view(self): 
     27            return "view" 
     28  
    2929    prj = connect_function(MockID(), MockID(), "weight", "delay", "synapse_type", "p", "rng") 
    30     projection_class.assert_called_with("parent", "parent", "connector", target="synapse_type", rng="rng") 
     30    projection_class.assert_called_with("view", "view", "connector", target="synapse_type", rng="rng") 
    3131     
    3232def test_set():