MathGroup Archive 2007

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

Search the Archive

How to compile this module?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg80882] How to compile this module?
  • From: P_ter <peter_van_summeren at yahoo.co.uk>
  • Date: Wed, 5 Sep 2007 02:41:12 -0400 (EDT)

Hello,
I have some code in a Module and I would like to compile it so that Mathematica does not give complaints in execution:
myM[lst_, W_] := Module [ {i, j = 1, len = Length@lst, res},
  Reap[For[i = 1, i <= len, i++, 
    While[lst[[j]] - lst[[i]] <= W && j < len, j++];
    Sow[j - i]]; res]
  ]
It works on this special constructed list (with a large number at the end):
lst = {1, 2, 4, 5, 6, 9, 10, 12, 15, 1000};
The following is compiled by Mathematica:
myC = Compile[{{lst, _Integer}, {W, _Integer}}, 
  Module [ {i, j = 1, len = Length@lst, s, res},
   Reap[For[i = 1, i <= len, i++, 
       While[lst[[j]] - lst[[i]] <= W && j < len, j++];
       Sow[j - i]]; res]
   ], {{res, _Integer, 4}}
  ]
If Mathematica executes: myC[lst,2], it gives a message that the argument lst at position 1 should be a machine-size integer.
Can anyone help?
with friendly greetings,
P_ter


  • Prev by Date: Re: Unevaluated hypergeometric functions
  • Next by Date: Re: Unevaluated hypergeometric functions
  • Previous by thread: Re: Formula simplify for Solve
  • Next by thread: Re: How to compile this module?