Show
Ignore:
Timestamp:
03/10/10 11:16:33 (2 years ago)
Author:
apdavison
Message:

A few connector-related fixes, plus a new unit test for distance-dependent weights.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/connectors.py

    r722 r725  
    1919from numpy import arccos, arcsin, arctan, arctan2, ceil, cos, cosh, e, exp, \ 
    2020                  fabs, floor, fmod, hypot, ldexp, log, log10, modf, pi, power, \ 
    21                   sin, sinh, sqrt, tan, tanh 
     21                  sin, sinh, sqrt, tan, tanh, maximum, minimum 
    2222from pyNN import random, common, errors, core 
    2323from pyNN.space import Space 
     
    5858    """Base class for Connector classes.""" 
    5959     
    60     def __init__(self, weights=0.0, delays=None): 
     60    def __init__(self, weights=0.0, delays=None, space=None): 
    6161        self.w_index = 0 # should probably use a generator 
    6262        self.d_index = 0 # rather than storing these values 
     
    7171        else: 
    7272            self.delays = delays 
    73          
    7473        if delays is None: 
    7574            self.delays = common.get_min_delay() 
     75        if space is not None: 
     76            assert isinstance(space, Space) 
     77            self.space = space 
    7678         
    7779    def connect(self, projection): 
     
    9597        return delays 
    9698 
     99    def reset(self): 
     100        """ 
     101        After running connect(), this should be called to reset attributes that 
     102        have been modified to their initial values. 
     103        """ 
     104        if hasattr(self, "w_expr"): 
     105            self.weights = numpy.empty((1,0)) 
     106        if hasattr(self, "d_expr"): 
     107            self.delays = numpy.empty((1,0)) 
     108        self.w_index = 0 # should probably use a generator 
     109        self.d_index = 0 # rather than storing these values 
     110     
    97111     
    98112class ProbabilisticConnector(Connector): 
     
    147161            if len(targets) > 0: 
    148162                projection.connection_manager.connect(src, targets, weights, delays) 
    149  
     163        self.reset()         
    150164 
    151165class AllToAllConnector(ProbabilisticConnector): 
     
    169183                     to the global minimum delay. 
    170184        """ 
    171         Connector.__init__(self, weights, delays) 
     185        Connector.__init__(self, weights, delays, space) 
    172186        assert isinstance(allow_self_connections, bool) 
    173187        self.allow_self_connections = allow_self_connections 
     
    479493                     to the global minimum delay. 
    480494        """ 
    481         Connector.__init__(self, weights, delays) 
     495        Connector.__init__(self, weights, delays, space) 
    482496        assert isinstance(allow_self_connections, bool) 
    483497        self.allow_self_connections = allow_self_connections 
     
    521535                     to the global minimum delay. 
    522536        """ 
    523         Connector.__init__(self, weights, delays) 
     537        Connector.__init__(self, weights, delays, space) 
    524538        assert isinstance(d_expression, str) 
    525539        try: 
     
    529543            raise ZeroDivisionError("Error in the distance expression %s. %s" % (d_expression, err)) 
    530544        self.d_expression = d_expression 
    531         self.space = space 
    532545        assert isinstance(allow_self_connections, bool) 
    533546        self.allow_self_connections = allow_self_connections 
    534         assert isinstance(space, Space) 
    535         self.space = space 
    536547         
    537548