samedi 19 août 2017

Iteration over multi indices

I'm trying to find an efficiant way to deal with some multi index calculation in c++11. In particular, I am looking at a sum over all multi indices less or equal some number p, like so:

I am calculating the coefficiants a recursively, starting from |alpha| = 0.

So I first need to iterate over the indices where the sum of the alphas is 0 (|\alpha| = 0), then where the sum is 1, and so on.

In two dimensions (d=2) the multi-indices would be (0,0), (1,0), (0,1), (2,0), (1,1), (0,2),... so the diagonals of a matrix basically.

I know I can do it with some loops, always checking if the sum of my alphas is equal to the current iteration, but this seems very inefficiant! Also it seems to get messy for higher dimensions.

What is the best generic way to do it? Is it in any way possible to avoid looping over all possible indices and looking if the sum fits my condition?

Aucun commentaire:

Enregistrer un commentaire