eric-haibin-lin commented on a change in pull request #16175: [Dataset] add 
shard API
URL: https://github.com/apache/incubator-mxnet/pull/16175#discussion_r324509765
 
 

 ##########
 File path: python/mxnet/gluon/data/dataset.py
 ##########
 @@ -84,14 +84,13 @@ def shard(self, num_shards, index):
         """
         assert index < num_shards, 'Shard index of out bound: %d out of 
%d'%(index, num_shards)
         assert num_shards > 0, 'Number of shards must be greater than 0'
+        assert index >= 0, 'Index must be non-negative'
         length = len(self)
-        shard_len = length // num_shards
+        shard_len = (length + num_shards - 1) // num_shards
         # Compute the start index for this partition
         start = shard_len * index
         # Compute the end index for this partition
-        end = start + shard_len
-        if index == num_shards - 1:
-            end = length
+        end = start + shard_len if index < num_shards - 1 else length
 
 Review comment:
   Got it. Thanks a lot to point this out! I'll fix it 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to