@@ -391,41 +391,31 @@ abstract class RDD[T: ClassTag](
391
391
seed : Long = Utils .random.nextLong): Array [T ] = {
392
392
var fraction = 0.0
393
393
var total = 0
394
- val multiplier = 3.0
395
394
val initialCount = this .count()
396
- var maxSelected = 0
397
395
398
396
if (num < 0 ) {
399
397
throw new IllegalArgumentException (" Negative number of elements requested" )
400
398
}
401
399
400
+ if (initialCount == 0 ) {
401
+ return new Array [T ](0 )
402
+ }
403
+
402
404
if (! withReplacement && num > initialCount) {
403
405
throw new IllegalArgumentException (" Cannot create sample larger than the original when " +
404
406
" sampling without replacement" )
405
407
}
406
408
407
- if (initialCount == 0 ) {
408
- return new Array [T ](0 )
409
- }
410
-
411
409
if (initialCount > Integer .MAX_VALUE - 1 ) {
412
- maxSelected = Integer .MAX_VALUE - (5.0 * math.sqrt(Integer .MAX_VALUE )).toInt
410
+ val maxSelected = Integer .MAX_VALUE - (5.0 * math.sqrt(Integer .MAX_VALUE )).toInt
413
411
if (num > maxSelected) {
414
412
throw new IllegalArgumentException (" Cannot support a sample size > Integer.MAX_VALUE - " +
415
413
" 5.0 * math.sqrt(Integer.MAX_VALUE)" )
416
414
}
417
- } else {
418
- maxSelected = initialCount.toInt
419
415
}
420
416
421
- if (num > initialCount && ! withReplacement) {
422
- // special case not covered in computeFraction
423
- total = maxSelected
424
- fraction = multiplier * (maxSelected + 1 ) / initialCount
425
- } else {
426
- fraction = SamplingUtils .computeFraction(num, initialCount, withReplacement)
427
- total = num
428
- }
417
+ fraction = SamplingUtils .computeFraction(num, initialCount, withReplacement)
418
+ total = num
429
419
430
420
val rand = new Random (seed)
431
421
var samples = this .sample(withReplacement, fraction, rand.nextInt()).collect()
0 commit comments