Skip to content

Commit 19ad5c3

Browse files
committed
add fix
1 parent 20f9498 commit 19ad5c3

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

R/pkg/R/context.R

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,10 @@ parallelize <- function(sc, coll, numSlices = 1) {
138138

139139
sizeLimit <- getMaxAllocationLimit(sc)
140140
objectSize <- object.size(coll)
141+
len <- length(coll)
141142

142143
# For large objects we make sure the size of each slice is also smaller than sizeLimit
143-
numSerializedSlices <- max(numSlices, ceiling(objectSize / sizeLimit))
144-
if (numSerializedSlices > length(coll))
145-
numSerializedSlices <- length(coll)
144+
numSerializedSlices <- min(len, max(numSlices, ceiling(objectSize / sizeLimit)))
146145

147146
# Generate the slice ids to put each row
148147
# For instance, for numSerializedSlices of 22, length of 50
@@ -153,8 +152,8 @@ parallelize <- function(sc, coll, numSlices = 1) {
153152
splits <- if (numSerializedSlices > 0) {
154153
unlist(lapply(0: (numSerializedSlices - 1), function(x) {
155154
# nolint start
156-
start <- trunc((x * length(coll)) / numSerializedSlices)
157-
end <- trunc(((x + 1) * length(coll)) / numSerializedSlices)
155+
start <- trunc((as.numeric(x) * len) / numSerializedSlices)
156+
end <- trunc(((as.numeric(x) + 1) * len) / numSerializedSlices)
158157
# nolint end
159158
rep(start, end - start)
160159
}))

0 commit comments

Comments
 (0)