[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: speed up for array ops

>I discovered that converting the whole array to a list was worth the
>extra expense:
>(defun a-to-list (a)
>  "makes a list out of any array"
>  (coerce 
>   (make-array (array-total-size a)
>               :displaced-to a
>               :element-type (array-element-type a))
>   'list))
>(defun listlim (numlist)
>  "Returns the maximum and minimum values of a list of complex numbers."
>  (let* ((amax (abs (first numlist)))
>         (amin amax))
>    (mapc #'(lambda (z)
>              (setq z (abs z))
>              (cond ((> z amax) (setq amax z))
>                    ((< z amin) (setq amin z)))) 
>          numlist)
>    `((min ,amin)(max ,amax))))
>Does this mean that MCLs AREF is slower than it ought to be?

No. It means that (coerce x 'list) is faster than (dotimes (...) (aref ...)).
AREF needs to do type and bounds checking on each reference. COERCE can
do it once outside the loop. My example showed how to get a simple vector
that was amenable to an in-line non-bounds-checked AREF.