--- /dev/null
+from copy import copy
+
+def preduce(vl, vec, pred):
+ pred = copy(pred) # must not damage predicate
+ step = 1
+ while step < vl:
+ step *= 2
+ for i in range(0, vl, step):
+ other = i + step // 2
+ other_pred = other < vl and pred[other]
+ if pred[i] and other_pred:
+ vec[i] += vec[other]
+ elif other_pred:
+ vec[i] = vec[other]
+ pred[i] |= other_pred
+ print(" row", step, pred, vec)
+
+if __name__ == '__main__':
+ vec = [1, 2, 3, 4, 9, 5, 6]
+ prd = [1, 1, 1, 1, 0, 1, 1]
+ print (vec)
+ preduce(len(vec), vec, prd)
+ print (vec)
+ print ()
+