Skip to content

Commit

Permalink
Merge pull request #404 from brian-team/lio_optional
Browse files Browse the repository at this point in the history
Make the "loop-invariant optimisations" optional via a preference
  • Loading branch information
thesamovar committed Feb 12, 2015
2 parents 880f00e + e1e7ae0 commit b26f7c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
12 changes: 11 additions & 1 deletion brian2/codegen/_prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,15 @@
Accepts the same arguments as `codegen.target`.
''',
validator=lambda target: isinstance(target, basestring) or issubclass(target, CodeObject),
),
loop_invariant_optimisations=BrianPreference(
default=True,
docs='''
Whether to pull out scalar expressions out of the statements, so that
they are only evaluated once instead of once for every neuron/synapse/...
Can be switched off, e.g. because it complicates the code (and the same
optimisation is already performed by the compiler) or because the
code generation target does not deal well with it. Defaults to ``True``.
'''
)
)
)
11 changes: 7 additions & 4 deletions brian2/codegen/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import numpy as np

from brian2.core.preferences import prefs
from brian2.core.variables import Variable, Subexpression, AuxiliaryVariable
from brian2.core.functions import Function
from brian2.utils.stringtools import (deindent, strip_empty_lines,
Expand Down Expand Up @@ -469,10 +470,12 @@ def make_statements(code, variables, dtype):

scalar_statements = [s for s in statements if s.scalar]
vector_statements = [s for s in statements if not s.scalar]
scalar_constants, vector_statements = apply_loop_invariant_optimisations(vector_statements,
variables,
dtype)
scalar_statements.extend(scalar_constants)

if prefs.codegen.loop_invariant_optimisations:
scalar_constants, vector_statements = apply_loop_invariant_optimisations(vector_statements,
variables,
dtype)
scalar_statements.extend(scalar_constants)

return scalar_statements, vector_statements

0 comments on commit b26f7c5

Please sign in to comment.