Group Abstract Group Abstract

Message Boards Message Boards

0
|
13K Views
|
11 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Compile on lists?

Posted 11 years ago
POSTED BY: Miguel Olivo-V
11 Replies
Posted 11 years ago
POSTED BY: Miguel Olivo-V
POSTED BY: Ivan Morozov
Posted 11 years ago

Is it possible save the compiled function so that I can use it later without having to recompile it again?

What if the function is compiled to C and I wanted to run it in another computer?

POSTED BY: Miguel Olivo-V
POSTED BY: Frank Kampas
Posted 11 years ago
POSTED BY: Miguel Olivo-V

Hi,

If I do that, it keeps evaluating the cell forever...

Same for me. Miguel, try this:

<< CompiledFunctionTools` ;
P = \[CapitalPi][X];
f2 = Compile[{{m, _Real, 1}}, Log[Exp[P + \[Beta] F1.m] + Exp[\[Beta] F0.m]]]
f3 = Compile[{{m, _Real, 1}}, Log[Exp[P + \[Beta] F1.m] + Exp[\[Beta] F0.m]], CompilationOptions -> {"InlineExternalDefinitions" -> True}]
StringFreeQ[CompilePrint[f2], "MainEvaluate"]
StringFreeQ[CompilePrint[f3], "MainEvaluate"]

Also, take a look at http://mathematica.stackexchange.com/questions/1803/how-to-compile-effectively

I.M.

POSTED BY: Ivan Morozov
POSTED BY: Frank Kampas

You have functions in your Compile statement which are defined outside it. At the least, you need to wrap the argument of Compile with Evaluate since Compile is HoldAll.

POSTED BY: Frank Kampas
Posted 11 years ago

If I do that, it keeps evaluating the cell forever...

POSTED BY: Miguel Olivo-V
Posted 11 years ago

Thank you, I didn't notice that in the documentation when I was reading it.

However, I get inconsistent results when using the function. See attached notebook. Basically, it gives me an error the first few times that I try to use the compiled function, but after a few calls, it behaves as expected. What could be happening?

Attachments:
POSTED BY: Miguel Olivo-V
f = Compile[{{m, _Real, 2}, {v, _Real, 1}}, m.v]
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