def preduce(vl, vec, pred):
vec = copy(vec)
- pred = copy(pred) # must not damage predicate
step = 1
print(" start", step, pred, vec)
while step < vl:
vec[i] += vec[other]
elif other_pred:
vec[i] = vec[other]
- pred[i] |= other_pred
print(" row", step, pred, vec)
return vec
def preducei(vl, vec, pred):
vec = copy(vec)
- pred = copy(pred) # must not damage predicate
step = 1
ix = list(range(vl)) # indices move rather than copy data
print(" start", step, pred, vec)
vec[ci] += vec[oi]
elif other_pred:
ix[i] = oi # leave data in-place, copy index instead
- pred[ci] |= other_pred
print(" row", step, pred, vec, ix)
return vec
def preduce_yield(vl, vec, pred):
- pred = copy(pred) # must not damage predicate
step = 1
ix = list(range(vl))
while step < vl:
yield ci, oi
elif other_pred:
ix[i] = oi
- pred[ci] |= other_pred
def preduce_y(vl, vec, pred):
print ()
assert vec == res2
+ vec = [1, 2, 3, 4, 9, 5, 6, 8]
+ prd = [0, 0, 0, 0, 1, 1, 1, 1]
+ print (vec)
+ res = preduce(len(vec), vec, prd)
+ print (res)
+ res2 = preducei(len(vec), vec, prd)
+ print (res2)
+ print ()
+ preduce_y(len(vec), vec, prd)
+ print (vec)
+ print ()
+ assert vec == res2
+
+ vec = [1, 2, 3, 4, 9, 5, 6, 8]
+ prd = [0, 1, 0, 0, 0, 1, 0, 1]
+ print (vec)
+ res = preduce(len(vec), vec, prd)
+ print (res)
+ res2 = preducei(len(vec), vec, prd)
+ print (res2)
+ print ()
+ preduce_y(len(vec), vec, prd)
+ print (vec)
+ print ()
+ assert vec == res2
+
+ vec = [1, 2, 3, 4, 9, 5, 6]
+ prd = [1, 0, 1, 1, 0, 0, 1]
+ print (vec)
+ res = preduce(len(vec), vec, prd)
+ print (res)
+ res2 = preducei(len(vec), vec, prd)
+ print (res2)
+ print ()
+ preduce_y(len(vec), vec, prd)
+ print (vec)
+ print ()
+ assert vec == res2
+