How to compute a conditional sum of a vector efficiently

2 posts were split to a new topic: Speeding up a sum involving 3 matrices