Subject: matrix transpose (was Re: mini / maxi functions)
From: Mario Rodriguez
Date: Mon, 28 Jun 2010 08:10:10 +0200
Barton Willis escribi?:
> For a n x n matrix, the running time for transpose is O(n^3). Here is a proposed O(n^2) replacement:
>
> ;; Transpose a list of lists ll and return a list of lists. Example:
> ;; ((1 2) (3 4)) --> ((1 3) (2 4)).
>
> (defun transpose (ll)
> (let ((acc nil))
> (while (car ll)
> (push (mapcar #'car ll) acc)
> (setq ll (mapcar #'cdr ll)))
> (nreverse acc)))
>
> To transpose the 800 x 800 matrix (i,j) --> i - j:
>
> current transpose: 26.21 seconds
> proposed transpose: 0.80 seconds.
>
> Matrix multiplication also uses transpose.
>
> Comments?
>
I am in favor of this improvement. Big matrices are common in data
analysis and hard to handle with the descriptive package. Function
transpose is called frequently inside package descriptive.
--
Mario