I have defined the following function:
g = Compile[{{x0, _Real}},
sol = NSolve[
Rationalize[CDF[ExponentialDistribution[1], x] == x0, 10^-10],
{x}, Reals];
sol]
Running g[0.5]
it fails with:
In[460]:= g[0.5]
During evaluation of In[460]:= CompiledFunction::cfse: Compiled expression {{x->0.693147}} should be a machine-size integer. >>
During evaluation of In[460]:= CompiledFunction::cfex: Could not complete external evaluation at instruction 2; proceeding with uncompiled evaluation. >>
Out[460]= {{x -> 0.693147}}
If I try to extract the rhs from the transformation rule with sol[[1,1,2]]
I get the following error:
Compile::part: Part specification sol[[1,1,2]] cannot be compiled since the argument is not a tensor of sufficient rank. Evaluation will use the uncompiled function. >>
Compile::part: Part specification {{x->0.693147}}[[1,1,2]] cannot be compiled since the argument is not a tensor of sufficient rank. Evaluation will use the uncompiled function. >>
How could I let Compile[]
know that I intend to return {{a -> b}}
or how could I extract the rhs of the transformation rule and return that only?
EDIT: It appears that none of my functions (Rationalize[]
, NSolve[]
, ExponentialDistribution[]
) is "compilable" based on this link by @MichaelE2.
Compile
works. $\endgroup$