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

    https://github.com/apache/spark/pull/16037#discussion_r90773871
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/optimization/LBFGS.scala ---
    @@ -241,16 +241,27 @@ object LBFGS extends Logging {
           val bcW = data.context.broadcast(w)
           val localGradient = gradient
     
    -      val (gradientSum, lossSum) = data.treeAggregate((Vectors.zeros(n), 
0.0))(
    -          seqOp = (c, v) => (c, v) match { case ((grad, loss), (label, 
features)) =>
    -            val l = localGradient.compute(
    -              features, label, bcW.value, grad)
    -            (grad, loss + l)
    -          },
    -          combOp = (c1, c2) => (c1, c2) match { case ((grad1, loss1), 
(grad2, loss2)) =>
    -            axpy(1.0, grad2, grad1)
    -            (grad1, loss1 + loss2)
    -          })
    +      // Given (current accumulated gradient, current loss) and (label, 
features)
    +      // tuples, updates the current gradient and current loss
    +      val seqOp = (c: (Vector, Double), v: (Double, Vector)) =>
    +        (c, v) match {
    +          case ((grad, loss), (label, features)) =>
    +            val denseGrad = grad.toDense
    +            val l = localGradient.compute(features, label, bcW.value, 
denseGrad)
    +            (denseGrad, loss + l)
    +        }
    +
    +      // Adds two (gradient, loss) tuples
    +      val combOp = (c1: (Vector, Double), c2: (Vector, Double)) =>
    +        (c1, c2) match { case ((grad1, loss1), (grad2, loss2)) =>
    +          val denseGrad1 = grad1.toDense
    +          val denseGrad2 = grad2.toDense
    +          axpy(1.0, denseGrad2, denseGrad1)
    +          (denseGrad1, loss1 + loss2)
    +       }
    +
    +      val zeroSparseVector = Vectors.sparse(n, Seq())
    +      val (gradientSum, lossSum) = data.treeAggregate(zeroSparseVector, 
0.0)(seqOp, combOp)
    --- End diff --
    
    I'm slightly in favor of keeping the parentheses for the zero values. If 
you don't know the signature of `treeAggregate` and that the scala compiler 
evidently packs these into a tuple, you may be confused about what the second 
argument is. Not a strong preference.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to