3
$\begingroup$

What is the cause of this error?

Compile[{{r, _Integer, 2}, {d, _Integer, 2}},
  pos = Position[MapThread[#1 > #2 &, {r, d}, 2], x_ /; x == True]]

Compile::cplist: MapThread[#1 > #2&, {r, d}, 2] should be a tensor of type Integer, Real, or Complex; evaluation will use the uncompiled function. >>

$\endgroup$
7
  • 6
    $\begingroup$ The error message tells you: the virtual machine does not support registers of tensor boolean type. See this related question. $\endgroup$ Commented Jan 9, 2016 at 21:11
  • $\begingroup$ Thanks @OleksandrR. I will trying it without MapThread, and threading it by a loop. $\endgroup$
    – jack cilba
    Commented Jan 10, 2016 at 5:54
  • 1
    $\begingroup$ Whichever method you attempt to use to produce a boolean list will fail in the VM, unfortunately, since this simply does not exist as a type. Perhaps, as in the linked question, you could produce a list of 1s and 0s instead of Trues and Falses? $\endgroup$ Commented Jan 10, 2016 at 9:32
  • $\begingroup$ Yes actually I have problem yet, there is some problem with ">" Greater , Also. @OleksandrR. MapThread is not the core of problem, I used it with Compile before. $\endgroup$
    – jack cilba
    Commented Jan 10, 2016 at 11:31
  • 1
    $\begingroup$ I know. Seriously, please read the linked thread in detail. It discusses the very same problem as you're facing, and Andy Ross's answer tells you what to do about it. $\endgroup$ Commented Jan 10, 2016 at 11:53

1 Answer 1

0
$\begingroup$
Compile[{{r, _Integer, 2}, {d, _Integer, 2}},
 a = Position[Sign@MapThread[#1 - #2 &, {r, d}], 1]
 ]
$\endgroup$
2
  • $\begingroup$ when there is some error from using map in compile, with adding IntegerPart@ to the list that will be map, the error will not occur again. but why? $\endgroup$
    – jack cilba
    Commented Jan 11, 2016 at 21:41
  • $\begingroup$ Regarding your comment, probably the compiler cannot tell what type the list will be and is expecting an Integer array. You can often fix this by using a third argument in Compile; see the documentation for details. Post a new question with a minimal self-contained example if you need help. $\endgroup$
    – Mr.Wizard
    Commented Feb 3, 2016 at 12:40

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