MathGroup Archive 2005

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

Search the Archive

Nested iterators in Compile

  • To: mathgroup at
  • Subject: [mg55010] Nested iterators in Compile
  • From: Maxim <ab_def at>
  • Date: Wed, 9 Mar 2005 06:34:35 -0500 (EST)
  • Sender: owner-wri-mathgroup at

The fact that iterators work differently when used in Compile seems to  
lead to a serious limitation:

   Module[{s = 0},
     Do[s += j, {i, n}, {j, i}];

CompiledFunction::cfse: Compiled expression i should be a machine-size  
real number.

CompiledFunction::cfex: External evaluation error at instruction 4;  
proceeding with uncompiled evaluation.


The iterator {j, i} is evaluated before any value is assigned to i, and  
the evaluation of the compiled code fails (and if we add the  
initialization i=0 before Do, we'll only get an empty loop as the result,  
unlike the uncompiled version). So we have to resort to some workarounds  
such as changing the inner iterator to {j, n} and adding If[j>i,  
Continue[]] to the loop body, which of course decreases the performance.

Maxim Rytin
m.r at

  • Prev by Date: Re: substrings at the end of words
  • Next by Date: NIntegrate a COM Object
  • Previous by thread: Re: symbolic approximation (formular manipulation)
  • Next by thread: Re: Nested iterators in Compile