Message Boards Message Boards

0
|
9272 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

Compiled expression with mixed types not working

Posted 10 years ago

I have some sample code:

data1 = {{1, 2, 9}, {4, 5, 6}, {2, 5, 6}};
data2 = {{1, 2, "bob"}, {4, 5, 6}, {2, 5, 6}};
testfn1 = Compile[{{n, _Integer}}, Select[data1, #[[2]] == n &]]
testfn2 = Compile[{{n, _Integer}}, Select[data2, #[[2]] == n &]]

The only difference between data1 and data2 is that the latter has a string element "bob". testfn1 and testfn2 simply splice the matrix.

In[904]:= testfn1[5]

Out[904]= {{4, 5, 6}, {2, 5, 6}}

The above code works fine. However:

In[905]:= testfn2[5]

During evaluation of In[905]:= CompiledFunction::cfte: Compiled expression {{1,2,bob},{4,5,6},{2,5,6}} should be a rank 2 tensor of machine-size real numbers. >>

During evaluation of In[905]:= CompiledFunction::cfex: Could not complete external evaluation at instruction 3; proceeding with uncompiled evaluation. >>

Out[905]= {{4, 5, 6}, {2, 5, 6}}

Why does data2 have to only have Real elements?

Thanks!

POSTED BY: Priyan Fernando

Vector and tensor arguments to compiled functions need to all be a single type.

POSTED BY: Frank Kampas
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