spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mengxr <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-4431][MLlib] Implement efficient foreac...
Date Fri, 21 Nov 2014 23:09:35 GMT
Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/3288#discussion_r20748804
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/stat/MultivariateOnlineSummarizer.scala
---
    @@ -83,34 +58,37 @@ class MultivariateOnlineSummarizer extends MultivariateStatisticalSummary
with S
           require(sample.size > 0, s"Vector should have dimension larger than zero.")
           n = sample.size
     
    -      currMean = BDV.zeros[Double](n)
    -      currM2n = BDV.zeros[Double](n)
    -      currM2 = BDV.zeros[Double](n)
    -      currL1 = BDV.zeros[Double](n)
    -      nnz = BDV.zeros[Double](n)
    -      currMax = BDV.fill(n)(Double.MinValue)
    -      currMin = BDV.fill(n)(Double.MaxValue)
    +      currMean = Array.ofDim[Double](n)
    +      currM2n = Array.ofDim[Double](n)
    +      currM2 = Array.ofDim[Double](n)
    +      currL1 = Array.ofDim[Double](n)
    +      nnz = Array.ofDim[Double](n)
    +      currMax = Array.fill[Double](n)(Double.MinValue)
    +      currMin = Array.fill[Double](n)(Double.MaxValue)
         }
     
         require(n == sample.size, s"Dimensions mismatch when adding new sample." +
           s" Expecting $n but got ${sample.size}.")
     
    -    sample match {
    -      case dv: DenseVector => {
    -        var j = 0
    -        while (j < dv.size) {
    -          add(j, dv.values(j))
    -          j += 1
    +    sample.foreachActive((index, value) => {
    --- End diff --
    
    The following style is more common in the codebase:
    
    ~~~
    sample.foreachActive { (index, value) =>
      ...
    }
    ~~~


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

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


Mime
View raw message