Github user srowen commented on a diff in the pull request:
https://github.com/apache/spark/pull/5148#discussion_r27136348
--- Diff: core/src/main/scala/org/apache/spark/rdd/DoubleRDDFunctions.scala
---
@@ -191,25 +191,22 @@ class DoubleRDDFunctions(self: RDD[Double]) extends
Logging with Serializable {
}
}
// Determine the bucket function in constant time. Requires that
buckets are evenly spaced
- def fastBucketFunction(min: Double, increment: Double, count: Int)(e:
Double): Option[Int] = {
+ def fastBucketFunction(min: Double, max: Double, count: Int)(e:
Double): Option[Int] = {
// If our input is not a number unless the increment is also NaN
then we fail fast
- if (e.isNaN()) {
- return None
- }
- val bucketNumber = (e - min)/(increment)
- // We do this rather than buckets.lengthCompare(bucketNumber)
- // because Array[Double] fails to override it (for now).
- if (bucketNumber > count || bucketNumber < 0) {
+ if (e.isNaN || e < min || e > max) {
None
} else {
- Some(bucketNumber.toInt.min(count - 1))
+ val bucketNumber = (((e - min) / (max - min)) * count).toInt
--- End diff --
My gut was that it would be more accurate to compute the ratio of two
potentially Huge numbers first, then multiply by something Small, rather than
compute the ratio of Small-to-Huge then multiply by a Huge number. If you try
min = 0, max = 1e20, count = 1000000000 (thats 10^9), e = 1e11, you get 1 from
this expression (correct) whereas the alternative says 0.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]