Debian Codegraph @

brian2/codegen/_prefs.py

raw
1 """
2 Module declaring general code generation preferences.
3
4 Preferences
5 -----------
6 .. document_brian_prefs:: codegen
7 """
8
9 from brian2.core.preferences import BrianPreference, prefs
10
11 from .codeobject import CodeObject
12
13 # Preferences
14 prefs.register_preferences(
15 "codegen",
16 "Code generation preferences",
17 target=BrianPreference(
18 default="auto",
19 docs="""
20 Default target for code generation.
21
22 Can be a string, in which case it should be one of:
23
24 * ``'auto'`` the default, automatically chose the best code generation
25 target available.
26 * ``'cython'``, uses the Cython package to generate C++ code. Needs a
27 working installation of Cython and a C++ compiler.
28 * ``'numpy'`` works on all platforms and doesn't need a C compiler but
29 is often less efficient.
30
31 Or it can be a ``CodeObject`` class.
32 """,
33 validator=lambda target: isinstance(target, str)
34 or issubclass(target, CodeObject),
35 ),
36 string_expression_target=BrianPreference(
37 default="numpy",
38 docs="""
39 Default target for the evaluation of string expressions (e.g. when
40 indexing state variables). Should normally not be changed from the
41 default numpy target, because the overhead of compiling code is not
42 worth the speed gain for simple expressions.
43
44 Accepts the same arguments as `codegen.target`, except for ``'auto'``
45 """,
46 validator=lambda target: isinstance(target, str)
47 or issubclass(target, CodeObject),
48 ),
49 loop_invariant_optimisations=BrianPreference(
50 default=True,
51 docs="""
52 Whether to pull out scalar expressions out of the statements, so that
53 they are only evaluated once instead of once for every neuron/synapse/...
54 Can be switched off, e.g. because it complicates the code (and the same
55 optimisation is already performed by the compiler) or because the
56 code generation target does not deal well with it. Defaults to ``True``.
57 """,
58 ),
59 max_cache_dir_size=BrianPreference(
60 default=1000,
61 docs="""
62 The size of a directory (in MB) with cached code for Cython that triggers
63 a warning. Set to 0 to never get a warning.
64 """,
65 ),
66 )