Skip to main content

Infer.NET development : Compiler transforms

Loop cutting transform

This transform cuts for loops, so that each statement in the loop ends up in a loop by itself. It also converts variables declared inside loops into array variables declared at the top level. References to such variables are modified by adding indices appropriately.

Input Output
for(int i=0; i<10; i++) {
double x;
y[i] = Factor.Random(prior);
z[i] = Factor.Gaussian(y[i],x);
}
double[]] x = new double[10];
for(int i=0; i<10; i++) {
y[i] = Factor.Random(prior);
}
for(int i=0; i<10; i++) {
z[i] = Factor.Gaussian(y[i],x[i]);
}