MathGroup Archive 2011

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

Search the Archive

Re: Array of arrays of various sizes and compile

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115703] Re: Array of arrays of various sizes and compile
  • From: Oliver Ruebenkoenig <ruebenko at wolfram.com>
  • Date: Wed, 19 Jan 2011 05:22:56 -0500 (EST)

On Tue, 18 Jan 2011, Ramiro wrote:

> Is it possible to include such a variable in a compiled function?
>
> { {1}, {2,3}, {1}, {5,7,8} }
>
> I am getting an error with such input.
>
> Example:
>
> example=Compile[{{m,_Integer,2}},Plus@@Flatten[m]]
>
> example[{{1},{2}}]
>
> Works ok.
>
> But for the following:
> example[{{1},{2,1}}]
>
> During evaluation of In[338]:= CompiledFunction::cfta: Argument {{1},
> {2,1}} at position 1 should be a rank 2 tensor of machine-size
> integers. >>
> Out[340]= 4
>
> Any suggestions?
>
> Thanks,
> Ramiro
>
>

Hi Ramiro,

you could use:

tmp = Compile[{{m, _Integer, 1}}, Total[m],
   RuntimeAttributes -> Listable]
example2[data_] := tmp[tmp[data]]

example2[{{1}, {2, 1}}]

example2[{{1}, {2, 3}, {1}, {5, 7, 8}}]


Oliver


  • Prev by Date: Re: SetOptions does not work with Grid
  • Next by Date: Re: SetOptions does not work with Grid
  • Previous by thread: Re: Array of arrays of various sizes and compile
  • Next by thread: Re: Array of arrays of various sizes and compile