In a program I'm writing, the closure returned by the following
function is taking essentially all the runtime:

(defun make-cg-multiplier (dataset pointset sigma)
  (declare (type dataset dataset)
           (type pointset pointset)
           (type double-float sigma))
  (let ((s^2 (the double-float (* sigma sigma)))
        (n (the fixnum (veclen pointset))))
    #'(lambda (x)
        (declare (type df-vec x))
        (unless (= (veclen x) n)
          (error "The x vector and the dataset are not the same size."))
        (let ((result-vec (df-array n))
              (result-entry 0.0d0))
          (declare (type double-float result-entry))
          (fixtimes (i1 n)
             (fixfor (i2 i1 n)
                (setf result-entry
                      (the double-float
                        (exp (- (/ (distance (datapoint dataset (aref pointset i1))
                                             (datapoint dataset (aref pointset i2)))
                                   s^2)))))
                (if (= i1 i2)
                    (incf (aref result-vec i1) (* (aref x i1) result-entry))
                    (progn
                      (incf (aref result-vec i2) (* (aref x i1) result-entry))
                      (incf (aref result-vec i1) (* (aref x i2) result-entry))))))
          result-vec))))


When I compile this function (speed 3, safety and debug 0), one of the
compile-time notes is:

;   #'(LAMBDA (X)
;       (DECLARE #)
;       (UNLESS # #)
;       (LET #
;         # ..))
; Note: Doing float to pointer coercion (cost 13), for:
;     The second argument of CLOSURE-INIT.

I don't know what this means.  I'm vaguely guessing from the
description that it's something that only happens once per call of the
closure, in which case it's fine.  But I'd like to know what it is,
and also make 100% sure that it's not in the inner loop.  (I'm
assuming it's not, because distance is declared inline and returns a
double float, s^2 is a double float, so the call to exp should also be
compiled inline, and none of the other compiler notes indicate
anything different.)

Cheers,

rif


Reply via email to