spark-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject spark git commit: SPARK-6993 : Add default min, max methods for JavaDoubleRDD
Date Sun, 19 Apr 2015 01:21:47 GMT
Repository: spark
Updated Branches:
  refs/heads/master 729885ec6 -> 8fbd45c74


SPARK-6993 : Add default min, max methods for JavaDoubleRDD

The default method will use Guava's Ordering instead of
java.util.Comparator.naturalOrder() because it's not available
in Java 7, only in Java 8.

Author: Olivier Girardot <o.girardot@lateral-thoughts.com>

Closes #5571 from ogirardot/master and squashes the following commits:

7fe2e9e [Olivier Girardot] SPARK-6993 : Add default min, max methods for JavaDoubleRDD


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/8fbd45c7
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/8fbd45c7
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/8fbd45c7

Branch: refs/heads/master
Commit: 8fbd45c74e762dd6b071ea58a60f5bb649f74042
Parents: 729885e
Author: Olivier Girardot <o.girardot@lateral-thoughts.com>
Authored: Sat Apr 18 18:21:44 2015 -0700
Committer: Reynold Xin <rxin@databricks.com>
Committed: Sat Apr 18 18:21:44 2015 -0700

----------------------------------------------------------------------
 .../org/apache/spark/api/java/JavaDoubleRDD.scala     | 14 ++++++++++++++
 core/src/test/java/org/apache/spark/JavaAPISuite.java | 14 ++++++++++++++
 2 files changed, 28 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/8fbd45c7/core/src/main/scala/org/apache/spark/api/java/JavaDoubleRDD.scala
----------------------------------------------------------------------
diff --git a/core/src/main/scala/org/apache/spark/api/java/JavaDoubleRDD.scala b/core/src/main/scala/org/apache/spark/api/java/JavaDoubleRDD.scala
index 79e4ebf..61af867 100644
--- a/core/src/main/scala/org/apache/spark/api/java/JavaDoubleRDD.scala
+++ b/core/src/main/scala/org/apache/spark/api/java/JavaDoubleRDD.scala
@@ -164,6 +164,20 @@ class JavaDoubleRDD(val srdd: RDD[scala.Double])
   def sum(): JDouble = srdd.sum()
 
   /**
+   * Returns the minimum element from this RDD as defined by
+   * the default comparator natural order.
+   * @return the minimum of the RDD
+   */
+  def min(): JDouble = min(com.google.common.collect.Ordering.natural())
+
+  /**
+   * Returns the maximum element from this RDD as defined by
+   * the default comparator natural order.
+   * @return the maximum of the RDD
+   */
+  def max(): JDouble = max(com.google.common.collect.Ordering.natural())
+
+  /**
    * Return a [[org.apache.spark.util.StatCounter]] object that captures the mean, variance
and
    * count of the RDD's elements in one operation.
    */

http://git-wip-us.apache.org/repos/asf/spark/blob/8fbd45c7/core/src/test/java/org/apache/spark/JavaAPISuite.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/spark/JavaAPISuite.java b/core/src/test/java/org/apache/spark/JavaAPISuite.java
index d4b5bb5..8a4f2a0 100644
--- a/core/src/test/java/org/apache/spark/JavaAPISuite.java
+++ b/core/src/test/java/org/apache/spark/JavaAPISuite.java
@@ -762,6 +762,20 @@ public class JavaAPISuite implements Serializable {
   }
 
   @Test
+  public void naturalMax() {
+    JavaDoubleRDD rdd = sc.parallelizeDoubles(Arrays.asList(1.0, 2.0, 3.0, 4.0));
+    double max = rdd.max();
+    Assert.assertTrue(4.0 == max);
+  }
+
+  @Test
+  public void naturalMin() {
+    JavaDoubleRDD rdd = sc.parallelizeDoubles(Arrays.asList(1.0, 2.0, 3.0, 4.0));
+    double max = rdd.min();
+    Assert.assertTrue(1.0 == max);
+  }
+
+  @Test
   public void takeOrdered() {
     JavaDoubleRDD rdd = sc.parallelizeDoubles(Arrays.asList(1.0, 2.0, 3.0, 4.0));
     Assert.assertEquals(Arrays.asList(1.0, 2.0), rdd.takeOrdered(2, new DoubleComparator()));


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org


Mime
View raw message