Function mvpoly::utils::compute_indices_nested_loop
source · pub fn compute_indices_nested_loop(
nested_loop_sizes: Vec<usize>
) -> Vec<Vec<usize>>
Expand description
Compute the list of indices to perform N nested loops of different size each. In other words, if we have to perform the 3 nested loops:
let n1 = 3;
let n2 = 3;
let n3 = 5;
for i in 0..n1 {
for j in 0..n2 {
for k in 0..n3 {
}
}
}
the output will be all the possible values of i
, j
, and k
.
The algorithm is as follows:
let n1 = 3;
let n2 = 3;
let n3 = 5;
(0..(n1 * n2 * n3)).map(|l| {
let i = l % n1;
let j = (l / n1) % n2;
let k = (l / (n1 * n2)) % n3;
(i, j, k)
});
For N nested loops, the algorithm is the same, with the division increasing
by the factor N_k
for the index i_(k + 1)
In the case of an empty list, the function will return a list containing a single element which is the empty list.
In the case of an empty loop (i.e. one value in the input list is 0), the expected output is the empty list.