Given a trivial code example:
def some_fn():
for i in range(100):
result += x * i
return result
unrolled in batches of say 10 iterations:
def some_fn():
for i in range(0, 100, 10):
result += x * i
result += x * (i+1)
result += x * (i+2)
result += x * (i+3)
result += x * (i+4)
result += x * (i+5)
result += x * (i+6)
result += x * (i+7)
result += x * (i+8)
result += x * (i+9)
return result
- I know it's possible to do such a transform by hand with an unrolled inner loop and a normal outer loop and manually adjusting the loop iterations.
- I figured it would make it a less manual process (and less error-prone) if there was an option to automate this transform taking a parameter for the number of iterations to unroll at a time, and a corresponding decrease in the loop iterations.
Given a trivial code example:
unrolled in batches of say 10 iterations: