CodeGenerator class¶
(Shortest import: from brian2 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:
object
Base 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_write
andget_conditional_write_vars
, and updates theread
set.determine_keywords
()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
.get_conditional_write_vars
()Helper function, returns a dict of mappings (varname, condition_var_name)
indicating that whenvarname
is written to, it should only be whencondition_var_name
isTrue
.has_repeated_indices
(statements)Whether any of the statements potentially uses repeated indices (e.g. 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 Statement
into the target language, returns a string.translate_statement_sequence
(…)Translate a sequence of Statement
into 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_write
andget_conditional_write_vars
, and updates theread
set.
-
determine_keywords
()[source]¶ A dictionary of values that is made available to the templated. This is used for example by the
CPPCodeGenerator
to 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 :
ArrayVariable
The variable for which a name should be found.
access_data : bool, optional
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 whenvarname
is written to, it should only be whencondition_var_name
isTrue
.
-
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
Statement
into the target language, returns a string.
-
translate_statement_sequence
(scalar_statements, vector_statements)[source]¶ Translate a sequence of
Statement
into the target language, taking care to declare variables, etc. if necessary.Returns a tuple
(scalar_code, vector_code, kwds)
wherescalar_code
is a list of the lines of code executed before the inner loop,vector_code
is a list of the lines of code in the inner loop, andkwds
is a dictionary of values that is made available to the template.
-