CPPCodeGenerator class¶
(Shortest import: from brian2.codegen.generators import CPPCodeGenerator)
- class brian2.codegen.generators.cpp_generator.CPPCodeGenerator(*args, **kwds)[source]¶
Bases:
brian2.codegen.generators.base.CodeGeneratorC++ language
C++ code templates should provide Jinja2 macros with the following names:
mainThe main loop.
support_codeThe support code (function definitions, etc.), compiled in a separate file.
For user-defined functions, there are two keys to provide:
support_codeThe function definition which will be added to the support code.
hashdefine_codeThe
#definecode added to the main loop.
See
TimedArrayfor an example of these keys.Attributes
Methods
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.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_statement_sequence(sc_statements, ...)Translate a sequence of
Statementinto the target language, taking care to declare variables, etc.translate_to_declarations(read, write, indices)translate_to_read_arrays(read, write, indices)translate_to_statements(statements, ...)translate_to_write_arrays(write)Details
- flush_denormals¶
- restrict¶
- 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().
- 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(sc_statements, ve_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.