Ramiro
Posts:
26
Registered:
9/18/07
|
|
Re: Help on compiling a function
Posted:
Jan 19, 2011 5:24 AM
|
|
Thanks so much, this was the answer exactly. Just a small clarification:
I have been going through the compiler documenttaion. If I do On[ Compile::noinfo]
I get the following:
example1 = Compile[{{n, _Real, 1}, {a, _Real}, {b, _Real}, {t, _Real, 1}}, Block[{tn = Total[n]}, b^a*Exp[LogGamma[tn + a] - (Total[LogGamma[n + 1]] + LogGamma[a]) + Total[n*Log[t]] - (tn + a)*Log[Total[t] + b]]]]; example1[{97.6203, 8.4788, 21.4204, 46.1755}, 1, 1, {39.9342, 7.5820, 5.8656, 10.0553}] // AbsoluteTiming
Compile::noinfo: No information is available for compilation of LogGamma[Compile`$3]. The compiler will use an external evaluation and make assumptions about the return type. >>
Compile::noinfo: No information is available for compilation of LogGamma[n+1]. The compiler will use an external evaluation and make assumptions about the return type. >>
Compile::noinfo: No information is available for compilation of LogGamma[a]. The compiler will use an external evaluation and make assumptions about the return type. >> {0.000087, 1.06265*10^-11}
But if I add the corresponding information about LogGamma and Total, the function performs a bit slower:
In[109]:= Clear[example1]; example1 = Compile[{{n, _Real, 1}, {a, _Real}, {b, _Real}, {t, _Real, 1}}, Block[{tn = Total[n]}, b^a*Exp[LogGamma[tn + a] - (Total[LogGamma[n + 1]] + LogGamma[a]) + Total[n*Log[t]] - (tn + a)* Log[Total[t] + b]]], {{LogGamma[_], _Real}, {Total[_], _Real}}]; example1[{97.6203, 8.4788, 21.4204, 46.1755}, 1, 1, {39.9342, 7.5820, 5.8656, 10.0553}] // AbsoluteTiming
Out[110]= {0.000141, 1.06265*10^-11}
Why is this?
Thanks to everyone for their help again,
Ramiro
|
|