MathGroup Archive 2006

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

Search the Archive

Re: Compile arguments

  • To: mathgroup at
  • Subject: [mg64230] Re: [mg64176] Compile arguments
  • From: Darren Glosemeyer <darreng at>
  • Date: Tue, 7 Feb 2006 03:35:59 -0500 (EST)
  • Sender: owner-wri-mathgroup at

One possibility would be to write a function that constructs the InputForm 
for the Compile input from strings.  For instance, buildcompiledfun 
constructs the expression (using Join as fc) based on a list of input 

In[1]:= fc = Join;

In[2]:= vars = {x, y};

In[3]:= Compile[{{x, _Real, 1}, {y, _Real, 1}},
          Apply[fc, vars], {{Apply[fc, vars], _Real}}]

Compile::cpapot: Compilation of fc @@ vars can only proceed when fc
      is Times, Plus or List; evaluation will use the uncompiled function.

Out[3]= CompiledFunction[{x, y}, fc @@ vars, -CompiledCode-]

In[4]:= buildcompiledfun[vars_] :=
           "Compile[" <> ToString[InputForm[Map[{#, _Real, 1} &, vars]]] <> 
"," <>
            ToString[InputForm[Apply[fc, vars]]] <> ",{{" <>
            ToString[InputForm[Apply[fc, vars]]] <> ",_Real}}]"]

buildcompiledfun[vars] is now a compiled function that evaluates for 
Length[vars] real vector arguments.

In[5]:= buildcompiledfun[{a, b}][{1.}, {2.}]

Out[5]= {1., 2.}

In[6]:= vals = Table[{i}, {i, 10}]

Out[6]= {{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}}

For an unspecified length, the list of variables for buildcompiledfun can 
be constructed based on the length of vals and the resulting compiled 
function applied to vals.

In[7]:= Apply[buildcompiledfun[Table[Unique[x], {Length[vals]}]], vals]

Out[7]= {1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}

Darren Glosemeyer
Wolfram Research

At 04:13 AM 2/4/2006 -0500, gcer wrote:
>Function fc is already compiled numerical function. When I use the
>following compilatinon line to build new function gc it compiles ok:
>but since, the function fc has more than just two arguments (25 to 30,
>two arguments are used for clarity) and I would like to compile the
>whole polinom of fc functions :
>It does not compile and I get following error line:
>"Compile::cpapot: Compilation of fc@@vars can only proceed when fc is
>Times, \Plus or List; evaluation will use the uncompiled function."
>With best regards,
>Gregor Cernivec

  • Prev by Date: Re: Digital Image Processing: showing graylevel images in
  • Next by Date: Solve problems
  • Previous by thread: Compile arguments
  • Next by thread: Notebooks, packages, cells, and literate programming