pyodide/benchmark/benchmarks/repeating.py

15 lines
412 B
Python
Raw Normal View History

2018-10-03 18:59:01 +00:00
# http://stackoverflow.com/questions/14553331/how-to-improve-numpy-performance-in-this-short-code
# pythran export repeating(float[], int)
# setup: import numpy as np ; a = np.random.rand(10000)
# run: repeating(a, 20)
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 repeating(x, nvar_y):
nvar_x = x.shape[0]
2018-10-03 18:59:01 +00:00
y = np.empty(nvar_x * (1 + nvar_y))
2018-04-05 22:07:33 +00:00
y[0:nvar_x] = x[0:nvar_x]
2018-10-03 18:59:01 +00:00
y[nvar_x:] = np.repeat(x, nvar_y)
2018-04-05 22:07:33 +00:00
return y