Changeset 379 for trunk

Show
Ignore:
Timestamp:
02/24/09 13:40:11 (3 years ago)
Author:
apdavison
Message:

Moved the test for RPy into the function within which it is used, to avoid importing it every time the module is used.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/stgen.py

    r356 r379  
    162162        if seed != None: 
    163163            self.rng.seed(seed) 
     164        self.rpy_checked = False 
    164165 
    165166    def seed(self,seed): 
     
    283284        # return empty if no spikes 
    284285        if len(ps) == 0: 
    285             return SpikeTrain(numpy.array([]), t_start=t[0],t_stop=t_stop) 
     286            if array: 
     287                return numpy.array([]) 
     288            else: 
     289                return SpikeTrain(numpy.array([]), t_start=t[0],t_stop=t_stop) 
    286290         
    287291        # gen uniform rand on 0,1 for each spike 
     
    390394    # use slow python implementation for the time being 
    391395    # TODO: provide optimized C/weave implementation if possible 
    392  
    393  
    394     def _inh_gamma_generator_unimplemented(self, a, b, t, t_stop, array=False): 
    395         raise Exception("inh_gamma_generator is disabled as dependency RPy was not found.") 
    396  
    397     if check_dependency('rpy'): 
    398         inh_gamma_generator = _inh_gamma_generator_python 
    399     else: 
    400         inh_gamma_generator = _inh_gamma_generator_unimplemented 
     396       
     397    def inh_gamma_generator(self, a, b, t, t_stop, array=False): 
     398        if not self.rpy_checked: 
     399            self.have_rpy = check_dependency('rpy') 
     400            self.rpy_checked = True 
     401        if self.have_rpy: 
     402            return self._inh_gamma_generator_python(a, b, t, t_stop, array) 
     403        else: 
     404            raise Exception("inh_gamma_generator is disabled as dependency RPy was not found.") 
    401405 
    402406