Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Prepare for a future removal of scipy.weave (replaced by weave)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Stimberg committed Feb 16, 2016
1 parent 82e3119 commit 52dd8ef
Show file tree
Hide file tree
Showing 22 changed files with 132 additions and 64 deletions.
6 changes: 5 additions & 1 deletion brian/connections/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
from .. import magic
from ..log import log_warn, log_info, log_debug
from numpy import *
from scipy import sparse, stats, rand, weave, linalg
try:
import weave
except ImportError:
from scipy import weave
from scipy import sparse, stats, rand, linalg
import scipy
import scipy.sparse
import numpy
Expand Down
6 changes: 4 additions & 2 deletions brian/equations.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@
'''
Differential equations for Brian models.
'''
#from scipy.weave import blitz
from operator import isSequenceType
import types
from units import *
from stdunits import *
from inspection import *
from scipy import exp
from scipy import weave
try:
import weave
except ImportError:
from scipy import weave
from globalprefs import *
import re
import inspect
Expand Down
7 changes: 5 additions & 2 deletions brian/experimental/c_stdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@
from ..optimiser import freeze
from ..utils.separate_equations import separate_equations
from codegen.c_support_code import *
from scipy import weave
try:
import weave
except ImportError:
from scipy import weave
import re

__all__ = ['CSTDP']



class CSTDP(NetworkOperation):
def __init__(self, C, eqs, pre, post, wmin=0, wmax=Inf, level=0,
clock=None, delay_pre=None, delay_post=None):
Expand Down
13 changes: 8 additions & 5 deletions brian/experimental/codegen/reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from ...globalprefs import get_global_preference
from ...log import log_warn
from expressions import *
from scipy import weave
try:
import weave
except ImportError:
from scipy import weave
from c_support_code import *

