After discovering that MapIndexed cannot be used with compile (see MapIndexed and Compile) I am now trying do implement similar functionality using a combination of MapThread and Map. Unfortunately I am running into problems even when only using MapThread.
Here is a test-scenario:
Create Lists first:
A = {{1, 2}, {2, 3}};
B = {{{1, 2, 3}, {2, 3, 4}}, {{2, 3, 4}, {3, 4, 5}}};
The I simply run MapThread with function List[] to obtain a suitable combination of those lists and put the whole thing inside a Compile-statement:
test = Compile[{{B, _Real, 3}, {A, _Real, 2}}, MapThread[List[#1, #2, #3] &, {B, A, A}, 2]];
But when running test[B,A] I get the following compile error:
CompiledFunction::cfex: Could not complete external evaluation at instruction 15; proceeding with uncompiled evaluation.
When using CompilePrint[test] instruction 15 shows a call to MainEvaluate.
Unfortunately I currently have no clue how to fix that problem. Any hint is appreciated.
Answer
Incorporating the comments into an answer:
I don't think you are allowed to have lists of that irregular shape, i.e.
{{1, 2, 3}, 1, 1}. Note that it works as expected withPlus[#1,#2,#3]&. See for instanceCompile[{}, Block[{a = {1, 2}, b = 3}, {a, b}]][]– ssch Oct 15 '13 at 14:20indeed, Compile only works with rectangular arrays of consistent type -- because otherwise they cannot be packed. Arrays in Compile are packed arrays, and ragged arrays destroy packing, and hence, compilation. – Andreas Lauschke Oct 15 '13 at 14:39
Comments
Post a Comment