Message Boards Message Boards

0
|
2872 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Compile Subexpression Type specification for a List type?

The example in the documentation is for a subexpression that returns an integer:

In[24]:= com[i_] := Binomial[2 i, i]

In[26]:= t1 = 
 Compile[{x, {i, _Integer}}, x^com[i], {{com[_], _Integer}}]

What do I do if my subexpression returns a List of Integers? Replacing Integer with {Integer,1} gives an error message: Invalid type or rank specification.

POSTED BY: Frank Kampas
2 Replies
Posted 9 years ago

Hi Frank, a simple example worked for me. How do you get the error?

In[1]:= returnList[i_] := {i, 2 i, 3 i}

In[2]:= t3 = 
  Compile[{{x, _Real}, {k, _Integer}}, 
   x returnList[k], {{returnList[_], _Integer, 1}}];

In[3]:= t3[2.3, 2]

Out[3]= {4.6, 9.2, 13.8}
POSTED BY: David Keith

I tried to do it with an extra set of brackets around _Integer and 1. I see that what you did is the way the inputs are specified, which makes more sense.

Thanks

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