aboutsummaryrefslogtreecommitdiff
path: root/mllib/src
diff options
context:
space:
mode:
authorSean Owen <sowen@cloudera.com>2016-07-30 04:42:38 -0700
committerSean Owen <sowen@cloudera.com>2016-07-30 04:42:38 -0700
commit0dc4310b470c7e4355c0da67ca3373c3013cc9dd (patch)
tree9a8ac5aefbb25188958e9ae028c7ffdc117b705a /mllib/src
parentbbc247548ac6faeca15afc05c266cee37ef13416 (diff)
downloadspark-0dc4310b470c7e4355c0da67ca3373c3013cc9dd.tar.gz
spark-0dc4310b470c7e4355c0da67ca3373c3013cc9dd.tar.bz2
spark-0dc4310b470c7e4355c0da67ca3373c3013cc9dd.zip
[SPARK-16694][CORE] Use for/foreach rather than map for Unit expressions whose side effects are required
## What changes were proposed in this pull request? Use foreach/for instead of map where operation requires execution of body, not actually defining a transformation ## How was this patch tested? Jenkins Author: Sean Owen <sowen@cloudera.com> Closes #14332 from srowen/SPARK-16694.
Diffstat (limited to 'mllib/src')
-rw-r--r--mllib/src/main/scala/org/apache/spark/mllib/clustering/KMeans.scala2
-rw-r--r--mllib/src/test/scala/org/apache/spark/ml/feature/Word2VecSuite.scala4
-rw-r--r--mllib/src/test/scala/org/apache/spark/mllib/classification/NaiveBayesSuite.scala2
-rw-r--r--mllib/src/test/scala/org/apache/spark/mllib/random/RandomDataGeneratorSuite.scala6
4 files changed, 7 insertions, 7 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 871b1c7d21..9a3d64fca5 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
@@ -268,7 +268,7 @@ class KMeans private (
val iterationStartTime = System.nanoTime()
- instr.map(_.logNumFeatures(centers(0)(0).vector.size))
+ instr.foreach(_.logNumFeatures(centers(0)(0).vector.size))
// Execute iterations of Lloyd's algorithm until all runs have converged
while (iteration < maxIterations && !activeRuns.isEmpty) {
diff --git a/mllib/src/test/scala/org/apache/spark/ml/feature/Word2VecSuite.scala b/mllib/src/test/scala/org/apache/spark/ml/feature/Word2VecSuite.scala
index 16c74f6785..0b441f8b80 100644
--- a/mllib/src/test/scala/org/apache/spark/ml/feature/Word2VecSuite.scala
+++ b/mllib/src/test/scala/org/apache/spark/ml/feature/Word2VecSuite.scala
@@ -138,8 +138,8 @@ class Word2VecSuite extends SparkFunSuite with MLlibTestSparkContext with Defaul
case Row(w: String, sim: Double) => (w, sim)
}.collect().unzip
- assert(synonyms.toArray === Array("b", "c"))
- expectedSimilarity.zip(similarity).map {
+ assert(synonyms === Array("b", "c"))
+ expectedSimilarity.zip(similarity).foreach {
case (expected, actual) => assert(math.abs((expected - actual) / expected) < 1E-5)
}
}
diff --git a/mllib/src/test/scala/org/apache/spark/mllib/classification/NaiveBayesSuite.scala b/mllib/src/test/scala/org/apache/spark/mllib/classification/NaiveBayesSuite.scala
index 0c0aefc52b..5ec4c15387 100644
--- a/mllib/src/test/scala/org/apache/spark/mllib/classification/NaiveBayesSuite.scala
+++ b/mllib/src/test/scala/org/apache/spark/mllib/classification/NaiveBayesSuite.scala
@@ -307,7 +307,7 @@ class NaiveBayesSuite extends SparkFunSuite with MLlibTestSparkContext {
val tempDir = Utils.createTempDir()
val path = tempDir.toURI.toString
- Seq(NaiveBayesSuite.binaryBernoulliModel, NaiveBayesSuite.binaryMultinomialModel).map {
+ Seq(NaiveBayesSuite.binaryBernoulliModel, NaiveBayesSuite.binaryMultinomialModel).foreach {
model =>
// Save model, load it back, and compare.
try {
diff --git a/mllib/src/test/scala/org/apache/spark/mllib/random/RandomDataGeneratorSuite.scala b/mllib/src/test/scala/org/apache/spark/mllib/random/RandomDataGeneratorSuite.scala
index 8416771552..e30ad15967 100644
--- a/mllib/src/test/scala/org/apache/spark/mllib/random/RandomDataGeneratorSuite.scala
+++ b/mllib/src/test/scala/org/apache/spark/mllib/random/RandomDataGeneratorSuite.scala
@@ -80,7 +80,7 @@ class RandomDataGeneratorSuite extends SparkFunSuite {
}
test("LogNormalGenerator") {
- List((0.0, 1.0), (0.0, 2.0), (2.0, 1.0), (2.0, 2.0)).map {
+ List((0.0, 1.0), (0.0, 2.0), (2.0, 1.0), (2.0, 2.0)).foreach {
case (mean: Double, vari: Double) =>
val normal = new LogNormalGenerator(mean, math.sqrt(vari))
apiChecks(normal)
@@ -125,7 +125,7 @@ class RandomDataGeneratorSuite extends SparkFunSuite {
test("GammaGenerator") {
// mean = 0.0 will not pass the API checks since 0.0 is always deterministically produced.
- List((1.0, 2.0), (2.0, 2.0), (3.0, 2.0), (5.0, 1.0), (9.0, 0.5)).map {
+ List((1.0, 2.0), (2.0, 2.0), (3.0, 2.0), (5.0, 1.0), (9.0, 0.5)).foreach {
case (shape: Double, scale: Double) =>
val gamma = new GammaGenerator(shape, scale)
apiChecks(gamma)
@@ -138,7 +138,7 @@ class RandomDataGeneratorSuite extends SparkFunSuite {
}
test("WeibullGenerator") {
- List((1.0, 2.0), (2.0, 3.0), (2.5, 3.5), (10.4, 2.222)).map {
+ List((1.0, 2.0), (2.0, 3.0), (2.5, 3.5), (10.4, 2.222)).foreach {
case (alpha: Double, beta: Double) =>
val weibull = new WeibullGenerator(alpha, beta)
apiChecks(weibull)