MathGroup Archive 2010

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

Search the Archive

Re: multiple outputs from compiled function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114368] Re: multiple outputs from compiled function
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Thu, 2 Dec 2010 05:40:17 -0500 (EST)

Eric Michielssen wrote:
> Thanks for the suggestion.
> 
> I was thinking more about a routine that populates a huge sparse matrix, say
> for finite element analysis. SparseArray does not work within Compile, and
> that's understandable. 
> 
> So the next best thing would be to have a compiled function generate a long
> list of positions ( pos = {pos1,pos2,pos3...} with posi = {n1,n2} ) and a
> list of values ( val = {val1,val2,val3,...} ), and then construct the
> SparseArray externally to a compiled function. 
> 
> But how do I get my compiled function to return both pos and val? Upon
> reaching Return[{pos,val}], Mathematica reverts to the noncompiled function,
> in essence starting over from scratch. (I can only think of a few not so
> elegant solutions, none of which would apply in situations more complex than
> the above).
> 
> Eric

Seems weird, but you might just do the setting via external variable(s). 
Here is a brief example. Notice that the list 'll' is not defined within 
Compile, but it is used in a Part assignment therein.

In[1]:= ll = {2., 3., 4.};

In[2]:= c = Compile[{{x}, {y}}, ll[[1]] = x; y];

In[3]:= c[4.5, 5.6]
Out[3]= 5.6

In[4]:= ll
Out[4]= {4.5, 3., 4.}

Daniel Lichtblau
Wolfram Research


  • Prev by Date: Re: How to evaluate the Laplacian of a function as a function?
  • Next by Date: Re: Re-virginating Manipulates?
  • Previous by thread: Re: multiple outputs from compiled function
  • Next by thread: Re: multiple outputs from compiled function