-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLPythranTest.py
More file actions
29 lines (23 loc) · 830 Bytes
/
Copy pathLPythranTest.py
File metadata and controls
29 lines (23 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import numpy as np
#pythran export laplace_pyth(float[:,:], bool)
def laplace_pyth(image, wrap):
h = image.shape[0]
if wrap:
laplacian = np.empty((h, h))
for i in range(h):
for j in range(h):
im = (i - 1 + h) % h
ip = (i+1) % h
jm = (j - 1 + h) % h
jp = (j + 1) % h
laplacian[i, j] = image[im, j] + image[ip, j] + image[i, jm] + image[i, jp] - 4*image[i, j]
else:
laplacian = np.empty((h-2, h-2))
for i in range(1,h-1):
for j in range(1,h-1):
im = i-1
ip = i+1
jm = j-1
jp = j+1
laplacian[im, jm] = image[im, j] + image[ip, j] + image[i, jm] + image[i, jp] - 4 * image[i, j]
return laplacian