pyodide/benchmark/benchmarks/check_mask.py

18 lines
572 B
Python
Raw Normal View History

2018-10-03 18:59:01 +00:00
# setup: n=100 ; import numpy; db = numpy.random.randint(2, size=(n, 4), dtype='bool') # noqa
# run: check_mask(db)
# from:
# http://stackoverflow.com/questions/34500913/numba-slower-for-numpy-bitwise-and-on-boolean-arrays
2018-04-05 22:07:33 +00:00
2018-10-03 18:59:01 +00:00
# pythran export check_mask(bool[][])
2018-04-05 22:07:33 +00:00
import numpy as np
2018-10-03 18:59:01 +00:00
2018-04-05 22:07:33 +00:00
def check_mask(db, mask=[1, 0, 1]):
2018-10-03 18:59:01 +00:00
out = np.zeros(db.shape[0], dtype=bool)
2018-04-05 22:07:33 +00:00
for idx, line in enumerate(db):
target, vector = line[0], line[1:]
if (mask == np.bitwise_and(mask, vector)).all():
if target == 1:
out[idx] = 1
return out