Re: Optimizing simple Common Lisp gibbs sampler program
Faheem Mitha <faheem@email.unc.edu> writes:
> (defun gibbs (N thin)
> (declare (fixnum N thin))
> (declare (optimize (speed 3) (safety 1)))
> (let ((x 0.0) (y 0.0))
> (declare ((double-float 0.0 *) x))
> (declare (double-float y))
> (print "Iter x y")
> (dotimes (i N)
> (dotimes (j thin)
> (declare (fixnum i j))
> (setf x (cl-rmath::rgamma 3.0 (/ 1.0 (+ (* y y) 4))))
> (setf y (cl-rmath::rnorm (/ 1.0 (+ x 1.0)) (/ 1.0 (sqrt (+ (* 2 x) 2))))))
> (format t "~a ~a ~a~%" i x y))))
^^^^^^
I didn't check it, but isn't the performance of this code completely
output-dominated?
Nicolas
P.S.: Your reasoning about the problems of C++/Python and similar
couplings was also what lead me to CL. Maybe I'll expand this later.
|