Show
Ignore:
Timestamp:
02/12/10 16:02:09 (2 years ago)
Author:
apdavison
Message:

Various fixes from running doctests

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/nest/simulator.py

    r702 r708  
    271271    def __getitem__(self, i): 
    272272        """Return the `i`th connection on the local MPI node.""" 
    273         if i < len(self): 
    274             return Connection(self, i) 
    275         else: 
    276             raise IndexError("%d > %d" % (i, len(self)-1)) 
     273        if isinstance(i, int): 
     274            if i < len(self): 
     275                return Connection(self, i) 
     276            else: 
     277                raise IndexError("%d > %d" % (i, len(self)-1)) 
     278        elif isinstance(i, slice): 
     279            if i.stop < len(self): 
     280                return [Connection(self, j) for j in range(i.start, i.stop, i.step or 1)] 
     281            else: 
     282                raise IndexError("%d > %d" % (i.stop, len(self)-1)) 
     283             
    277284     
    278285    def __len__(self): 
     
    395402         
    396403        if parameter_name not in ('weight', 'delay'): 
    397             if parameter_name in self.parent.synapse_dynamics.fast.translations: 
    398                 parameter_name = self.parent.synapse_dynamics.fast.translations[parameter_name]["translated_name"] # this is a hack that works because there are no units conversions 
     404            translated_name = None 
     405            if self.parent.synapse_dynamics.fast and parameter_name in self.parent.synapse_dynamics.fast.translations: 
     406                translated_name = self.parent.synapse_dynamics.fast.translations[parameter_name]["translated_name"] # this is a hack that works because there are no units conversions 
     407            elif self.parent.synapse_dynamics.slow: 
     408                for component_name in "timing_dependence", "weight_dependence", "voltage_dependence": 
     409                    component = getattr(self.parent.synapse_dynamics.slow, component_name) 
     410                    if component and parameter_name in component.translations: 
     411                        translated_name = component.translations[parameter_name]["translated_name"] 
     412                        break 
     413            if translated_name: 
     414                parameter_name = translated_name 
    399415            else: 
    400416                raise Exception("synapse type does not have an attribute '%s', or else this attribute is not accessible." % parameter_name) 
     
    468484            #translation = self.parent.synapse_dynamics.reverse_translate({name: value}) 
    469485            #name, value = translation.items()[0] 
    470             name = self.parent.synapse_dynamics.fast.translations[name]["translated_name"] # a hack 
     486            translated_name = None 
     487            if self.parent.synapse_dynamics.fast: 
     488                if name in self.parent.synapse_dynamics.fast.translations: 
     489                    translated_name = self.parent.synapse_dynamics.fast.translations[name]["translated_name"] # a hack 
     490            if translated_name is None: 
     491                if self.parent.synapse_dynamics.slow: 
     492                    for component_name in "timing_dependence", "weight_dependence", "voltage_dependence": 
     493                        component = getattr(self.parent.synapse_dynamics.slow, component_name) 
     494                        if component and name in component.translations: 
     495                            translated_name = component.translations[name]["translated_name"] 
     496                            break 
     497            if translated_name: 
     498                name = translated_name 
    471499         
    472500        i = 0