Group Abstract Group Abstract

Message Boards Message Boards

Compile a function and produce C code version of it?

Posted 7 years ago
Attachments:
POSTED BY: Jamie Dixson
2 Replies

Jamie,

You can easily turn your code into a multiline function:

myfunction[s1_, s2_, distfunc_, band_] := 
 Module[{xcorrs1, xcorrs2, d1, d2, dist}, {xcorrs1, xcorrs2} = 
   CanonicalWarpingCorrespondence[s1, s2, 
    Automatic, {"SlantedBand", band}, 
    Method -> {"MatchingInterval" -> Automatic}, 
    DistanceFunction -> distfunc]; d1 = Part[s1, xcorrs1]; 
  d2 = Part[s2, xcorrs2]; 
  dist = CanonicalWarpingDistance[s1, s2, 
    Automatic, {"SlantedBand", band}, 
    Method -> {"MatchingInterval" -> Automatic}, 
    DistanceFunction -> distfunc]; {dist, d1, d2}]

However, this will not help you compile it. The compiler will not support functions such as CanonicalWarpingDistance and CanonicalWarpingCorrespondence. In Version 12 they announced that they will enable compiling of functions like this, however, I have no idea when they will add support for those two functions. At the Wolfram conference 2018 they announced that you will be able to do this. I would ask technical support for a timetable (and a V12 release date). I assume that you would need to have your C code either link to a MMA library or communicate with a running kernel to do built-in functions like that.

One other option is to recode those two routines using elemental functions and then compile it with the new compiler when it is released. The existing compiler is very limited.

Regards,

Neil

POSTED BY: Neil Singer
Posted 7 years ago

Thank you Neil. I was afraid that might be the case. At one point I was successful in compiling the function after turning it into a module similar to what you have shown but when I tried to compile it, there was an error that said that it was successfully compiled but that it would produce some error if I tried to run it outside of Mathematica. I gave up on trying to compile as a module at that point. I will check with tech support on the release date for V12 and if CWC and CWD will be include in the initial release or when they will be added. Thank you again.

POSTED BY: Jamie Dixson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard