I don't know how to fix this problem:
In[175]:= test = Compile[{{x, _Real}}, If[Sin[x] > 0.1, Tan[x], 0]];
FindMinimum[test[x], {x, 1.}, WorkingPrecision -> MachinePrecision]
During evaluation of In[175]:= CompiledFunction::cfsa: Argument x at position 1 should be a machine-size real number. >>
Out[176]= {0., {x -> -1.02705}}
I understand why it's complaining. But I need to use compile as my function has many lines with all sorts of comditionals. Speed is important. Stuck with this optimization step of FindMinimum
. Any idea how to fix it without derailing up Compile
?
If
is missing, which is forcing Mathematica to resort to non-compiled evaluation to handle it. To understand why, consider what would happen ifSin[x] < 0.1
. Search this site forCompilePrint
to see how to diagnose the problem. Use something likeIf[Sin[x] > 0.1, Tan[x], 0]
to fix it. $\endgroup$test
takes a non-trivial amount of time uncompiled. But actually: you don't need to create an additional function. You can just ignore the error. It won't affect the result. $\endgroup$