@@ -45,26 +45,25 @@ def test_mfab_loop(make_mfab):
4545
4646 # numpy representation: non-copying view, including the
4747 # guard/ghost region
48- # note: in numpy, indices are in C-order!
49- marr_np = np .array (marr , copy = False )
48+ marr_np = marr .to_numpy ()
5049
5150 # check the values at start/end are the same: first component
5251 assert marr_np [0 , 0 , 0 , 0 ] == marr [bx .small_end ]
53- assert marr_np [0 , - 1 , - 1 , - 1 ] == marr [bx .big_end ]
52+ assert marr_np [- 1 , - 1 , - 1 , 0 ] == marr [bx .big_end ]
5453 # same check, but for all components
5554 for n in range (mfab .num_comp ):
5655 small_end_comp = list (bx .small_end ) + [n ]
5756 big_end_comp = list (bx .big_end ) + [n ]
58- assert marr_np [n , 0 , 0 , 0 ] == marr [small_end_comp ]
59- assert marr_np [n , - 1 , - 1 , - 1 ] == marr [big_end_comp ]
57+ assert marr_np [0 , 0 , 0 , n ] == marr [small_end_comp ]
58+ assert marr_np [- 1 , - 1 , - 1 , n ] == marr [big_end_comp ]
6059
6160 # now we do some faster assignments, using range based access
6261 # this should fail as out-of-bounds, but does not
6362 # does Numpy not check array access for non-owned views?
6463 # marr_np[24:200, :, :, :] = 42.
6564
6665 # all components and all indices set at once to 42
67- marr_np [:, :, :, : ] = 42.0
66+ marr_np [() ] = 42.0
6867
6968 # values in start & end still match?
7069 assert marr_np [0 , 0 , 0 , 0 ] == marr [bx .small_end ]
@@ -210,10 +209,11 @@ def test_mfab_ops_cuda_cupy(make_mfab_device):
210209 with cupy .profiler .time_range ("assign 3 [()]" , color_id = 0 ):
211210 for mfi in mfab_device :
212211 bx = mfi .tilebox ().grow (ngv )
213- marr = mfab_device .array (mfi )
214- marr_cupy = cp .array (marr , copy = False )
212+ marr_cupy = mfab_device .array (mfi ).to_cupy (order = "C" )
215213 # print(marr_cupy.shape) # 1, 32, 32, 32
216214 # print(marr_cupy.dtype) # float64
215+ # performance:
216+ # https://github.com/AMReX-Codes/pyamrex/issues/55#issuecomment-1579610074
217217
218218 # write and read into the marr_cupy
219219 marr_cupy [()] = 3.0
@@ -244,8 +244,11 @@ def set_to_five(mm):
244244
245245 for mfi in mfab_device :
246246 bx = mfi .tilebox ().grow (ngv )
247- marr = mfab_device .array (mfi )
248- marr_cupy = cp .array (marr , copy = False )
247+ marr_cupy = mfab_device .array (mfi ).to_cupy (order = "F" )
248+ # print(marr_cupy.shape) # 32, 32, 32, 1
249+ # print(marr_cupy.dtype) # float64
250+ # performance:
251+ # https://github.com/AMReX-Codes/pyamrex/issues/55#issuecomment-1579610074
249252
250253 # write and read into the marr_cupy
251254 fives_cp = set_to_five (marr_cupy )
@@ -266,8 +269,7 @@ def set_to_seven(x):
266269
267270 for mfi in mfab_device :
268271 bx = mfi .tilebox ().grow (ngv )
269- marr = mfab_device .array (mfi )
270- marr_cupy = cp .array (marr , copy = False )
272+ marr_cupy = mfab_device .array (mfi ).to_cupy (order = "C" )
271273
272274 # write and read into the marr_cupy
273275 set_to_seven (marr_cupy )
0 commit comments