I’m still in awe how I could have missed that^^  Thanks a lot for that!
I am effectively trying to sample from a GEM distribution which uses an iterative construction. Let’s assume that v is a k-dimensional vector. Then the sample g, which then is GEM distributed (hand-waving), can be defined as:
g[i] = torch.prod(1-v[:i-1]) * v[i] 

The loop construction gives me a linear complexity instead of the quadratic one in the naive case. Do you possibly see a way to vectorize the expression? (The loop kind of feels strange to be honest^^)