Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: On the built-in function "Compile"

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90220] Re: On the built-in function "Compile"
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Wed, 2 Jul 2008 05:33:19 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <g4d2ui$eqv$1@smc.vnet.net>

shingo wrote:

<snip>

> However, in the case of nested list, it doesnt.
> 
> In[2]:=
> testB = Compile[{{i, _Integer}},
>   Outer[{#1, #2} &, Range[1, i, 1], Range[1, i, 1]]]
> 
> Out[2]:=
> Compile::cpapot: Compilation of \
> Outer[{#1,#2}&,Range[1,i,1],Range[1,i,1]] is not supported for the \
> function argument {#1,#2}&. The only function arguments supported are
> \
> Times, Plus, or List. Evaluation will use the uncompiled function. >>
> CompiledFunction[{i},Outer[{#1,#2}&,Range[1,i,1],Range[1,i,1]],-
> CompiledCode-]

This has *nothing* to do with nested lists.

The message you get tells you that Compile will compile the function 
Outer[] if and only if the first argument of Outer[] is either one of 
the functions Times, Plus, or List. Nothing else will be accepted.

In[1]:= testB =
   Compile[{{i, _Integer}},
    Outer[Times, Range[1, i, 1], Range[1, i, 1]]];
testB[3]

Out[2]= {{1, 2, 3}, {2, 4, 6}, {3, 6, 9}}

In[3]:= testB =
   Compile[{{i, _Integer}},
    Outer[Plus, Range[1, i, 1], Range[1, i, 1]]];
testB[3]

Out[4]= {{2, 3, 4}, {3, 4, 5}, {4, 5, 6}}

In[5]:= testB =
   Compile[{{i, _Integer}},
    Outer[List, Range[1, i, 1], Range[1, i, 1]]];
testB[3]

Out[6]= {{{1, 1}, {1, 2}, {1, 3}}, {{2, 1}, {2, 2}, {2, 3}}, {{3,
    1}, {3, 2}, {3, 3}}}

Regards,
-- Jean-Marc


  • Prev by Date: Re: Draw two functions in a graph, one of them does also have a parameter.
  • Next by Date: Re: For loop problem in mathematica
  • Previous by thread: Re: On the built-in function "Compile"
  • Next by thread: Re: display Floor in StandardForm