speeding up linear algebra



I'm not sure what you are really trying to do, but this has a much better
chance of running fast.  Generalizations for other types should be
simple to figure out.  I could run this program, sumit2 taking about
1/3 of the cpu time, and  half the GC time as your original.
Also the total times is more than 100X shorter on my 933 mHz pentium 3
than the times you give.  That is, I could do 10^6 elements in
0.32 sec + 1.6sec GC. for a total of 2 sec

I hope this helps with your linear algebra.



(defun sumit2(typ lst)
  (if (eq typ 'double) (sumit2d lst)))

(defun sumit2d (lst)
  (let ((s 0.0d0))
    (declare (double-float s)(optimize(speed 3)(safety 0)(debug 0)))
    (dolist (j lst s)
          (declare (double-float j))
      (incf s j))))

(defun makeabc(N)(setf abc (loop for i from 1  to (expt 10 N) collect (/ 
1.0d0 i))))



----- Original Message ----- 
From: "Barton Willis" <willisb at unk.edu>
To: <maxima at math.utexas.edu>
Sent: Sunday, January 22, 2006 7:29 AM
Subject: speeding up linear algebra


>
> I was thinking about how to speed up some code in /share/linearalgebra.
> If I could figure out how to make the function 'sumit' (see below)
> faster, I could use the same ideas to speed up linearalgebra.
> My experiments show that 'sumit' runs no faster when it uses doubles
> than when it doesn't.
>
> (The function 'sumit' imitates things that need to be done in
> linearalgebra--the function 'sumit' is just a simplified 'toy'
> function.)
>
> (%i2) load("sumit.o")$
> (%i3) showtime : all$
> Evaluation took 0.00 seconds (0.00 elapsed)
> (%i4) lst : makelist(1.0/k,k,1,10^4)$
>
> (%i5) sumit('double,lst);
> Evaluation took 3.70 seconds (3.70 elapsed)
>
> (%o5) 9.7876060360443446
> (%i6) sumit('abc,lst);
> Evaluation took 3.77 seconds (3.77 elapsed)
> (%o6) 9.7876060360443446
>
> ---file sumit.lisp-------
> (defun $sumit (typ lst)
>  (let* ((n ($length lst)) (acc 0)
>  (a (if (eq typ '$double)
>  (make-array  n :element-type 'double-float :initial-contents (cdr lst))
>       (make-array n :initial-contents (cdr lst)))))
>    (flet ((fadd (x y) (if (eq typ '$double) (+ x y) (add x y))))
>      (decf n)
>      (loop for i from 0 to n do
> (setq acc (fadd acc (aref a i)))))
>    acc))
> ------------------------
> Barton
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>