quad_qag slow due to compilation at each step?



On Wed, Mar 12, 2008 at 1:06 PM, dlakelan <dlakelan at street-artists.org> wrote:

>  I don't know whether in this specific case, the overhead of compile is
>  worth it. Any suggestions as to how to deal with this??

I think (without trying it) that it should be faster if you make the
integrand for quad_foo the name of a compiled function
instead of an expression or uncompiled function.

e.g.
f(x) := x^2;
compile (f);
/* now f is a compiled Lisp function */
:lisp (symbol-function '$f)
 => <compiled-function $f> or something
quad_foo (f, x, 0, 1);

I think the Lisp compiler should notice if f is already compiled.
No guarantee, I guess. Also this scheme depends on the
undocumented behavior of COERCE-FLOAT-FUN (to return
#'$f instead of constructing a new Lisp function).

>  Perhaps I just try replacing quad_qag with romberg...

I compared quadpack with romberg in some detail a while ago.
Quadpack is consistently better: greater accuracy with fewer
function evaluations, and succeeds on problems in which
romberg fails. Also quadpack tries to detect problematic
situations and romberg doesn't bother.

>  Is there a way we can provide the user
>  with a mechanism to hand quadpack functions a pre-compiled integrand?

Yeah, that would be good.

FWIW

Robert