pyodide/benchmark/benchmarks/allpairs_distances_loops.py

14 lines
466 B
Python
Raw Normal View History

2018-10-03 18:59:01 +00:00
# setup: import numpy as np ; N = 50 ; X, Y = np.random.randn(30,N), np.random.randn(20,N) # noqa
# run: allpairs_distances_loops(X, Y)
2018-04-05 22:07:33 +00:00
2018-10-03 18:59:01 +00:00
# pythran export allpairs_distances_loops(float64[][], float64[][])
2018-04-05 22:07:33 +00:00
import numpy as np
2018-10-03 18:59:01 +00:00
def allpairs_distances_loops(X, Y):
result = np.zeros((X.shape[0], Y.shape[0]), X.dtype)
for i in range(X.shape[0]):
for j in range(Y.shape[0]):
result[i, j] = np.sum((X[i, :] - Y[j, :]) ** 2)
return result