Return-Path: Delivered-To: apmail-lucene-mahout-commits-archive@minotaur.apache.org Received: (qmail 7269 invoked from network); 14 May 2009 15:29:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 May 2009 15:29:10 -0000 Received: (qmail 92381 invoked by uid 500); 14 May 2009 15:29:10 -0000 Delivered-To: apmail-lucene-mahout-commits-archive@lucene.apache.org Received: (qmail 92310 invoked by uid 500); 14 May 2009 15:29:10 -0000 Mailing-List: contact mahout-commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: mahout-dev@lucene.apache.org Delivered-To: mailing list mahout-commits@lucene.apache.org Received: (qmail 92301 invoked by uid 99); 14 May 2009 15:29:09 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 May 2009 15:29:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 May 2009 15:29:06 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5D2812388866; Thu, 14 May 2009 15:28:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: mahout-commits@lucene.apache.org From: srowen@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090514152844.5D2812388866@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ *

Finds smallest prime p such that p is greater than or equal to n.

*/ 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 true 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);