Message Boards Message Boards

1
|
6971 Views
|
3 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Why my Mathematica 12.0 cannot find a definition for Sum in compiling

Posted 4 years ago

I think I have found some very interesting things when I am trying to accelerate a function using "FunctionCompile".

  1. The list iterator like "i", "j" in build-in function Sum cannot be recognized as local variables by "FunctionCompile". You have to define it ahead and then use it. It may not be a problem, as it is a tradition in other low-level languages like C. But it confused me a little and it is quite different from wolfram language usages. See the following codes for example.

    FunctionCompile[Function[Typed[arg,"Real64"],Sum[arg^2+i, {i, 10}]]]
    

the above code gives an error "Cannot find a definition for i".

  1. A dramatic thing happened when I try to fix this problem. Adding the definition of the iterator "i", it gives me an error "TypeError. Cannot find a definition for Sum."

    FunctionCompile[Function[{Typed[arg,"Real64"],Typed[i,"Real64"]},Sum[arg^2+i, {i, 10}]]]
    

I think that is very interesting. Although the function Sum can be replaced by other functions like Total in some time, it is still a frequently used function in many programs. Other build-in function like Table, Power, Gamma or even Pochhammer and LaguerreL seems allright.

I hope it is an exception and can be fixed by a simple upgrade, or reload.

POSTED BY: Han Wu
3 Replies

Update in May, 3th, 2020.

Many thanks to Nicholas and Volker.

I test the same code in Mathematica 12.1 and it works. But it fails when replacing "Sum" to "NSum".

After confirming this problem with my friend in Wolfram, it is true a compatibility problem in "FunctionCompile". Hopes it can be fixed in 12.2.

POSTED BY: Han Wu

I find an identical behaviour as Han Wu with my Mathematica 12.0.

I don’t have this issue using 12.1 in the cloud

In[1]:= myFunc=FunctionCompile[Function[Typed[arg,"Real64"],Sum[arg^2+i, {i, 10}]]];
myFunc[18.]

Out[2]= 3295.

Perhaps it’s a bug or issue with your installation?

I do get this behaviour when using NSum—it looks like that is not compilable. Perhaps there is something you are doing with your sum that forces it to remain unevaluated or use NSum?

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract