pyodide/benchmark/benchmarks/specialconvolve.py

13 lines
496 B
Python
Raw Normal View History

2018-10-03 18:59:01 +00:00
# from: http://stackoverflow.com/questions/2196693/improving-numpy-performance
# pythran export specialconvolve(uint32 [][])
# setup: import numpy as np ; r = np.arange(100*10000, dtype=np.uint32).reshape(1000,1000) # noqa
# run: specialconvolve(r)
2018-04-05 22:07:33 +00:00
def specialconvolve(a):
# sorry, you must pad the input yourself
2018-10-03 18:59:01 +00:00
rowconvol = a[1:-1, :] + a[:-2, :] + a[2:, :]
colconvol = rowconvol[:, 1:-1] + rowconvol[:, :-2] + \
rowconvol[:, 2:] - 9 * a[1:-1, 1:-1]
2018-04-05 22:07:33 +00:00
return colconvol