pyodide/benchmark/benchmarks/evolve.py

17 lines
643 B
Python
Raw Normal View History

2018-04-05 22:07:33 +00:00
#setup: import numpy as np ; grid_shape = (512, 512) ; grid = np.zeros(grid_shape) ; block_low = int(grid_shape[0] * .4) ; block_high = int(grid_shape[0] * .5) ; grid[block_low:block_high, block_low:block_high] = 0.005
#run: evolve(grid, 0.1)
#from: High Performance Python by Micha Gorelick and Ian Ozsvald, http://shop.oreilly.com/product/0636920028963.do
#pythran export evolve(float64[][], float)
2018-10-03 12:38:48 +00:00
2018-04-05 22:07:33 +00:00
import numpy as np
2018-10-03 12:38:48 +00:00
2018-04-05 22:07:33 +00:00
def laplacian(grid):
2018-10-03 12:38:48 +00:00
return (np.roll(grid, +1, 0) + np.roll(grid, -1, 0)
+ np.roll(grid, +1, 1) + np.roll(grid, -1, 1) - 4 * grid)
2018-04-05 22:07:33 +00:00
def evolve(grid, dt, D=1):
return grid + dt * D * laplacian(grid)