Skip to content

Commit

Permalink
Fix GSL for Cython and standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
mstimberg committed Sep 8, 2023
1 parent 2e57656 commit 8b8ce98
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
22 changes: 13 additions & 9 deletions brian2/codegen/generators/GSL_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ def get_dimension_code(self, diff_num):
set_dimension_code : str
The code describing the target language function in a single string
"""
code = ["\n{start_declare}int set_dimension(size_t * dimension){open_function}"]
code = [
"\n{start_func_declare}int set_dimension(size_t * dimension){open_function}"
]
code += ["\tdimension[0] = %d{end_statement}" % diff_num]
code += ["\treturn GSL_SUCCESS{end_statement}{end_function}"]
return ("\n").join(code).format(**self.syntax)
Expand All @@ -352,11 +354,11 @@ def yvector_code(self, diff_vars):
``_empty_y_vector``) as single string.
"""
fill_y = [
"\n{start_declare}int _fill_y_vector(_dataholder *"
"\n{start_func_declare}int _fill_y_vector(_dataholder *"
"_GSL_dataholder, double * _GSL_y, int _idx){open_function}"
]
empty_y = [
"\n{start_declare}int _empty_y_vector(_dataholder * "
"\n{start_func_declare}int _empty_y_vector(_dataholder * "
"_GSL_dataholder, double * _GSL_y, int _idx){"
"open_function}"
]
Expand Down Expand Up @@ -397,11 +399,11 @@ def make_function_code(self, lines):
code describing ``_GSL_func`` that is sent to GSL integrator.
"""
code = [
"\n{start_declare}int _GSL_func(double t, const double "
"\n{start_func_declare}int _GSL_func(double t, const double "
"_GSL_y[], double f[], void * params){open_function}"
"\n\t{start_declare}_dataholder * _GSL_dataholder = {open_cast}"
"\n\t{start_var_declare}_dataholder * _GSL_dataholder = {open_cast}"
"_dataholder *{close_cast} params{end_statement}"
"\n\t{start_declare}int _idx = _GSL_dataholder{access_pointer}_idx"
"\n\t{start_var_declare}int _idx = _GSL_dataholder{access_pointer}_idx"
"{end_statement}"
]
code += [lines]
Expand Down Expand Up @@ -449,7 +451,7 @@ def write_dataholder(self, variables_in_vector):
code : str
code for _dataholder struct
"""
code = ["\n{start_declare}struct _dataholder{open_struct}"]
code = ["\n{start_var_declare}struct _dataholder{open_struct}"]
code += ["\tint _idx{end_statement}"]
for var, var_obj in list(variables_in_vector.items()):
if (
Expand Down Expand Up @@ -1053,7 +1055,8 @@ class GSLCythonCodeGenerator(GSLCodeGenerator):
syntax = {
"end_statement": "",
"access_pointer": ".",
"start_declare": "cdef extern ",
"start_func_declare": "cdef extern ",
"start_var_declare": "cdef ",
"open_function": ":",
"open_struct": ":",
"end_function": "",
Expand Down Expand Up @@ -1113,7 +1116,8 @@ def __getattr__(self, item):
syntax = {
"end_statement": ";",
"access_pointer": "->",
"start_declare": 'extern "C" ',
"start_func_declare": 'extern "C" ',
"start_var_declare": "",
"open_function": "\n{",
"open_struct": "\n{",
"end_function": "\n}",
Expand Down
3 changes: 1 addition & 2 deletions brian2/devices/cpp_standalone/GSLcodeobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
GNU Scientific Library
"""

from brian2.codegen.codeobject import CodeObject
from brian2.codegen.generators.cpp_generator import CPPCodeGenerator
from brian2.codegen.generators.GSL_generator import GSLCPPCodeGenerator
from brian2.devices.cpp_standalone import CPPStandaloneCodeObject


class GSLCPPStandaloneCodeObject(CodeObject):
class GSLCPPStandaloneCodeObject(CPPStandaloneCodeObject):
templater = CPPStandaloneCodeObject.templater.derive(
"brian2.devices.cpp_standalone", templates_dir="templates_GSL"
)
Expand Down

0 comments on commit 8b8ce98

Please sign in to comment.