3 def preduce(vl
, vec
, pred
):
5 pred
= copy(pred
) # must not damage predicate
7 print(" start", step
, pred
, vec
)
10 for i
in range(0, vl
, step
):
12 other_pred
= other
< vl
and pred
[other
]
13 if pred
[i
] and other_pred
:
18 print(" row", step
, pred
, vec
)
22 def preducei(vl
, vec
, pred
):
24 pred
= copy(pred
) # must not damage predicate
26 ix
= list(range(vl
)) # indices move rather than copy data
27 print(" start", step
, pred
, vec
)
30 for i
in range(0, vl
, step
):
33 oi
= ix
[other
] if other
< vl
else None
34 other_pred
= other
< vl
and pred
[oi
]
35 if pred
[ci
] and other_pred
:
38 ix
[i
] = oi
# leave data in-place, copy index instead
39 pred
[ci
] |
= other_pred
40 print(" row", step
, pred
, vec
, ix
)
44 def preduce_yield(vl
, vec
, pred
):
45 pred
= copy(pred
) # must not damage predicate
50 for i
in range(0, vl
, step
):
53 oi
= ix
[other
] if other
< vl
else None
54 other_pred
= other
< vl
and pred
[oi
]
55 if pred
[ci
] and other_pred
:
59 pred
[ci
] |
= other_pred
62 def preduce_y(vl
, vec
, pred
):
63 for i
, other
in preduce_yield(vl
, vec
, pred
):
67 if __name__
== '__main__':
68 vec
= [1, 2, 3, 4, 9, 5, 6]
69 prd
= [0, 1, 1, 1, 0, 0, 1]
71 res
= preduce(len(vec
), vec
, prd
)
73 res2
= preducei(len(vec
), vec
, prd
)
76 preduce_y(len(vec
), vec
, prd
)
81 vec
= [1, 2, 3, 4, 9, 5, 6]
82 prd
= [1, 0, 0, 1, 1, 0, 1]
84 res
= preduce(len(vec
), vec
, prd
)
86 res2
= preducei(len(vec
), vec
, prd
)
89 preduce_y(len(vec
), vec
, prd
)