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):
2222 """Size of A should be power of two."""
2323 total = len (A )
2424 # 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 )
2626
2727 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 )
3131
3232 return R [0 ]
3333
3434
3535def test_sum_reduce ():
36- # This test will only work for size = power of two
3736 N = 2048
38- assert N % 2 == 0
3937
4038 A = np .arange (N , dtype = np .float32 )
4139 A_copy = np .arange (N , dtype = np .float32 )
You can’t perform that action at this time.
0 commit comments