Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Compile forgets assigned values inside Do unless they are initialised

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82343] Re: Compile forgets assigned values inside Do unless they are initialised
  • From: Vince Virgilio <blueschi at gmail.com>
  • Date: Thu, 18 Oct 2007 04:49:00 -0400 (EDT)
  • References: <fepss7$gi3$1@smc.vnet.net><ff1pcn$8p2$1@smc.vnet.net>

On Oct 16, 3:31 am, "Jean-Marc Gulliet" <jeanmarc.gull... at gmail.com>
wrote:
> Giving more thoughts, I think you are right and my "thesis" would have
> been clearer if I had written, "As a rule of thumb, if one wants to
> compile an expression that uses local symbols, then these symbols
> should be initialized preferably at the beginning of the Module or
> Block construct, or as soon as possible."
>
> Why that? Because, as we are warned by the online documentation,
> "Compiled code does not handle numerical precision and local variables
> in the same way as ordinary Mathematica code."
>
> Moreover, "The number of times and the order in which objects are
> evaluated by Compile may be different from ordinary Mathematica code."
>
> In other words, ordinary evaluation rules do not necessarily and/or
> usually apply to compiled code.

I second this.

Here's another example with similar behavior, but with Compile at
level > 0.

In[5]:= Module[{x},Compile[{},x=7;];x]
Module[{x=0},Compile[{},x=7;];x]
Out[5]= x$178
Out[6]= 0

Notice that it does not produce messages. Beware.

Vince Virgilio



  • Prev by Date: Debugging with v6
  • Next by Date: Re: Mathematica 6.01 and openSUSE 10.3
  • Previous by thread: Re: Compile forgets assigned values inside Do unless they are initialised
  • Next by thread: InverseFourierTransform strange behaviour