MathGroup Archive 2007

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

Search the Archive

How to return a mixture of vectors and matrices from compiled functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg79422] How to return a mixture of vectors and matrices from compiled functions
  • From: Frank Hu <frank1998 at gmail.com>
  • Date: Thu, 26 Jul 2007 05:36:26 -0400 (EDT)

Hi, all,

I need to return two vectors and a matrix from a purely numerical  
function, by setting the last expression of the function to something  
like {v1,v2,m1}.  v1 and v2 are column vectors, effectively nx1  
matrices.  The function compiles fine (no 'Function' in the 4th  
component in the input form).  When I call the function though, I got  
the message

CompiledFunction::"cflist" :  "Nontensor object generated; proceeding  
with uncompiled evaluation"

It can be demonstrated by the following snippet; f3 runs fine, but  
not f4.

In[501]:= f3=Compile[{},{{{1.},{1.},{1.}},{{2.},{2.},{2.}}}]
Out[501]= CompiledFunction[{},{{{1.},{1.},{1.}},{{2.},{2.},{2.}}},- 
CompiledCode-]
In[502]:= f3[]
Out[502]= {{{1.},{1.},{1.}},{{2.},{2.},{2.}}}
In[503]:= f4=Compile[{},{{{1.},{1.},{1.}},{{2.},{2.},{2.}}, 
{{1.,0.,0.},{0.,1.,0},{0.,0.,1.}}}]
Out[503]= CompiledFunction[{},{{{1.},{1.},{1.}},{{2.},{2.},{2.}}, 
{{1.,0.,0.},{0.,1.,0},{0.,0.,1.}}},-CompiledCode-]
In[504]:= f4[]
During evaluation of In[504]:= CompiledFunction::cflist: Nontensor  
object generated; proceeding with uncompiled evaluation. >>
Out[504]= {{{1.},{1.},{1.}},{{2.},{2.},{2.}},{{1.,0.,0.},{0.,1.,0}, 
{0.,0.,1.}}}

It seems that Compile needs the return value to have the same  
dimensions.  Why is that?  I know that compiled functions always  
return packed arrays, if arrays are to be returned.   
Developer`ToPackedArray[{v1,v2,m1}] seems to work, though.  So what  
is the proper way to return the mixture of vectors and matrices?

Frank


  • Prev by Date: Letting functions not evaluate
  • Next by Date: Re: Cyclic permutations
  • Previous by thread: Re: Letting functions not evaluate
  • Next by thread: approximation