You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by mahmoudmahdi24 <gi...@git.apache.org> on 2018/06/29 10:30:40 UTC
[GitHub] spark pull request #21120: [SPARK-22448][ML] Added sum function to Summerize...
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