Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: How to compile this module?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg80982] Re: [mg80882] How to compile this module?
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Thu, 6 Sep 2007 05:42:19 -0400 (EDT)
  • References: <26506823.1188992308374.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

The "myM" function returns "res" as the result but doesn't set it in any 
way, so it couldn't possibly work on lst = {1, 2, 4, 5, 6, 9, 10, 12, 15,  
1000} or any other list. Ditto for "myC". If your code doesn't work and 

you haven't told us what it's supposed to do, so how can anyone correct it  
for you?

That said, there are some obvious problems with your Compile statement. 
Since the first argument is a list, you have to declare this to  
Mathematica, something like

Compile[{{lst, _Integer, 1}, {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}}]

But Compile won't allow every possible Mathematica expression. I doubt  
that Reap and Sow will qualify, for instance. (And you still haven't given  
"res" a value.)

Bobby

On Wed, 05 Sep 2007 01:41:12 -0500, P_ter <peter_van_summeren at yahoo.co.uk>  
wrote:

> 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
>
>



-- 

DrMajorBob at bigfoot.com


  • Prev by Date: Re: Slow Show/Graphics in v6.0
  • Next by Date: Re: How to obtain numberical value from an InverseFunction?
  • Previous by thread: Re: How to compile this module?
  • Next by thread: Re: How to compile this module?