Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Compile can't handle indexed variables inside loops

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114266] Compile can't handle indexed variables inside loops
  • From: Frank K <fkampas at gmail.com>
  • Date: Mon, 29 Nov 2010 06:08:23 -0500 (EST)

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: Reasons for a two-dimensional layout (was Re: Mathematica 8 docs
  • Next by Date: Re: Mathematica and Symbolic Manipulation
  • Previous by thread: Re: Reasons for a two-dimensional layout (was Re: Mathematica 8 docs
  • Next by thread: Re: Compile can't handle indexed variables inside loops