Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7161 > unrolled thread

Compile Problem with Nested Sum

Started byJulian Francis <julian.w.francis@gmail.com>
First post2011-12-13 10:41 +0000
Last post2011-12-20 08:10 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Compile Problem with Nested Sum Julian Francis <julian.w.francis@gmail.com> - 2011-12-13 10:41 +0000
    Re: Compile Problem with Nested Sum Frank K <fkampas@gmail.com> - 2011-12-19 12:19 +0000
      Re: Compile Problem with Nested Sum Szabolcs <szhorvat@gmail.com> - 2011-12-20 08:10 +0000

#7161 — Compile Problem with Nested Sum

FromJulian Francis <julian.w.francis@gmail.com>
Date2011-12-13 10:41 +0000
SubjectCompile Problem with Nested Sum
Message-ID<jc7a56$on6$1@smc.vnet.net>
Dear all,

I have a simple function which compiles fine:

fC1 = Compile[{{mx, _Integer}, {my, _Integer}, {mat, _Real, 2}},
  Sum[
   mat[[mx, my]] , {a, 0, 1}]
  ]

However, a sum within a sum doesn't compile:

fC2 = Compile[{{mx, _Integer}, {my, _Integer}, {mat, _Real, 2}},
  Sum[
   Sum[
    mat[[mx, my]] , {a, 0, 1}],
   {b, 1, 1}]
  ]

which generates the following error message:

Compile::noinfo: No information is available for compilation of \!\
(\*UnderoverscriptBox[\(\[Sum]\), \(b = 1\), \(1\)]\
((\*UnderoverscriptBox[\(\[Sum]\), \(a = 0\), \(1\)]mat[[mx, my]])\)
\). The compiler will use an external evaluation and make assumptions
about the return type. >>

I am confused as to why the first works, but the second doesn't.

Any help would be appreciated.

Thanks,
Julian Francis.

[toc] | [next] | [standalone]


#7341

FromFrank K <fkampas@gmail.com>
Date2011-12-19 12:19 +0000
Message-ID<jcna5c$e5m$1@smc.vnet.net>
In reply to#7161
On Dec 13, 5:41 am, Julian Francis <julian.w.fran...@gmail.com> wrote:
> Dear all,
>
> I have a simple function which compiles fine:
>
> fC1 = Compile[{{mx, _Integer}, {my, _Integer}, {mat, _Real, 2}},
>   Sum[
>    mat[[mx, my]] , {a, 0, 1}]
>   ]
>
> However, a sum within a sum doesn't compile:
>
> fC2 = Compile[{{mx, _Integer}, {my, _Integer}, {mat, _Real, 2}},
>   Sum[
>    Sum[
>     mat[[mx, my]] , {a, 0, 1}],
>    {b, 1, 1}]
>   ]
>
> which generates the following error message:
>
> Compile::noinfo: No information is available for compilation of \!\
> (\*UnderoverscriptBox[\(\[Sum]\), \(b = 1\), \(1\)]\
> ((\*UnderoverscriptBox[\(\[Sum]\), \(a = 0\), \(1\)]mat[[mx, my]])\)
> \). The compiler will use an external evaluation and make assumptions
> about the return type. >>
>
> I am confused as to why the first works, but the second doesn't.
>
> Any help would be appreciated.
>
> Thanks,
> Julian Francis.

What version of Mathematica are you running?  It compiles ok on 8.0.4.
However, I don't understand why you're not summing over the indices of
the matrix.
Also, you don't need to nest Sum, you can put both indices inside one
sum

[toc] | [prev] | [next] | [standalone]


#7372

FromSzabolcs <szhorvat@gmail.com>
Date2011-12-20 08:10 +0000
Message-ID<jcpft1$qik$1@smc.vnet.net>
In reply to#7341
On Monday, 19 December 2011 13:19:56 UTC+1, Frank K  wrote:
> On Dec 13, 5:41 am, Julian Francis <julian.w...@gmail.com> wrote:
> > Dear all,
> >
> > I have a simple function which compiles fine:
> >
> > fC1 = Compile[{{mx, _Integer}, {my, _Integer}, {mat, _Real, 2}},
> >   Sum[
> >    mat[[mx, my]] , {a, 0, 1}]
> >   ]
> >
> > However, a sum within a sum doesn't compile:
> >
> > fC2 = Compile[{{mx, _Integer}, {my, _Integer}, {mat, _Real, 2}},
> >   Sum[
> >    Sum[
> >     mat[[mx, my]] , {a, 0, 1}],
> >    {b, 1, 1}]
> >   ]
> >
> > which generates the following error message:
> >
> > Compile::noinfo: No information is available for compilation of \!\
> > (\*UnderoverscriptBox[\(\[Sum]\), \(b = 1\), \(1\)]\
> > ((\*UnderoverscriptBox[\(\[Sum]\), \(a = 0\), \(1\)]mat[[mx, my]])\)
> > \). The compiler will use an external evaluation and make assumptions
> > about the return type. >>
> >
> > I am confused as to why the first works, but the second doesn't.
> >
> > Any help would be appreciated.
> >
> > Thanks,
> > Julian Francis.
> 
> What version of Mathematica are you running?  It compiles ok on 8.0.4.
> However, I don't understand why you're not summing over the indices of
> the matrix.
> Also, you don't need to nest Sum, you can put both indices inside one
> sum

The reason this doesn't give a message in 8.0.4 is that Compile::noinfo is turned off by default.  The expression is still being computed using a standard evaluation (rather than the virtual machine), as you can see with CompilePrint[fC2].

I'm not sure why the nested Sum doesn't compile, but as Frank mentioned, a single Sum with two ranges does work.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web