Subject: code for the transpose of a list of lists.
From: Barton Willis
Date: Mon, 28 Jun 2010 22:27:14 -0500
Pedro,
Thanks for this contribution. Using GCL and testing with a 600 x 600 matrix shows that
the speeds are about the same; first my code
(%i2) compile_file("transpose_bw.lisp")$
(%i3) load(second(%))$
(%i4) m : genmatrix(lambda([i,j],i), 600,600)$
Evaluation took 3.6700 seconds (3.6700 elapsed)
(%i5) transpose(m)$
Evaluation took 0.2100 seconds (0.2100 elapsed)
Second, your code:
(%i6) compile_file("transpose_pg.lisp")$
(%i7) load(second(%))$
(%i8) transpose(m)$
Evaluation took 0.2800 seconds (0.2800 elapsed)
Possibly your code is faster for nonsquare matrices or faster for some other compiler?
Because I don't read loop code, it's difficult for me to guess when your code is faster.
Also I'd guess that converting your code to be nondestructive would slow it somewhat.
--Barton
-----maxima-bounces at math.utexas.edu wrote: -----
>To:?maxima at math.utexas.edu
>From:?Pedro?Garrido?gomez?<perogarridogomez at yahoo.es>
>Sent?by:?maxima-bounces at math.utexas.edu
>Date:?06/28/2010?05:22PM
>Subject:?[Maxima]?code?for?the?transpose?of?a?list?of?lists.
>
>This?is?the?code?for?a?version?of?transpose,?this?one?is?destructive,?so
>?perhaps?should?be?called?transpose!.
>?
>?This?version?is?about?
>seven?time?faster?than?the?version?in?maxima?list.
>
>?Yours?
>sincerely,?Pero?Garrido
>?
>
>???(defun?transpose(m)
>??(let?(m1)
>????
>(setq?m1?(loop?for?x?on?(car?m)?collect?x))
>????(transposeaux?m)
>???
>?m1))
>?????????
>(defun?transposeaux(ll)
>??(let?(next)
>????
>(loop?for?l1?in?ll
>???????for?l2
>?in?(cdr?ll)?do
>???????(loop?for?ai?=?l1?then?next?
>??????????for?
>bi?on?l2?do
>????????(setf?next?(cdr
>?ai))
>????????(rplacd?ai?bi))
>?????finally?
>???????(loop?for?bi
>?=?l2?then?next?
>????????while?(cdr?bi)?do
>????????(setf?next?(cdr
>?bi)
>??????????????(cdr?bi)?nil)))?????????
>????ll))
>
>(defmacro
>?tra(m)
>??`(setq?,m?(transpose?,m)))
>
>
>
>
>
>??????_______________________________________________
>Maxima?mailing?list
>Maxima at math.utexas.edu
>http://www.math.utexas.edu/mailman/listinfo/maxima