5,336
edits
No edit summary |
|||
Line 30: | Line 30: | ||
This is one way to simulate switch statements. | This is one way to simulate switch statements. | ||
Technically these do not have branching but will have a memory read which could be just as slow as a single branch. | Technically these do not have branching but will have a memory read which could be just as slow as a single branch. | ||
< | <syntaxhighlight lang="python"> | ||
# Cache the following at the start of your program or in the constructor | # Cache the following at the start of your program or in the constructor | ||
# Assume we have some functions batch_norm(), group_norm() | # Assume we have some functions batch_norm(), group_norm() | ||
Line 41: | Line 41: | ||
# At runtime, you can do: | # At runtime, you can do: | ||
x = my_cache[operation](x) | x = my_cache[operation](x) | ||
</ | </syntaxhighlight> | ||
==Multiplications== | ==Multiplications== |