spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mahmoudmahdi24 <...@git.apache.org>
Subject [GitHub] spark pull request #21120: [SPARK-22448][ML] Added sum function to Summerize...
Date Fri, 29 Jun 2018 10:30:40 GMT
Github user mahmoudmahdi24 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/21120#discussion_r199119223
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/stat/Summarizer.scala ---
    @@ -562,6 +573,23 @@ private[ml] object SummaryBuilderImpl extends Logging {
     
           Vectors.dense(currL1)
         }
    +
    +    /**
    +     * Sum of each dimension
    +     */
    +    def sum: Vector = {
    +      require(requestedMetrics.contains(Sum))
    +      require(totalWeightSum > 0, s"Nothing has been added to this summarizer.")
    +
    +      val realSum = Array.ofDim[Double](n)
    +      var i = 0
    +      val len = currMean.length
    +      while (i < len) {
    +        realSum(i) = currMean(i) * weightSum(i)
    +        i += 1
    --- End diff --
    
    Please avoid using mutable values, use foldLeft for example to solve this.


---

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


Mime
View raw message