I'm trying to optimize the following function (yes, profiling
indicates that this function is the bottleneck, it's taking the lion's
share of the time and the consing).
(defun find-closest-index (point centers)
(declare (type simple-array centers)
(type (simple-array double-float) point))
(let ((best-dist most-positive-double-float)
(dist 0.0d0)
(index -1))
(declare (type fixnum index)
(type double-float best-dist)
(type double-float dist))
(fixtimes (i (array-dimension centers 0))
(let ((c (aref centers i)))
(declare (type (simple-array double-float) c))
(setf dist (the double-float (l2-distance-squared point c)))
(when (< dist best-dist)
(progn
(setf index i)
(setf best-dist dist)))))
index))
One of the compiler notes (settings were speed 3, debug and safety 0)
for this function is:
; (SETF BEST-DIST DIST)
; ==>
; (SETQ BEST-DIST DIST)
; Note: Doing float to pointer coercion (cost 13) from DIST to BEST-DIST.
And I cannot for the life of me figure out why I'm getting this. Any
ideas?
Cheers,
rif
ps. Yes, I know that not all of the current type declarations are
necessary. I'm still in the "better safe than sorry" stage of
debugging. Once I can get that pesky conversion gone, I'll figure out
which other type declarations are unnecessary.