Matrix transpose in MATRIX high treason

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Matrix transpose in MATRIX high treason

Kirill Orlov
For those using MATRIX. You live and learn.
Transposition of a matrix is so basic operation.
I never knew that transposing a big matrix (not vector) in MATRIX is not as fast as one might hope.

set seed 4987349.
matrix.
comp var= uniform(10000,1).
comp n= nrow(var).
comp m= var*make(1,n,1).
comp x= m-t(m).
*print mssq(x).
end matrix.

set seed 4987349.
matrix.
comp var= uniform(10000,1).
comp n= nrow(var).
comp m1= var*make(1,n,1).
comp m2= make(n,1,1)*t(var).
comp x= m1-m2.
*print mssq(x).
end matrix.

The second piece which computes "t(m)" directly rather than by transposing m, is more than 1.5 times faster. Wow!

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD