Hi everyone,
This isn’t a classic support request, sorry, but I couldn’t find a good category for my question.
With years of Brian/Brian2 usage, I accumulated a bunch of functions that I really would like to have inside equations. Moreover, I want them on all devices cpp, numpy, cython, etc. So is there any template for such a library?
What will be very handy is to have something like this:
from brian2 import *
from brian2pls import fe
n = NeuronGroup(..., model ="dr/dt = fe(r)/tau : 1" ....)
It seems decorator @implementation is the best way to go. So a fe function may look like this:
@implementation('cython', f'''
cdef double fe(double x):
return {ge}*(x-{thetae}) if x-{thetae} > 0. else 0.
''')
@implementation('cpp',f''''
double fe(double x)
{{
return ((x-{thetae})<0.)?0.:{ge}*(x-{thetae});
}}''')
@check_units(x=1, result=1)
def fe(x):
return ge*(x-thetae) if x-thetae > 0. else 0.
This seems (I’m really not sure) works for both cpp, standalone, omp device, and cython device. It isn’t completely clear to me how to implements it for numpy device, and do we have cuda/gpu device or not?
Any thoughts, suggestions, and examples are highly appreciated.
P.S. As we discussed with @mstimberg before, many of my functions can be written as a combination of brian2’s equation functions, but it is too messy. On the other hand, I want to have full control over cpp/cython implementation, to be sure that it is the most optimal one.
