Github user srowen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1425#discussion_r15216588
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/mllib/util/TestingUtils.scala ---
    @@ -18,28 +18,90 @@
     package org.apache.spark.mllib.util
     
     import org.apache.spark.mllib.linalg.Vector
    +import org.scalatest.exceptions.TestFailedException
     
     object TestingUtils {
     
    +  val defaultEpsilon = 1E-10
    +
       implicit class DoubleWithAlmostEquals(val x: Double) {
    -    // An improved version of AlmostEquals would always divide by the 
larger number.
    -    // This will avoid the problem of diving by zero.
    -    def almostEquals(y: Double, epsilon: Double = 1E-10): Boolean = {
    -      if(x == y) {
    +
    +    def almostEquals(y: Double, eps: Double = defaultEpsilon): Boolean = {
    +      val absX = math.abs(x)
    +      val absY = math.abs(y)
    +      val diff = math.abs(x - y)
    +      if (x == y) {
             true
    -      } else if(math.abs(x) > math.abs(y)) {
    -        math.abs(x - y) / math.abs(x) < epsilon
    +      } else if (absX < 1E-15 || absY < 1E-15) {
    --- End diff --
    
    See commentary at 
https://issues.apache.org/jira/browse/SPARK-2599?focusedCommentId=14068293&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14068293
 I can see the idea here, but all of these kinds of efforts seem to lead to 
errors or unintuitive behavior. For example this line means that:
    
    Fails:
    expected = 1e-15
    actual = 2e-15
    eps = 0.1
    
    Passes:
    expected = 1e-16
    actual = 2e-16
    eps = 0.1
    
    Why is 1e-15 special anyway?


---
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.
---

Reply via email to