Compiled function changes somehow.
- To: mathgroup at smc.vnet.net
- Subject: [mg78568] Compiled function changes somehow.
- From: Nacho <ncc1701zzz at gmail.com>
- Date: Wed, 4 Jul 2007 05:40:30 -0400 (EDT)
Hello. I have been playing with Compile to accelerate some simple code and I have found some differences that I cannot explain. The standard/compiled code is as follows: standard[max_] := Table[n/m, {n, 1, max}, {m, 1, max}] // N // Flatten; compiled = Compile[{{max, _Integer}}, Table[n/m, {n, 1, max}, {m, 1, max}] // N // Flatten]; So I can do the same calculations with both codes: In[19]:= standardresult = standard[1000]; // Timing Out[19]= {2.969, Null} In[20]:= compiledresult = compiled[1000]; // Timing Out[20]= {0.422, Null} The second is much faster, as expected. But are the results the same? Apparently, yes: In[21]:= standardresult == compiledresult Out[21]= True In[22]:= standardresult === compiledresult Out[22]= True But when I use Union in the lists to count the number of different elements, I have this surprise: Length[Union[standardresult]] Length[Union[compiledresult]] Out[23]= 608383 Out[24]= 634815 So they are not exactly the same... I think that the correct answer comes from the uncompiled version. It is the same if I remove the //N so it can be compared symbolically. Is this behaviour expected? Am I missing something? Both seem to be Machine Precision, but obviously there are some little differences. This happens with V5.2 and V6.0. Any hint? Thank you.
- Follow-Ups:
- Re: Compiled function changes somehow.
- From: Andrzej Kozlowski <akoz@mimuw.edu.pl>
- Re: Compiled function changes somehow.
- From: Carl Woll <carlw@wolfram.com>
- Re: Compiled function changes somehow.