mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r774822 - /lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/RandomUtils.java
Date Thu, 14 May 2009 15:28:06 GMT
Author: srowen
Date: Thu May 14 15:28:05 2009
New Revision: 774822

URL: http://svn.apache.org/viewvc?rev=774822&view=rev
Log:
More intelligent handling of small values

Modified:
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/RandomUtils.java

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/RandomUtils.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/RandomUtils.java?rev=774822&r1=774821&r2=774822&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/RandomUtils.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/RandomUtils.java
Thu May 14 15:28:05 2009
@@ -64,6 +64,9 @@
     if (n > MAX_INT_SMALLER_TWIN_PRIME) {
       throw new IllegalArgumentException();
     }
+    if (n <= 2) {
+      return 3;
+    }
     int next = nextPrime(n);
     while (isNotPrime(next + 2)) {
       next = nextPrime(next + 4);
@@ -75,6 +78,9 @@
    * <p>Finds smallest prime p such that p is greater than or equal to n.</p>
    */
   public static int nextPrime(int n) {
+    if (n < 2) {
+      return 2;
+    }
     // Make sure the number is odd. Is this too clever?
     n |= 0x1;
     // There is no problem with overflow since Integer.MAX_INT is prime, as it happens
@@ -89,10 +95,7 @@
    * @return <code>true</code> iff n is not a prime
    */
   public static boolean isNotPrime(int n) {
-    if (n < 2) {
-      throw new IllegalArgumentException();
-    }
-    if ((n & 0x1) == 0) { // even
+    if (n < 2 || (n & 0x1) == 0) { // < 2 or even
       return true;
     }
     int max = 1 + (int) Math.sqrt((double) n);



Mime
View raw message