Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.041 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'value,': 0.04; 'subject:()': 0.09; 'sure,': 0.09; 'jan': 0.12; 'comparison.': 0.16; 'conditional': 0.16; 'determining': 0.16; 'efficiency.': 0.16; 'matlab': 0.16; 'zero,': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'differ': 0.19; 'error': 0.23; 'together.': 0.24; 'equivalent': 0.26; 'pass': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'am,': 0.29; 'generally': 0.29; 'absolute': 0.30; 'relative': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'calculated': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'probably': 0.32; 'guess': 0.33; 'not.': 0.33; 'case,': 0.35; 'usual': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'url:ref': 0.36; 'minimum': 0.38; 'branch': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'simple': 0.61; 'maximum': 0.63; 'more': 0.64; 'taking': 0.65; 'close': 0.67; 'url:help': 0.67; '2015': 0.84; 'or:': 0.84; 'subject:skip:n 10': 0.84; 'tolerance': 0.84; 'hand,': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=Engs/IxGw775i03taRmICa9OiI1VDDs9EK5IRdirQbo=; b=OVfICcWapVbk2Z5WfSd90LxN9yKVMTh+CXUVWOAzlJJ56kbx/CmUF2pLHnj/QNtue2 qw+tDJvgd3GHfylgGGg/2YrL6/s/FzDaWS/glfqCxSpCf95BmQrrOJFFCVyDR01t1rpk gs8YkTnw/suPUDXf6FPxzq7371JGnvb7J4yTHhDD+KtcesAayide6Ti11V8hvCMCSL0g ucwigzxIq+MDMeclx2T4bi2q6A+hWMs/ByRVfrrlV5c8Sa3gUH/j5mdHYUZY4Y8plArC 1yOp7Z/4sD8M77zlF3royqRbphplZmBoXvyC/YO0eRfP2p+95869fL0pRX1+pZipbLvi 9UUg== X-Received: by 10.66.254.33 with SMTP id af1mr5854524pad.106.1421520196170; Sat, 17 Jan 2015 10:43:16 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <54ba7113$0$12985$c3e8da3$5496439d@news.astraweb.com> References: <54ba7113$0$12985$c3e8da3$5496439d@news.astraweb.com> From: Ian Kelly Date: Sat, 17 Jan 2015 11:42:35 -0700 Subject: Re: numpy.allclose() To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1421520205 news.xs4all.nl 2911 [2001:888:2000:d::a6]:44030 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:83940 On Sat, Jan 17, 2015 at 7:26 AM, Steven D'Aprano wrote: > I don't understand why they add the error tolerances together. I can > understand taking the minimum, or the maximum: The usual idea is that the tolerance is calculated as a relative value, but an absolute tolerance is used instead when the values get close to zero, so under normal circumstances the relative tolerance will dominate and the absolute tolerance will be very small in comparison. So why add them instead of taking the maximum? I'm not sure, but I would guess it's probably for efficiency. Determining the maximum requires the CPU to perform a conditional branch that a simple addition does not. In any case, this is not unique to numpy. See e.g.: https://books.google.com/books?id=CbH0AwAAQBAJ&pg=PA164 (equation 8.26) or: https://books.google.com/books?id=j0rY3D9fx-0C&pg=PA71 (equation 7.437) On the other hand, Matlab evidently uses the maximum: http://www.mathworks.com/help/simbio/ref/absolutetolerance.html > * taking the minimum is equivalent to the rule "numbers are close if they > differ by no more than BOTH the absolute tolerance AND the relative > tolerance". This is generally not the desired semantic, and it's not unheard of to pass 0 for one of the tolerances, in which case the minimum would clearly be incorrect.