>>>>> "rif" == rif <[EMAIL PROTECTED]> writes:
rif> I'm trying to optimize the following function (yes, profiling
rif> indicates that this function is the bottleneck, it's taking the lion's
rif> share of the time and the consing).
rif> (defun find-closest-index (point centers)
rif> (declare (type simple-array centers)
rif> (type (simple-array double-float) point))
Presumably point is really a 1-D array, not of unknown dimensions. If
so, declaring it as such will help a lot.
rif> (let ((best-dist most-positive-double-float)
rif> (dist 0.0d0)
rif> (index -1))
rif> (declare (type fixnum index)
rif> (type double-float best-dist)
rif> (type double-float dist))
rif> (fixtimes (i (array-dimension centers 0))
rif> (let ((c (aref centers i)))
rif> (declare (type (simple-array double-float) c))
Presumably, c is now a 1-D double-float array, now. Same comments as
for point, above.
rif> (setf dist (the double-float (l2-distance-squared point c)))
Could you also supply l2-distance-squared function?
rif> (when (< dist best-dist)
rif> (progn
rif> (setf index i)
rif> (setf best-dist dist)))))
rif> index))
rif> One of the compiler notes (settings were speed 3, debug and safety 0)
rif> for this function is:
rif> ; (SETF BEST-DIST DIST)
rif> ; ==>
rif> ; (SETQ BEST-DIST DIST)
rif> ; Note: Doing float to pointer coercion (cost 13) from DIST to BEST-DIST.
rif> And I cannot for the life of me figure out why I'm getting this. Any
rif> ideas?
Not sure, but sometimes I've noticed that the x86 port runs out of FP
registers or something so things get boxed that I didn't expect.
Never tracked this down. I don't think this happens on sparc in this
case, but I'm not sure.
Ray