Re: Compile Module w/ Function inside?
- To: mathgroup at smc.vnet.net
- Subject: [mg42237] Re: Compile Module w/ Function inside?
- From: scwoods at taz.qinetiq.com (Simon Woods)
- Date: Wed, 25 Jun 2003 01:53:32 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Try this:
foo = With[{q = Function[p,2*p]},Compile[{x},q[x]]]
Not sure if this is what you wanted - I think the With function
replaces q with the pure function before Compiling, effectively doing
the "in-lining" for you.
Simon.
frankeye at cox.net (Frank Iannarilli) wrote in message news:<bd8o5m$loo$1 at smc.vnet.net>...
> 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!