Skip to content

Commit b185a77

Browse files
author
DB Tsai
committed
cleanup
1 parent 4554ddd commit b185a77

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

mllib/src/main/scala/org/apache/spark/mllib/clustering/KMeans.scala

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff 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
/**

mllib/src/main/scala/org/apache/spark/mllib/util/MLUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package org.apache.spark.mllib.util
2020
import scala.reflect.ClassTag
2121

2222
import breeze.linalg.{DenseVector => BDV, SparseVector => BSV,
23-
squaredDistance => breezeSquaredDistance}
23+
squaredDistance => breezeSquaredDistance}
2424

2525
import org.apache.spark.annotation.Experimental
2626
import org.apache.spark.SparkContext

0 commit comments

Comments
 (0)