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: 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 and get_conditional_write_vars, and updates the read 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 when varname is written to, it should only be when condition_var_name is True.
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 and get_conditional_write_vars, and updates the read 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.

get_conditional_write_vars()[source]

Helper function, returns a dict of mappings (varname, condition_var_name) indicating that when varname is written to, it should only be when condition_var_name is True.

has_repeated_indices(statements)[source]

Whether any of the statements potentially uses repeated indices (e.g. pre- or postsynaptic indices).

translate(code, dtype)[source]

Translates an abstract code block into the target language.

translate_expression(expr)[source]

Translate the given expression string into a string in the target language, returns a string.

translate_one_statement_sequence(statements, scalar=False)[source]
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) where scalar_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, and kwds is a dictionary of values that is made available to the template.