CodeGenerator class¶
(Shortest import: from brian2.codegen.generators import CodeGenerator)
- class brian2.codegen.generators.base.CodeGenerator(variables, variable_indices, owner, iterate_all, codeobj_class, name, template_name, override_conditional_write=None, allows_scalar_write=False)[source]¶
Bases:
objectBase class for all languages.
See definition of methods below.
TODO: more details here
Methods
array_read_write(statements)Helper function, gives the set of ArrayVariables that are read from and written to in the series of statements.
arrays_helper(statements)Combines the two helper functions
array_read_writeandget_conditional_write_vars, and updates thereadset.A dictionary of values that is made available to the templated.
get_array_name(var[, access_data])Get a globally unique name for a
ArrayVariable.Helper function, returns a dict of mappings
(varname, condition_var_name)indicating that whenvarnameis written to, it should only be whencondition_var_nameisTrue.has_repeated_indices(statements)Whether any of the statements potentially uses repeated indices (e.g. pre- or postsynaptic indices).
translate(code, dtype)Translates an abstract code block into the target language.
translate_expression(expr)Translate the given expression string into a string in the target language, returns a string.
translate_one_statement_sequence(statements)translate_statement(statement)Translate a single line
Statementinto the target language, returns a string.Translate a sequence of
Statementinto the target language, taking care to declare variables, etc.Details
- array_read_write(statements)[source]¶
Helper function, gives the set of ArrayVariables that are read from and written to in the series of statements. Returns the pair read, write of sets of variable names.
- arrays_helper(statements)[source]¶
Combines the two helper functions
array_read_writeandget_conditional_write_vars, and updates thereadset.
- determine_keywords()[source]¶
A dictionary of values that is made available to the templated. This is used for example by the
CPPCodeGeneratorto set up all the supporting code
- static get_array_name(var, access_data=True)[source]¶
Get a globally unique name for a
ArrayVariable.- Parameters:
var :
ArrayVariableThe variable for which a name should be found.
access_data : bool, optional
For
DynamicArrayVariableobjects, specifyingTruehere means the name for the underlying data is returned. If specifyingFalse, the name of object itself is returned (e.g. to allow resizing).Returns :
——- :
name : str
A uniqe name for
var.
- get_conditional_write_vars()[source]¶
Helper function, returns a dict of mappings
(varname, condition_var_name)indicating that whenvarnameis written to, it should only be whencondition_var_nameisTrue.
- has_repeated_indices(statements)[source]¶
Whether any of the statements potentially uses repeated indices (e.g. pre- or postsynaptic indices).
- translate_expression(expr)[source]¶
Translate the given expression string into a string in the target language, returns a string.
- translate_statement(statement)[source]¶
Translate a single line
Statementinto the target language, returns a string.
- translate_statement_sequence(scalar_statements, vector_statements)[source]¶
Translate a sequence of
Statementinto the target language, taking care to declare variables, etc. if necessary.Returns a tuple
(scalar_code, vector_code, kwds)wherescalar_codeis a list of the lines of code executed before the inner loop,vector_codeis a list of the lines of code in the inner loop, andkwdsis a dictionary of values that is made available to the template.