File tree Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -22,20 +22,18 @@ def sum_reduce(A):
22
22
"""Size of A should be power of two."""
23
23
total = len (A )
24
24
# max size will require half the size of A to store sum
25
- R = np .array (np .random .random (math .ceil (total / 2 )), dtype = A .dtype )
25
+ R = np .array (np .random .random (math .floor (total / 2 )), dtype = A .dtype )
26
26
27
27
while total > 1 :
28
- global_size = total // 2
29
- sum_reduction_kernel [ ndpx . Range ( global_size )]( A , R , global_size )
30
- total = total // 2
28
+ global_size = math . floor ( total // 2 )
29
+ total = total - global_size
30
+ sum_reduction_kernel [ ndpx . Range ( global_size )]( A , R , total )
31
31
32
32
return R [0 ]
33
33
34
34
35
35
def test_sum_reduce ():
36
- # This test will only work for size = power of two
37
36
N = 2048
38
- assert N % 2 == 0
39
37
40
38
A = np .arange (N , dtype = np .float32 )
41
39
A_copy = np .arange (N , dtype = np .float32 )
You can’t perform that action at this time.
0 commit comments