File tree 1 file changed +10
-5
lines changed
1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change 14
14
import psutil
15
15
import gc
16
16
from math import sqrt
17
- from math import floor
18
17
from bisect import bisect_left
19
18
from packaging import version as pkg_version
20
19
@@ -552,17 +551,23 @@ def prefix_sum_inc(weights):
552
551
553
552
554
553
def partition_uniform (num_items , num_parts ):
554
+ import numpy
555
555
parts = [0 ] * (num_parts + 1 )
556
556
# First check for the trivial edge case
557
557
if num_items <= num_parts :
558
558
for p in range (num_parts + 1 ):
559
559
parts [p ] = min (p , num_items )
560
560
return parts
561
561
562
- chunksize = floor (num_items / num_parts )
563
- for p in range (num_parts ):
564
- parts [p ] = min (chunksize * p , num_items )
565
- parts [num_parts ] = num_items
562
+ chunksize = num_items // num_parts
563
+ residual = num_items - (chunksize * num_parts )
564
+
565
+ parts = numpy .arange (0 , (num_parts + 1 ) * chunksize , chunksize )
566
+
567
+ for i in range (residual ):
568
+ parts [i + 1 :] += 1
569
+ parts = parts .tolist ()
570
+
566
571
return parts
567
572
568
573
You can’t perform that action at this time.
0 commit comments