MathGroup Archive 2010

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

Search the Archive

Re: Compile can't handle indexed variables inside loops

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114279] Re: Compile can't handle indexed variables inside loops
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Tue, 30 Nov 2010 04:01:22 -0500 (EST)

Hi Frank,

This looks like a bug. I tried For loop with the same effect. I am actually
surprised that Compile at all allows indexed variables.

Regards,
Leonid


On Mon, Nov 29, 2010 at 2:08 PM, Frank K <fkampas at gmail.com> wrote:

> Indexed variables are renamed.  This is ok if they aren't inside a
> loop
>
> In[1]:= fc1 = Compile[{x[1],x[2]},x[1]+x[2]]
>
> Out[1]= CompiledFunction[{x$651,x$652},x$651+x$652,-CompiledCode-]
>
> In[2]:= fc1[1,2]
>
> Out[2]= 3.
>
> Indexed variables are not renamed inside a loop, so the function
> fails.
>
> In[3]:= fc2 = Compile[{x[1],x[2]},Sum[x[i],{i,2}]]
>
> Out[3]= CompiledFunction[{x$655,x$656},\!\(
> \*UnderoverscriptBox[\(\[Sum]\), \(i\), \(2\)]\(x[i]\)\),-
> CompiledCode-]
>
> In[4]:= fc2[1,2]
> During evaluation of In[4]:= CompiledFunction::cfex: Could not
> complete external evaluation at instruction 5;
> proceeding with uncompiled evaluation. >>
>
> Out[4]= x[1]+x[2]
>
>


  • Prev by Date: Re: Re-virginating Manipulates?
  • Next by Date: Re: How do I take every 3rd number from a text file?
  • Previous by thread: Re: Compile can't handle indexed variables inside loops
  • Next by thread: Re: Compile can't handle indexed variables inside loops