Compute the position of the first nonzero bit for each int in an array.
(a)
| 18 | |
| 19 | |
| 20 | def compute_first_bit(a): |
| 21 | "Compute the position of the first nonzero bit for each int in an array." |
| 22 | # TODO: consider making this less memory-hungry |
| 23 | bits = np.bitwise_and.outer(a, 1 << np.arange(32)) |
| 24 | bits = bits.cumsum(axis=1).astype(bool) |
| 25 | return 33 - bits.sum(axis=1) |
| 26 | |
| 27 | |
| 28 | def compute_hll_array(obj, b): |