@@ -54,25 +54,26 @@ def run(n, backend, datatype, benchmark_mode):
54
54
if backend == "sharpy" :
55
55
import sharpy as np
56
56
from sharpy import fini , init , sync
57
- from sharpy .numpy import fromfunction as _fromfunction
58
57
59
58
device = os .getenv ("SHARPY_DEVICE" , "" )
60
59
create_full = partial (np .full , device = device )
61
- fromfunction = partial (_fromfunction , device = device )
60
+
61
+ def transpose (a ):
62
+ return np .permute_dims (a , [1 , 0 ])
62
63
63
64
all_axes = [0 , 1 ]
64
65
init (False )
65
66
66
67
elif backend == "numpy" :
67
68
import numpy as np
68
- from numpy import fromfunction
69
69
70
70
if comm is not None :
71
71
assert (
72
72
comm .Get_size () == 1
73
73
), "Numpy backend only supports serial execution."
74
74
75
75
create_full = np .full
76
+ transpose = np .transpose
76
77
77
78
fini = sync = lambda x = None : None
78
79
all_axes = None
@@ -110,17 +111,23 @@ def run(n, backend, datatype, benchmark_mode):
110
111
t_export = 0.02
111
112
t_end = 1.0
112
113
113
- # coordinate arrays
114
- x_t_2d = fromfunction (
115
- lambda i , j : xmin + i * dx + dx / 2 , (nx , ny ), dtype = dtype
116
- )
117
- y_t_2d = fromfunction (
118
- lambda i , j : ymin + j * dy + dy / 2 , (nx , ny ), dtype = dtype
119
- )
114
+ def ind_arr (shape , columns = False ):
115
+ """Construct an (nx, ny) array where each row/col is an arange"""
116
+ nx , ny = shape
117
+ if columns :
118
+ ind = np .arange (0 , nx * ny , 1 , dtype = np .int32 ) % nx
119
+ ind = transpose (np .reshape (ind , (ny , nx )))
120
+ else :
121
+ ind = np .arange (0 , nx * ny , 1 , dtype = np .int32 ) % ny
122
+ ind = np .reshape (ind , (nx , ny ))
123
+ return ind .astype (dtype )
120
124
125
+ # coordinate arrays
121
126
T_shape = (nx , ny )
122
127
U_shape = (nx + 1 , ny )
123
128
V_shape = (nx , ny + 1 )
129
+ x_t_2d = xmin + ind_arr (T_shape , True ) * dx + dx / 2
130
+ y_t_2d = ymin + ind_arr (T_shape ) * dy + dy / 2
124
131
125
132
dofs_T = int (numpy .prod (numpy .asarray (T_shape )))
126
133
dofs_U = int (numpy .prod (numpy .asarray (U_shape )))
0 commit comments