This may be stupid and lead nowhere, but have you tried

        (declaim (ftype (function () double-float) one-normal-rand))

        (defun one-normal-rand () ...)

?

Cheers

Marco

On Dec 14, 2004, at 4:30 PM, Harvey J. Stein wrote:

>
>
> Thomas Fischbacher <[EMAIL PROTECTED]> writes:
>
>> On Tue, 14 Dec 2004, Harvey J. Stein wrote:
>>
>>> The compiler won't unbox the result of (one-normal-rand) and
>>> (callpay), and I still don't know why.
>>
>> Hm, first of all, I suppose you should get lots of
>>
>>  Unable to optimize due to type uncertainty
>>
>> compiler notes. If so, you should provide the compiler with the
>> proper additional type information. Macros will help. Besides this, 
>> you
>> may think of making one-normal-rand
>>
>>
>> (defun one-normal-rand ()
>>   (declare (values (double-float)))
>>   (labels ((onr ()
>>           (let* ((u (random 1d0))
>>                  (u1 (random 1d0)))
>>             (declare (type (double-float (0d0) 1d0) u u1))
>>             (let* ((v (* SQRT2OVERE (- (* 2d0  u1) 1d0)))
>>                    (x (/ v u))
>>                    (y (/ (* x x) 4d0)))
>>               (if (and (> y (- 1d0 u))
>>                        (> y (- (log u))))
>>                   (onr)
>>                   x)))))
>>     (onr)))
>>
>> so that you can let the compiler inline it. And besides that, there
>> furthermore would be block compilation.
>
> When I compile this snippet, preceeded by:
>
>    (eval-when (compile)
>      (proclaim '(optimize (speed 3) (safety 1) (space 0) (debug 0))))
>
>    (defconstant SQRT2OVERE (the double-float (sqrt (/ 2d0 (exp 1d0)))))
>
>    (eval-when (compile)
>      (proclaim '(type double-float SQRT2OVERE)))
>
> I get a compilation note:
>
>    * (compile-file "bsmc-cl-t2")
>
>    Python version 1.0, VM version Intel x86 on 14 DEC 04 01:38:37 pm.
>    Compiling: /home/hjstein/Quadrus/bsmc-cl-t2.lisp 14 DEC 04 01:38:35 
> pm
>
>    Converted ONE-NORMAL-RAND.
>    Compiling DEFUN ONE-NORMAL-RAND:
>
>    File: /home/hjstein/Quadrus/bsmc-cl-t2.lisp
>
>    In: DEFUN ONE-NORMAL-RAND
>      (DEFUN ONE-NORMAL-RAND ()
>        (DECLARE (VALUES #))
>        (LABELS (#)
>          (ONR)))
>    Note: Doing float to pointer coercion (cost 13) to "<return value>".
>
> I don't know if this is faster or not, but it doesn't clear up the
> cost 13 coercion to pointer note.  BTW, neither does replacing the
> recursion with iteration.  And, using inlining & block compilation
> doesn't help much either.
>
> -- 
> Harvey Stein
> Bloomberg LP
> [EMAIL PROTECTED]
>
>
--
Marco Antoniotti                                        
http://bioinformatics.nyu.edu
NYU Courant Bioinformatics Group                tel. +1 - 212 - 998 3488
715 Broadway 10th FL                            fax. +1 - 212 - 998 3484
New York, NY, 10003, U.S.A.

Reply via email to