Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: Help on compiling a function
Replies: 6   Last Post: Jan 19, 2011 5:24 AM

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 Ramiro Posts: 26 Registered: 9/18/07
Re: Help on compiling a function
Posted: Jan 19, 2011 5:24 AM
 Plain Text Reply

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

Date Subject Author
1/16/11 Ramiro
1/17/11 Daniel Lichtblau
1/17/11 sjoerd.c.devries@gmail.com
1/17/11 sjoerd.c.devries@gmail.com
1/17/11 Peter Pein
1/19/11 Ramiro
1/18/11 ramiro

© The Math Forum at NCTM 1994-2017. All Rights Reserved.