Re: Compile Module w/ Function inside?
- To: mathgroup at smc.vnet.net
- Subject: [mg42234] Re: [mg42225] Compile Module w/ Function inside?
- From: "Y.A.Tesiram" <yas at pcomm.hfi.unimelb.edu.au>
- Date: Wed, 25 Jun 2003 01:53:29 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
G'day Frank, I don't know if this is of much help, but I had considerable difficulty in using Function inside Compile. I don't think its possible and I recall reading somewhere in the door stop book that it is not supported. Assuming p*2.0 is slightly more complicated than as you have set out the problem, I would suggest you break the problem up into some basic elements, find the slowest part of the computation and Compile it, then proceed with it using Function. Regards Yas On Tue, 24 Jun 2003, Frank Iannarilli wrote: > Hi, > > > I'm trying to speedup a Module. Poking about, I've learned that a > significant impediment to fast Compile'd code is the referencing of > global or otherwise external functions within the Compile'd Module > (indeed, one can check to see if the compiled opcode string is > "pure"). > > As my present Module *does* external function referencing, I wish to > bring these functions inside the Module, defining them using > Function[]. (Believe me, "in-lining" my functions' code within the > Module, every place they need to be invoked, is not an option). > Surely defining (pure) Functions inside Modules is allowed in general > (e.g., outside Compile[]), but I can't find an arrangement that is > Compile'able. > > Here is an example that goes nowhere, i.e., can be evaluated > (foo[3.]=6.), but does not use compiled code: > > foo = Compile[{x}, Module[{q = Function[p, p*2.]}, > q[x]], {{q[_], _Real}, {Function[___], _Real}}] > > In: foo[3.] > > CompiledFunction::cfse: Compiled expression Function[p,p 2.] should be > a \ > machine-size real number. > > Out: 6. > > Any means/hope to achieve my objective? > > > Thanks! > >