Code Restrictions#
The following code restrictions are necessary to ensure that the functions inside gettsim can be vectorized automatically. The code restrictions are checked and throw an error if violated.
If-Else Conditions#
Code inside an if / elif / else block can only perform one operation. For example, the following is allowed:
if x > 1: out = 1 else: out = 0
while
if x > 1: flag = True out = 1 else: out = 0
is not allowed since the code inside the if block performs two operations.
There cannot be a return statement inside a single if-condition. For example, the following is allowed:
if x > 1: return 1 else: return 0
or
if x > 1: out = 1 else: out = 0 return out
while
out = 0 if x > 1: return 1 return out
is not allowed.
Only certain operations can be performed in the body of an if / elif / else condition. For example, the following operations are allowed:
Assigning a variable (e.g.
out = 1
)Returning a value (e.g.
return 1
)One-line if-else conditions (e.g.
out = 1 if x > 1 else 0
)Nested if-elif-else conditions
Function Calls#
This is a list of restrictions applying to functions from the base and math modules.
The following functions can only be called with iterable arguments:
sum
any
all
For example the following is allowed:
any([True, False, False])
while
any(True, False, False)
is not allowed.
The following functions can only be called with two arguments or one iterable argument. For example the following is allowed:
min([1, 2, 3])
and
min(left, right)
while
min(1, 2, 3)
or
min(left, middle, right)
is not allowed.