Re: Compile and Total
- To: mathgroup at smc.vnet.net
- Subject: [mg120285] Re: Compile and Total
- From: Fred Simons <f.h.simons at tue.nl>
- Date: Sat, 16 Jul 2011 05:43:26 -0400 (EDT)
- References: <201107150120.VAA23682@smc.vnet.net> <201107150809.EAA26806@smc.vnet.net> <4E200C78.4050008@tue.nl> <20110715103232.GE31132@stewart.warwick.ac.uk>
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 > > >
- References:
- Compile and Total
- From: Neil Stewart <neil.stewart@warwick.ac.uk>
- Re: Compile and Total
- From: DrMajorBob <btreat1@austin.rr.com>
- Compile and Total