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

    https://github.com/apache/spark/pull/11858#discussion_r56839971
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/mllib/classification/NaiveBayesSuite.scala
 ---
    @@ -103,17 +104,26 @@ class NaiveBayesSuite extends SparkFunSuite with 
MLlibTestSparkContext {
           piData: Array[Double],
           thetaData: Array[Array[Double]],
           model: NaiveBayesModel): Unit = {
    -    def closeFit(d1: Double, d2: Double, precision: Double): Boolean = {
    -      (d1 - d2).abs <= precision
    -    }
    -    val modelIndex = (0 until piData.length).zip(model.labels.map(_.toInt))
    -    for (i <- modelIndex) {
    -      assert(closeFit(math.exp(piData(i._2)), math.exp(model.pi(i._1)), 
0.05))
    -    }
    -    for (i <- modelIndex) {
    -      for (j <- 0 until thetaData(i._2).length) {
    -        assert(closeFit(math.exp(thetaData(i._2)(j)), 
math.exp(model.theta(i._1)(j)), 0.05))
    +    val modelIndex = piData.indices.zip(model.labels.map(_.toInt))
    +    try {
    +      for (i <- modelIndex) {
    +        assert(math.exp(piData(i._2)) ~== math.exp(model.pi(i._1)) absTol 
0.05)
    +      }
    +      for (i <- modelIndex) {
    +        for (j <- thetaData(i._2).indices) {
    +          assert(math.exp(thetaData(i._2)(j)) ~== 
math.exp(model.theta(i._1)(j)) absTol 0.05)
    +        }
           }
    +    } catch {
    +      case e: TestFailedException =>
    +        def arr2str(a: Array[Double]): String = a.mkString("[", ", ", "]")
    +        val msg = "\nvalidateModelFit:\n" +
    --- End diff --
    
    You could also make a function that generates the error message you want, 
and pass that as an arg to the asserts. It's more straightforward but not sure 
it's simpler, so whatever you like here.


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

Reply via email to