Re: Nested iterators in Compile
- To: mathgroup at smc.vnet.net
- Subject: [mg55112] Re: Nested iterators in Compile
- From: "Ray Koopman" <koopman at sfu.ca>
- Date: Sun, 13 Mar 2005 04:57:32 -0500 (EST)
- References: <d0u6m8$klc$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Wolf, Hartmut wrote: >>-----Original Message----- >>From: Ray Koopman [mailto:koopman at sfu.ca] To: mathgroup at smc.vnet.net >>Sent: Friday, March 11, 2005 10:21 AM >>Subject: [mg55112] Re: Nested iterators in Compile >> >>Wolf, Hartmut wrote: >>> [...] >>> Also mistrust any compiled function f with >>> >>> In[3]:= FreeQ[f[[-2]], Function] >>> Out[3]= False >>> >>> >>> This case can be solved easily: >>> >>> In[4]:= f2 = Compile[{{n, _Integer}}, >>> Module[{s = 0}, Do[Do[s += j, {j, i}], {i, n}]; >>> s]]; >>> >>> In[5]:= f2[10] >>> Out[5]= 220 >>> >>> In[6]:= FreeQ[f2[[-2]], Function] >>> Out[6]= True >>> >> >>In[1]:= f1 = Compile[{n}, Module[{s = 0}, >> Do[s += j, {i, n}, {j, i}]; s]]; >> >>In[2]:= f2 = Compile[{{n, _Integer}},Module[{s = 0}, >> Do[Do[s += j, {j, i}], {i, n}]; s]]; >> >>In[3]:= FreeQ[f1[[#]],Function]& /@ Range@Length@f1 >> FreeQ[f2[[#]],Function]& /@ Range@Length@f2 >> >>Out[3]= {True,True,True,False,False,True} >>Out[4]= {True,True,True,True,False,True} >> >>Do you mean f[[-3]] ? >> >> > > In fact, I mean f[[4]] which, with my version is f[[-2]], with your's > obviously not. > > I'm sorry about that, but would like to know what you see at > f2//InputForm. > > > -- > Hartmut Wolf In[1]:= $Version Out[1]= 5.1 for Mac OS X (October 25, 2004) In[2]:= InputForm[f1 = Compile[{n}, Module[{s = 0}, Do[s += j, {i, n}, {j, i}]; s]]] Out[2]//InputForm= CompiledFunction[{_Real}, {{3, 0, 0}, {2, 0, 0}}, {0, 6, 3, 0, 0}, {{1, 5}, {4, 0, 0}, {37, 0, 1}, {21, Function[{n}, i], 3, 0, 0, 3, 0, 2}, {37, 2, 2}, {4, 0, 3}, {79, 3, 1, 6}, {4, 0, 4}, {79, 4, 2, -2}, {24, 0, 4, 5}, {9, 5, 0}, {42, -3}, {2}}, Function[{n}, Module[{s = 0}, Do[s += j, {i, n}, {j, i}]; s]], Evaluate] In[3]:= InputForm[f2 = Compile[{{n, _Integer}},Module[{s = 0}, Do[Do[s += j, {j, i}], {i, n}]; s]]] Out[3]//InputForm= CompiledFunction[{_Integer}, {{2, 0, 0}, {2, 0, 1}}, {0, 7, 0, 0, 0}, {{1, 5}, {4, 0, 1}, {9, 0, 2}, {4, 0, 3}, {79, 3, 2, 8}, {9, 3, 4}, {4, 0, 5}, {79, 5, 4, 4}, {24, 1, 5, 6}, {9, 6, 1}, {42, -3}, {42, -7}, {2}}, Function[{n}, Module[{s = 0}, Do[Do[s += j, {j, i}], {i, n}]; s]], Evaluate]