File tree Expand file tree Collapse file tree 2 files changed +7
-9
lines changed
mllib/src/main/scala/org/apache/spark/mllib Expand file tree Collapse file tree 2 files changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -170,16 +170,13 @@ class KMeans private (
170170 while (iteration < maxIterations && ! activeRuns.isEmpty) {
171171 type WeightedPoint = (Array [Double ], Long )
172172 def mergeContribs (p1 : WeightedPoint , p2 : WeightedPoint ): WeightedPoint = {
173- val v1 = p1._1
174- val v2 = p2._1
175- require(v1.size == v2.size)
176- val size = v1.size
173+ require(p1._1.size == p2._1.size)
177174 var i = 0
178- while (i < size) {
179- v1 (i) += v2 (i)
175+ while (i < p1._1. size) {
176+ p1._1 (i) += p2._1 (i)
180177 i += 1
181178 }
182- (v1 , p1._2 + p2._2)
179+ (p1._1 , p1._2 + p2._2)
183180 }
184181
185182 val activeCenters = activeRuns.map(r => centers(r)).toArray
@@ -220,6 +217,7 @@ class KMeans private (
220217 while (j < k) {
221218 val (sum, count) = totalContribs((i, j))
222219 if (count != 0 ) {
220+ val size = sum.size
223221 var i = 0
224222 while (i < sum.size) {
225223 sum(i) /= count
@@ -257,7 +255,7 @@ class KMeans private (
257255
258256 logInfo(s " The cost for the best run is $minCost. " )
259257
260- new KMeansModel (centers(bestRun).map(c => c .vector))
258+ new KMeansModel (centers(bestRun).map(_ .vector))
261259 }
262260
263261 /**
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ package org.apache.spark.mllib.util
2020import scala .reflect .ClassTag
2121
2222import breeze .linalg .{DenseVector => BDV , SparseVector => BSV ,
23- squaredDistance => breezeSquaredDistance }
23+ squaredDistance => breezeSquaredDistance }
2424
2525import org .apache .spark .annotation .Experimental
2626import org .apache .spark .SparkContext
You can’t perform that action at this time.
0 commit comments