aboutsummaryrefslogtreecommitdiff
path: root/mllib
diff options
context:
space:
mode:
authorwangyang <wangyang@haizhi.com>2016-06-10 13:10:03 -0700
committerReynold Xin <rxin@databricks.com>2016-06-10 13:10:03 -0700
commit026eb90644be7685971dacaabae67a293edd0133 (patch)
treecacc1ed1fb398d122bb5a46fd20b94574203fd58 /mllib
parent865ec32dd997e63aea01a871d1c7b4947f43c111 (diff)
downloadspark-026eb90644be7685971dacaabae67a293edd0133.tar.gz
spark-026eb90644be7685971dacaabae67a293edd0133.tar.bz2
spark-026eb90644be7685971dacaabae67a293edd0133.zip
[SPARK-15875] Try to use Seq.isEmpty and Seq.nonEmpty instead of Seq.length == 0 and Seq.length > 0
## What changes were proposed in this pull request? In scala, immutable.List.length is an expensive operation so we should avoid using Seq.length == 0 or Seq.lenth > 0, and use Seq.isEmpty and Seq.nonEmpty instead. ## How was this patch tested? existing tests Author: wangyang <wangyang@haizhi.com> Closes #13601 from yangw1234/isEmpty.
Diffstat (limited to 'mllib')
-rw-r--r--mllib/src/main/scala/org/apache/spark/mllib/clustering/KMeans.scala2
1 files changed, 1 insertions, 1 deletions
diff --git a/mllib/src/main/scala/org/apache/spark/mllib/clustering/KMeans.scala b/mllib/src/main/scala/org/apache/spark/mllib/clustering/KMeans.scala
index 38728f2693..871b1c7d21 100644
--- a/mllib/src/main/scala/org/apache/spark/mllib/clustering/KMeans.scala
+++ b/mllib/src/main/scala/org/apache/spark/mllib/clustering/KMeans.scala
@@ -441,7 +441,7 @@ class KMeans private (
val rs = (0 until runs).filter { r =>
rand.nextDouble() < 2.0 * c(r) * k / sumCosts(r)
}
- if (rs.length > 0) Some((p, rs)) else None
+ if (rs.nonEmpty) Some((p, rs)) else None
}
}.collect()
mergeNewCenters()