2
$\begingroup$

I'm unsuccessfully trying to compile this function

check[argA_, argB_] := argA[[1]] == argB[[1]];

assuming that both arguments argA and argB are of the form

{Real, String, ....}

Neither

cf = Compile[
{
{x, {_Real, _String}, 1},
{y, {_Real, _String}, 1}
},
x[[1]] == y[[1]]
];

nor

cf = Compile[
{
{x, {_Real, _String}, {1}},
{y, {_Real, _String}, {1}}
},
x[[1]] == y[[1]]
];

work as expected, and I can't see the underlying rule. I'm grateful for any explaination.

$\endgroup$
  • 2
    $\begingroup$ Can't mix types like that directly (from the docs: "assumes that Subscript[x, i] is a rank Subscript[n, i] array of objects, each of a type that matches Subscript[t, i]. " (emphasis mine). $\endgroup$ – ciao Apr 27 '14 at 21:26
  • 5
    $\begingroup$ Strings cannot be compiled. $\endgroup$ – RunnyKine Apr 27 '14 at 21:27
  • $\begingroup$ Related question: mathematica.stackexchange.com/questions/57355/… $\endgroup$ – dr.blochwave May 19 '15 at 21:35
  • $\begingroup$ You could convert input strings to integers and convert them back to strings in the output of the compiled function, if the strings are not supposed to change in the program. $\endgroup$ – faysou May 19 '15 at 22:00
4
$\begingroup$

As @RunnyKine comments, String arguments cannot be compiled. From the documentation:

The types handled by Compile are:

  • _Integer machine‐size integer
  • _Real machine‐precision approximate real number (default)
  • _Complex machine‐precision approximate complex number
  • True | False logical variable
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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