Return-Path: X-Original-To: apmail-commons-dev-archive@www.apache.org Delivered-To: apmail-commons-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 632AE10247 for ; Sat, 16 May 2015 13:59:30 +0000 (UTC) Received: (qmail 78042 invoked by uid 500); 16 May 2015 13:59:30 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 77896 invoked by uid 500); 16 May 2015 13:59:30 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 77881 invoked by uid 99); 16 May 2015 13:59:29 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 May 2015 13:59:29 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 4F6111827F4 for ; Sat, 16 May 2015 13:59:29 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.121 X-Spam-Level: X-Spam-Status: No, score=-0.121 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id O_IcYAEwlgQk for ; Sat, 16 May 2015 13:59:28 +0000 (UTC) Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com [209.85.212.181]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id 9A38743C83 for ; Sat, 16 May 2015 13:59:27 +0000 (UTC) Received: by wicmx19 with SMTP id mx19so58105472wic.0 for ; Sat, 16 May 2015 06:57:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=rdy5wEg/5BP5rjvIEI+e4EAQkFVx+IkrIDkXyjG44Nc=; b=N1Bri85kZJhoA0Jc9c3arBQAlKKaS5Gr3cCFig0dzry93gc+FQge+V5oPlQQdZf/Q/ vTM4eDsAxaE7xMNO7kk/DB9rRkgHLXbzlMGviYiTQjs/hnnEesCap3vOX35dsyyKOZ5/ 58ZyNpIwKhgQpiqZgHVm2VlTWYqN6/rhXQu+LoOe+G42LAJ4PNHiJIe8Yz4VIS9HH0Sp AOGPDKs386kNnbQGZvfWj6m+lge65B0mTk7Ig8wEEpa/BYyaFxrTqv2YAO7lLQulJf8M MD2NOweSeScZ7oeDQnZZNNItr8xDb9XDxrTGtSVri2gX0Zwj08zDuuF4rL2oCtU8u1Fc G8kg== X-Received: by 10.180.82.6 with SMTP id e6mr6371438wiy.84.1431784676714; Sat, 16 May 2015 06:57:56 -0700 (PDT) Received: from [192.168.1.3] (ip-81-11-239-141.dsl.scarlet.be. [81.11.239.141]) by mx.google.com with ESMTPSA id jq3sm7448198wjc.22.2015.05.16.06.57.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 May 2015 06:57:55 -0700 (PDT) Message-ID: <55574CE1.9080302@gmail.com> Date: Sat, 16 May 2015 15:57:53 +0200 From: Thomas Neidhart User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Commons Developers List Subject: Re: [math] working on pow again References: <55531570.8060608@spaceroots.org> <12d9afff05c8b1ff957bf57da1d75de9@scarlet.be> <55538D2D.4070508@spaceroots.org> <555636B1.1000200@spaceroots.org> In-Reply-To: <555636B1.1000200@spaceroots.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On 05/15/2015 08:10 PM, Luc Maisonobe wrote: > Le 14/05/2015 01:29, Gilles a écrit : >> On Wed, 13 May 2015 19:43:09 +0200, Luc Maisonobe wrote: >>> Le 13/05/2015 11:35, Gilles a écrit : >>>> Hello. >>>> >>>> On Wed, 13 May 2015 11:12:16 +0200, Luc Maisonobe wrote: >>>>> Hi all, >>>>> >>>>> As Jenkins failures appeared again, I restarted work on FastMath.pow. >>>>> I'll keep you informed as I make progess. >>>> >>>> Did someone see those failures anywhere else other than on the >>>> identified machine used for CI? >>> >>> I did not reproduce them myselves, and I guess most of us didn't succeed >>> either (lets remember last year when Thomas and Sebb tried to fix the >>> exp function). >>> >>> However, the configuration is not a rare one (Ubuntu, Java 7, Sun JVM), >>> so I fear this bug, even if rare, can hit several people. >> >> How much damage can it do, apart from a false positive on a unit test? >> Isn't it rather the configuration that is faulty, rather than the CM code? > > There are at least some (small) problems in the code. > I did reimplement the method, relying more heavily on bits > representation to detect special cases. This new implementation also > delegates all integer powers to pow(double, long), which handle these > cases directly with high accuracy multiplication and reciprocal. > > This showed that our previous implementation was sometimes slightly > false. For example during one test in the gamma distribution suite, we > compute 147.2421875^-142. Our former implementation returned > 1.3785386632060381807...e-308, and the new implementation returns > 1.3785386632060391688...e-308 whereas the exact result should be > 1.3785386632060390905...e-308. These are denormalized numbers, i.e. > their mantissas have less than 53 significant bits (here, they have 52 > bits). The mantissas are: > > former implementation 0x9E9AA8184555B > new implementation 0x9E9AA8184555D > exact result 0x9E9AA8184555C.D7655353C... > > So we had more than 1.8 ulp error in this case and now we have 0.16 ulp > error. > > Comparing all the calls done in our test suite for the full library, the > differences between the implementations are always in the integer power > cases (which is normal if you look at the code), they are quite rare and > generally only 1ulp away. The case above with 2ulps difference (from > -1.8 to +0.2) is rare. > > Performances are equivalent to the previous ones, the new code is > neither faster nor slower. On my 7 years old desktop computer running > Linux, FastMath.pow takes about 0.69 as much time as StrictMath, as per > Gilles performance benchmarks. > > Two junit tests did not pass anymore, and it took me a long time to > understand. The errors were really related to those 1 or 2 ulps differences. > > The first test was for BOBYQA optimizer, with the DiffPow > function, which computes: > > f(x) = abs(x0)^2 + abs(x1)^4 + abs(x2)^6 + > abs(x3)^8 +abs(x4)^10 + abs(x5)^12 > > The last term (power 12) is sometimes 1ulp away from the previous > implementation (and I think closer to exact result). The optimizer > does converge to the expected result (which is obviously all xi = 0), > but the number of iterations is extremelly large and highly dependent > on the accuracy. With former implementation, it took about 8000 > iterations on my computer, for a limit set to 12000 for this test. With > the new implementation, I needed to raise the limit to 21000 to avoid > failing with a max number of iterations error. It really seems this test > is a stress test for this optimizer. The values computed are really > small, with denormalized numbers. > > The second test was for gamma distribution, corresponding to a shape > parameter of 142. There was only one evaluation of pow that was > different, it is the one depicted above. The two ulps difference > implied the error in the non-overflow part of the distribution (with x > from 0 to 150) was between 1 and 6 ulps, with a mean at about 3.54 ulps > whereas with the previous implementation it was always 0 or 1 ulp with a > mean slightly below 0.5 ulp. So I had to raise the test tolerance to > pass. This seems strange to me. I tried to recompute the reference files > using the maxima script and increasing the accuracy from 64 digits to 96 > digits, but got similar behaviour. The tests for other shape parameters > do all pass (values 1, 8, 10, 100 and 1000). Only value 142 fails. I > even don't know why this 142 value was used (if it were 42 I would have > taken it as a well known humourous reference). Perhaps it was already a > borderline case. > > So here we are. A new implementation is available in the h10-builds > branch. It is as fast as the previous one, is probably slightly more > accurate for integer powers, but makes two tests fail unless we adjust > some test parameters or tolerances. The H10 host seem to not trigger the > JIT optimization bug anymore with this implementation. > > What do we do? Do we put this back to the master branch? +1 to merge the changes back in. Thomas --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org