Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
2  
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 with Plus[#1,#2,#3]&. See for instance Compile[{}, Block[{a = {1, 2}, b = 3}, {a, b}]][] –  ssch Oct 15 '13 at 14:20
3  
indeed, 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

1 Answer 1

up vote 1 down vote accepted

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 with Plus[#1,#2,#3]&. See for instance Compile[{}, Block[{a = {1, 2}, b = 3}, {a, b}]][]ssch Oct 15 '13 at 14:20

indeed, 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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.