Skip to content

Commit 5bff8c8

Browse files
authored
Merge pull request #1089 from IntelPython/feature/remove_power2_restriction_on_sum_example
Remove ^2 restriction on sum example
2 parents 81af300 + 434b516 commit 5bff8c8

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

numba_dpex/examples/sum_reduction.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff 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

3535
def 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)

0 commit comments

Comments
 (0)