Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl committed Dec 18, 2023
1 parent c0a2ed6 commit c27a123
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions python/sdist/amici/cxxcodeprinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,18 +343,19 @@ def get_switch_statement(
)
case_code = f"{indent1}case {expression}:"

cases_map[statement_code] = cases_map.get(statement_code, []) + [case_code]
cases_map[statement_code] = cases_map.get(statement_code, []) + [
case_code
]

if not cases_map:
return []

def get_lines():
for statements, case_code in cases_map.items():
yield from case_code
yield from statements

return [
f"{indent0}switch({condition}) {{",
*(get_lines()),
*(
code
for codes in cases_map.items()
for code in itertools.chain.from_iterable(reversed(codes))
),
indent0 + "}",
]

0 comments on commit c27a123

Please sign in to comment.