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 (
170
170
while (iteration < maxIterations && ! activeRuns.isEmpty) {
171
171
type WeightedPoint = (Array [Double ], Long )
172
172
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)
177
174
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)
180
177
i += 1
181
178
}
182
- (v1 , p1._2 + p2._2)
179
+ (p1._1 , p1._2 + p2._2)
183
180
}
184
181
185
182
val activeCenters = activeRuns.map(r => centers(r)).toArray
@@ -220,6 +217,7 @@ class KMeans private (
220
217
while (j < k) {
221
218
val (sum, count) = totalContribs((i, j))
222
219
if (count != 0 ) {
220
+ val size = sum.size
223
221
var i = 0
224
222
while (i < sum.size) {
225
223
sum(i) /= count
@@ -257,7 +255,7 @@ class KMeans private (
257
255
258
256
logInfo(s " The cost for the best run is $minCost. " )
259
257
260
- new KMeansModel (centers(bestRun).map(c => c .vector))
258
+ new KMeansModel (centers(bestRun).map(_ .vector))
261
259
}
262
260
263
261
/**
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ package org.apache.spark.mllib.util
20
20
import scala .reflect .ClassTag
21
21
22
22
import breeze .linalg .{DenseVector => BDV , SparseVector => BSV ,
23
- squaredDistance => breezeSquaredDistance }
23
+ squaredDistance => breezeSquaredDistance }
24
24
25
25
import org .apache .spark .annotation .Experimental
26
26
import org .apache .spark .SparkContext
You can’t perform that action at this time.
0 commit comments