__all__ = ['generate_c_reset', 'generate_python_reset',
Expand Down Expand Up @@ -58,13 +61,13 @@ def generate_python_reset(eqs, inputcode, level=0, ns=None):
code += line + '\n'
return code



class PythonReset(Reset):
def __init__(self, inputcode, level=0):
self._ns, unknowns = namespace(inputcode, level=level + 1, return_unknowns=True)
self._inputcode = inputcode
self._prepared = False


def __call__(self, P):
ns = self._ns
if not self._prepared:
Expand All @@ -80,7 +83,7 @@ def __call__(self, P):
ns['_spikes'] = spikes
exec cc in ns



class CReset(Reset):
def __init__(self, inputcode, level=0):
self._ns, unknowns = namespace(inputcode, level=level + 1, return_unknowns=True)
Expand All @@ -96,7 +99,7 @@ def __init__(self, inputcode, level=0):
self._extra_link_args = ['-fopenmp']
else:
self._extra_link_args = []


def __call__(self, P):
if not self._prepared:
vars = [var for var in P.var_index if isinstance(var, str)]
Expand Down
13 changes: 8 additions & 5 deletions brian/experimental/codegen/stateupdaters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
from codegen_python import *
from integration_schemes import *
import time
from scipy import weave
try:
import weave
except ImportError:
from scipy import weave
import numpy, scipy
import re
from c_support_code import *
Expand All @@ -17,7 +20,7 @@

__all__ = ['CStateUpdater', 'PythonStateUpdater']



class CStateUpdater(StateUpdater):
def __init__(self, eqs, scheme, clock=None, freeze=False):
self.clock = guess_clock(clock)
Expand Down Expand Up @@ -51,7 +54,7 @@ def __init__(self, eqs, scheme, clock=None, freeze=False):
self._arrays_to_check.append((varname, varval))
self.code_c = re.sub(r'\b'+varname+r'\b', varname+'[_i]', self.code_c)
break


def __call__(self, P):
if self._arrays_to_check is not None:
N = len(P)
Expand All @@ -77,7 +80,7 @@ def __call__(self, P):
self.__init__(self.eqs, self.scheme, self.clock, self.freeze)
self.__call__(P)



class PythonStateUpdater(StateUpdater):
def __init__(self, eqs, scheme, clock=None, freeze=False):
eqs.prepare()
Expand Down Expand Up @@ -113,7 +116,7 @@ def __init__(self, eqs, scheme, clock=None, freeze=False):
log_debug('brian.experimental.codegen.stateupdaters', 'Python state updater code:\n' + self.code_python)
exec self.code_python in self.namespace
self.state_update_func = self.namespace['_stateupdate']


def __call__(self, P):
self.state_update_func(P._S, P.clock._dt, P.clock._t, len(P))

Expand Down
5 changes: 4 additions & 1 deletion brian/experimental/codegen/test_hh.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
from brian.library.ionic_currents import *
from brian.experimental.codegen import *
import time
from scipy import weave
try:
import weave
except ImportError:
from scipy import weave

N = 1000
record_and_plot = N == 1
Expand Down
5 changes: 4 additions & 1 deletion brian/experimental/codegen/threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from ...globalprefs import get_global_preference
from ...log import log_warn
from expressions import *
from scipy import weave
try:
import weave
except ImportError:
from scipy import weave
from c_support_code import *

__all__ = ['generate_c_threshold', 'generate_python_threshold',
Expand Down
5 changes: 4 additions & 1 deletion brian/experimental/codegen2/codeobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"""
from brian import *
from brian.globalprefs import get_global_preference
from scipy import weave
try:
import weave
except ImportError:
from scipy import weave
from formatting import *

__all__ = ['Code',
Expand Down
13 changes: 8 additions & 5 deletions brian/experimental/cuda/gpucodegen.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#import brian_no_units
from brian import *
from brian import optimiser
from scipy import weave
try:
import weave
except ImportError:
from scipy import weave
try:
import pycuda
import pycuda.autoinit as autoinit
Expand Down Expand Up @@ -86,13 +89,13 @@ def __call__(self, P):
P._S.sync_to_cpu()
P._S.changed_cpu_data()



class UserControlledGPUNonlinearStateUpdater(GPUNonlinearStateUpdater):
def __init__(self, eqs, clock=None, freeze=False, precision='double', maxblocksize=512, gpu_to_cpu_vars=None, cpu_to_gpu_vars=None):
GPUNonlinearStateUpdater.__init__(self, eqs, clock=clock, freeze=freeze, precision=precision, maxblocksize=maxblocksize, forcesync=False)
self.gpu_to_cpu_vars = gpu_to_cpu_vars
self.cpu_to_gpu_vars = cpu_to_gpu_vars


def _prepare(self, P):
GPUNonlinearStateUpdater._prepare(self, P)
if isinstance(P._S._gpu_arr, pycuda.gpuarray.GPUArray):
Expand All @@ -101,7 +104,7 @@ def _prepare(self, P):
self._gpuoffset = int(P._S._gpu_arr)
self._cpuflat = array(P._S, copy=False)
self._cpuflat.shape = self._cpuflat.size


def __call__(self, P):
if not self._prepared:
self._prepare(P)
Expand All @@ -115,7 +118,7 @@ def __call__(self, P):
P._S._cpu_data_changed = False # override any buffering
P._S._gpu_data_changed = False # override any buffering



class GPUNeuronGroup(NeuronGroup):
'''
Neuron group which performs numerical integration on the GPU.
Expand Down
9 changes: 6 additions & 3 deletions brian/experimental/morphology/spatialneuron_remy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import functools
import warnings
from math import ceil, log
from scipy import weave
try:
import weave
except ImportError:
from scipy import weave
from time import time
import trace
import numpy
Expand All @@ -33,7 +36,7 @@

__all__ = ['SpatialNeuron', 'CompartmentalNeuron']



class SpatialNeuron(NeuronGroup):
"""
Compartmental model with morphology.
Expand Down Expand Up @@ -126,7 +129,7 @@ def __getattr__(self, x):
return self[x]
else:
return NeuronGroup.__getattr__(self, x)


class SpatialStateUpdater(StateUpdater):
"""
State updater for compartmental models.
Expand Down
16 changes: 10 additions & 6 deletions brian/experimental/multilinearstateupdater.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from brian import *
from brian.stateupdater import get_linear_equations_solution_numerically, get_linear_equations
from scipy import linalg, weave
try:
import weave
except ImportError:
from scipy import weave
from scipy import linalg
import numpy
import inspect
from itertools import count
Expand Down Expand Up @@ -101,7 +105,7 @@ def get_multilinear_state_updater(eqs, subs, level=0, clock=None):
B[:, i] = Bi.squeeze()
return MultiLinearStateUpdater(A, B)



class MultiLinearStateUpdater(StateUpdater):
'''
A StateUpdater with one differential equation for each neuron
Expand All @@ -121,7 +125,7 @@ def __init__(self, A, B=None):
self._extra_compile_args = ['-O3']
if self._cpp_compiler == 'gcc':
self._extra_compile_args += get_global_preference('gcc_options') # ['-march=native', '-ffast-math']


def __call__(self, P):
if self._useaccel:
n = len(P)
Expand Down Expand Up @@ -160,15 +164,15 @@ def __call__(self, P):
P._S[:] = AS
if self.B is not None:
add(P._S, self.B, P._S)


def __len__(self):
return self.A.shape[0]


def __repr__(self):
return 'MultiLinearStateUpdater'
__str__ = __repr__



class MultiLinearNeuronGroup(NeuronGroup):
'''
Make a NeuronGroup with a linear differential equation for each neuron
Expand Down
13 changes: 8 additions & 5 deletions brian/experimental/new_c_propagate.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@
from ..globalprefs import get_global_preference
from codegen.c_support_code import *
import numpy
from scipy import weave
try:
import weave
except ImportError:
from scipy import weave
import new

__all__ = ['make_new_connection',
Expand All @@ -112,7 +115,7 @@
'ConnectionCode',
]



class ConnectionCode(object):
def __init__(self, codestr, vars=None, pycodestr=None, pyvars=None):
if pyvars is None:
Expand All @@ -134,7 +137,7 @@ def __init__(self, codestr, vars=None, pycodestr=None, pyvars=None):
self._extra_compile_args = ['-O3']
if self._weave_compiler == 'gcc':
self._extra_compile_args += get_global_preference('gcc_options') # ['-march=native', '-ffast-math']


def prepare(self):
self.pyvars['vars'] = self.vars
self.vars['_spikes'] = None
Expand All @@ -145,7 +148,7 @@ def prepare(self):
else:
self.compiled_pycode = None
self.prepared = True


def __call__(self, _spikes):
if not self.prepared:
self.prepare()
Expand All @@ -171,7 +174,7 @@ def __call__(self, _spikes):
support_code=c_support_code,
compiler=self._weave_compiler,
extra_compile_args=self._extra_compile_args)


def __str__(self):
s = 'C code:\n'
spaces = 0
Expand Down
6 changes: 5 additions & 1 deletion brian/hears/filtering/filterbank.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from brian import *
from scipy import signal, weave, random
try:
import weave
except ImportError:
from scipy import weave
from scipy import signal, random
from ..bufferable import Bufferable
from operator import isSequenceType
from __builtin__ import all
Expand Down
6 changes: 5 additions & 1 deletion brian/hears/filtering/filterbanklibrary.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from brian import *
from scipy import signal, weave, random
try:
import weave
except ImportError:
from scipy import weave
from scipy import signal, random
from operator import isSequenceType
from filterbank import Filterbank,RestructureFilterbank
from linearfilterbank import *
Expand Down
6 changes: 5 additions & 1 deletion brian/hears/filtering/linearfilterbank.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from brian import *
from scipy import signal, weave, random
try:
import weave
except ImportError:
from scipy import weave
from scipy import signal, random
from filterbank import Filterbank, RestructureFilterbank
from ..bufferable import Bufferable
from itertools import izip
Expand Down
5 changes: 4 additions & 1 deletion brian/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@


from globalprefs import *
from scipy import weave
try:
import weave
except ImportError:
from scipy import weave


class Monitor(object):
Expand Down

0 comments on commit 52dd8ef

Please sign in to comment.