Re: Compile can't handle indexed variables inside loops
- To: mathgroup at smc.vnet.net
- Subject: [mg114313] Re: Compile can't handle indexed variables inside loops
- From: Oliver Ruebenkoenig <ruebenko at wolfram.com>
- Date: Tue, 30 Nov 2010 06:23:28 -0500 (EST)
On Tue, 30 Nov 2010, Leonid Shifrin wrote: > 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 Frank, Yes, perhaps Compile shoud give a message like so: fc1 = Module[{x[1], x[2]}, x[1] + x[2]] Oliver > > > 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] >> >> >