Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Compile Problem with Nested Sum

24 views
Skip to first unread message

Julian Francis

unread,
Dec 13, 2011, 5:41:42 AM12/13/11
to
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.

Frank K

unread,
Dec 19, 2011, 7:19:56 AM12/19/11
to
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

Szabolcs

unread,
Dec 20, 2011, 3:10:09 AM12/20/11
to

On Monday, 19 December 2011 13:19:56 UTC+1, Frank K wrote:
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.

0 new messages