Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Help on code comprehension from an example project of pymc Date: Wed, 16 Dec 2015 09:34:24 +1100 Lines: 39 Message-ID: References: <5e772de2-e50f-48f1-988c-a7c3eff33b10@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de t/zoHlHknqhPEe3NngEmmweqvUy7N5spM4vDdC5b/6Ug== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '16,': 0.03; 'apis': 0.07; 'line:': 0.07; 'raises': 0.07; 'subject:code': 0.07; 'subject:skip:c 10': 0.07; 'ugly': 0.07; 'api': 0.09; 'cc:addr :python-list': 0.09; 'ignoring': 0.09; 'must,': 0.09; 'subject:Help': 0.10; 'exception': 0.13; 'wed,': 0.15; "'data'": 0.16; 'code),': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'instantiate': 0.16; 'modules,': 0.16; 'pythonic': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'instance,': 0.18; 'subject:project': 0.18; '(in': 0.18; 'runs': 0.18; 'language': 0.19; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; 'code,': 0.23; 'dec': 0.23; "python's": 0.23; 'examples': 0.24; 'header:In-Reply- To:1': 0.24; "doesn't": 0.26; '(which': 0.26; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; 'arguments,': 0.29; 'equally': 0.29; 'referenced': 0.29; 'objects': 0.29; "i'm": 0.30; 'guess': 0.31; 'getting': 0.33; 'this?': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'robert': 0.35; 'quite': 0.35; 'something': 0.35; 'comment': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'received:209.85.213': 0.37; 'doing': 0.38; 'received:209': 0.38; 'end': 0.39; 'why': 0.39; 'data': 0.39; 'subject:from': 0.39; 'where': 0.40; 'still': 0.40; 'high': 0.60; 'your': 0.60; 'skip:u 10': 0.61; 'default': 0.61; 'side': 0.62; 'more': 0.63; 'different': 0.63; 'believe': 0.66; 'experience.': 0.66; 'expert': 0.70; 'as:': 0.79; 'chrisa': 0.84; 'original.': 0.84; 'presumably': 0.84; 'to:none': 0.91; 'effects.': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=lQR/89URJw0BoA2kgDB+3zj/86Ih7dTO2gQCqbtR77U=; b=nQ9SspNU6/+9IAp7MGTpUnDOYkjThJaJwQFC/Bc5iWisAGg6RoUviswFWj1KsgZ7Ju k5Esf8EMzxHUc+5Er04p1Aj/yZkFblkppumIkatVE4916PkUaJeICQ0pyvgv56Z5Vk7T QLHkzK8IwBX8wFLc/Bq9VaAMa+Z1QOi0sRgfSVR7/icMA/2wBlGufcyK1W9pdUjkyAJV NdtQg5+QG8r3MFT1/tLW0LvN84S9M5xCDb2TM+pvlw37xmPaNkb5GaUwNitOjH7Q00s6 MYQJmjveIHAXTUNGurwZKj6u34+oHnPHuU7+2/NlCUtvJU1UqJE2bKj9Fb8zAfjrGc1E 101w== X-Received: by 10.50.20.8 with SMTP id j8mr7036968ige.94.1450218864451; Tue, 15 Dec 2015 14:34:24 -0800 (PST) In-Reply-To: <5e772de2-e50f-48f1-988c-a7c3eff33b10@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100484 On Wed, Dec 16, 2015 at 3:15 AM, Robert wrote: > When I review the code, I find 'data' in the original line: > > data = pymc.Normal('data', mu=model, tau=tau, value=z_obs, observed=True) > > has not been referenced thereafter. > If I comment out the line as: > > #data = pymc.Normal('data', mu=model, tau=tau, value=z_obs, observed=True) > > the result is ugly different from the original. > > If I change it to: > > pymc.Normal('data', mu=model, tau=tau, value=z_obs, observed=True) > > it still runs as the original. > > This is quite different from my any other language experience. > > Could you help me on this? What this suggests is that the call you're doing returns something (as every function call must, unless it raises an exception or doesn't terminate), but it also has side effects. You're ignoring the return value (which is why "data = " doesn't affect your code), but you need the side effects. Unfortunately this is the case with quite a lot of Python's high end math/stats modules, presumably because their APIs are lifted directly from other languages; have a look at pyplot, for instance, where a more Pythonic API would be to instantiate a plot object every time. (In that particular example, I believe that's an option; but most examples just use the module-level default.) It's my guess (based on skimming the docs) that the objects passed in, including those referenced as function default arguments, are getting mutated. But I'm no expert on pymc. It's equally likely that module-level (global) state is being changed. ChrisA