Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.4K Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Compilation of IntegerPartitions

Posted 1 year ago

I need to compile a function to render it as fast as possible because it is used recurrently. Inside this function I use IntegerPartitions. However, it seems impossible to correctly compile code using IntegerPartitions. For instance, for the following test code

F = Compile[{{k, _Integer}, {d, _Integer}, {s, _Integer}}, Block[{ls},
   ls = IntegerPartitions[s, {k}, Range[d]];
   Return[ls]],
  CompilationTarget -> "C"]

the answer is "Compiled expression {{3,1,1},{2,2,1}} should be a rank 1 tensor of machine-size integers" when F[3,7,5] is executed, whether the CompilationTarget is C or WVM. However, with ls={{3,1,1},{2,2,1}} it is executed flawlessly. Has anyone an idea what is the reason for this oddity?

POSTED BY: Ulrich Utiger
2 Replies
Posted 1 year ago
POSTED BY: Ulrich Utiger

I know nothing about compiling, but the following

F = Compile[{{k, _Integer}, {d, _Integer}, {s, _Integer}}, 
  IntegerPartitions[s, {k}, Range[d]]]
With[{s = 8, k = 4, d = 5}, IntegerPartitions[s, {k}, Range[d]]]
With[{s = 8, k = 4, d = 5}, F[k, d, s]]

gives the message "Could not complete external evaluation at instruction 9; proceeding with uncompiled evaluation". Maybe IntegerPartitions cannot be compiled.

What is the purpose of Block in your code?

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