compile related issue
- To: mathgroup at smc.vnet.net
 - Subject: [mg101472] compile related issue
 - From: mpolko lokta <mpolkolokta at gmail.com>
 - Date: Wed, 8 Jul 2009 07:10:32 -0400 (EDT)
 - References: <7c7566c20906270520r49c1a132ndf15d8c7171e8f5@mail.gmail.com>
 
I cannot figure out why the output of the two versions of the decode
function produce different results. I would REALLY appreciate it if
someone could point me in the right direction here. Thanks in advance.
(code follows)
toBase=  Compile[{{list,_Integer,2},{base,_Integer},{strings,_Integer}},Module[{shift=ConstantArray[0,strings],out},Transpose[MapThread[(out=Mod[##-base+shift,base];shift+=##;out)&,{Transpose[list]}]]],{{_,_Integer,1}}]
split1=Compile[{{list,_Integer,2},{base,_Integer},{strings,_Integer},{ilow,_Integer},{ihigh,_Integer}},(Map[FromDigits[#,base]&,toBase[Take[list,All,{ilow,ihigh}],base,strings]]),{{_,_Integer,2}}]
split2[list_,base_,strings_,ilow_,ihigh_]:=Module[{},(Map[FromDigits[#,base]&,toBase[Take[list,All,{ilow,ihigh}],base,strings]])]
map1=Compile[{{list,_Integer,2},{base,_Integer},{strings,_Integer},{ilow,_Integer},{ihigh,_Integer},{digits,_Integer},{low,_Real},{high,_Real}},(low+(high-low)/(base^digits-1)
split1[list,base,strings,ilow,ihigh])//N,{{_,_Real,1}}]
map2[list_,base_,strings_,ilow_,ihigh_,digits_,low_,high_]:=Module[{},(low+(high-low)/(base^digits-1)
split2[list,base,strings,ilow,ihigh])//N]
decode1=Compile[{{list,_Integer,2},{base,_Integer},{strings,_Integer},{ilow,_Integer,1},{ihigh,_Integer,1},{digits,_Integer,1},{low,_Real,1},{high,_Real,1}},Transpose[MapThread[map1[list,base,strings,#1,#2,#5,#3,#4]&,{ilow,ihigh,low,high,digits}]],{{_,_Real,1}}]
decode2[list_,base_,strings_,ilow_,ihigh_,digits_,low_,high_]:=Module[{},Transpose[MapThread[map2[list,base,strings,#1,#2,#5,#3,#4]&,{ilow,ihigh,low,high,digits}]]]
PerformEvaluation=Compile[{{list,_Real,2}},{Sum[-10 Exp[-0.2
Sqrt[#[[i]]^2+#[[i+1]]^2]],{i,1,2}],Sum[Abs[#[[i]]^0.8]+5
Sin[#[[i]]^3],{i,1,3}]}&/@list];
(parameters follow)
BASE=2;
STRINGS=30;
PARAMETERS=3;
DIGITS={20,20,20};
iHIGH=Plus@@NestList[PadLeft[Most[#],PARAMETERS]&,DIGITS,PARAMETERS - 1];
iLOW=PadLeft[PadLeft[{},PARAMETERS-1,1]+PadRight[iHIGH,PARAMETERS-1],PARAMETERS,1];
LENGTH=Plus@@DIGITS;
LOW={-5,-5,-5};
HIGH={5,5,5};
(test modules follow)
strings=Table[RandomChoice[{0,BASE-1},LENGTH],{STRINGS}];
variables1=decode1[strings,BASE,STRINGS,iLOW,iHIGH,DIGITS,LOW,HIGH];
objectives1=PerformEvaluation[variables1];
variables2=decode2[strings,BASE,STRINGS,iLOW,iHIGH,DIGITS,LOW,HIGH];
objectives2=PerformEvaluation[variables2];
variables1==variables2
positions=Position[MapThread[#1==#2&,{variables1,variables2}],False];
pairs=Transpose[Map[Extract[#,positions]&,{variables1,variables2}]]
objectives1==objectives2
positions=Position[MapThread[#1==#2&,{objectives1,objectives2}],False];
pairs=Transpose[Map[Extract[#,positions]&,{objectives1,objectives2}]]