MathGroup Archive 2011

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

Search the Archive

Re: Compile and Total

  • To: mathgroup at smc.vnet.net
  • Subject: [mg120275] Re: Compile and Total
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Sat, 16 Jul 2011 05:41:38 -0400 (EDT)
  • References: <201107150120.VAA23682@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

Why "With" is any use here is beyond me, so I'm more confused than I  
started.

Bobby

On Fri, 15 Jul 2011 07:02:35 -0500, Fred Simons <f.h.simons at tue.nl> wrote:

> Dear All,
>
> I apologize for my mistakes. My only excuse is that I am using some drug  
> now, hopefully only for a few days, that is dangerous a.o. in  
> combination with driving, and, as I find now, also in combination with  
> Mathematica. I simply did not see that my 'better' code in my second  
> mail was incorrect in the first example. Neil found a way to overcome  
> it, by giving g head Function instead of Symbol. I have not observed  
> this before, but from this example it seems that  
> InlineExternalDefinitions does a check on the heads such that when an  
> external g is used as a function and does not have head Function, the  
> external definition will not be used.
>
> In my first mail I used the With construct for substituting the  
> definitions into the expression to be compiled. But having done so, then  
> obviously (for me only now) there is no reason for using  
> CompilationOptions:
>
> << CompiledFunctionTools`;
>
> g = Total;
> With[{g = g}, gC = Compile[{{x, _Real, 1}}, g[x]]];
> CompilePrint[gC]
>
> h = #/Total[#] &;
> With[{h = h}, hC = Compile[{{x, _Real, 1}}, h[x]]];
> CompilePrint[hC]
>
> Fred
>
> Op 15-7-2011 12:32, Neil Stewart schreef:
>> Fred, DrMajorBob, Patrick---thank you very much for your replies.  
>> Continuing
>> Fred's code:
>>
>> <<CompiledFunctionTools`;
>>
>> (* This does not compile *)
>> g = Total;
>> gC = Compile[{{x, _Real, 1}}, g[x],
>>     CompilationOptions ->  {"InlineExternalDefinitions" ->  True}];
>> CompilePrint[gC]
>>
>> (* This does *)
>> g = Total[#]&;
>> gC = Compile[{{x, _Real, 1}}, g[x],
>>     CompilationOptions ->  {"InlineExternalDefinitions" ->  True}];
>> CompilePrint[gC]
>>
>> I don't understand why, so I must be missing something fundamental about
>> functions. Do you know the Mathematica keyword for the concept I'm  
>> missing?
>>
>> Thanks,
>> Neil.
>>
>>
>> -----
>> Geen virus gevonden in dit bericht.
>> Gecontroleerd door AVG - www.avg.com
>> Versie: 10.0.1390 / Virusdatabase: 1516/3765 - datum van uitgifte:  
>> 07/14/11
>>
>>
>>
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: Numerical accuracy/precision - this is a bug or
  • Next by Date: Re: Numerical accuracy/precision - this is a bug or a feature?
  • Previous by thread: Re: Compile and Total
  • Next by thread: Re: Compile and Total