in reply to Re^3: An efficient, scalable matrix transformation algorithm
in thread An efficient, scalable matrix transformation algorithm

FWIW, this transpose runs ~3.5 times faster than the loop you had (on my machine, anyway). The message here is that the trick with Perl is to replace a for or while by map or grep if possible !

sub transpose_gmch { my ($matrix) = shift ; my @result = () ; my $lc = $#{$matrix->[0]} ; for my $col (0..$lc) { push @result, [map $_->[$col], @$matrix] ; } ; return( \@result ); }

Replies are listed 'Best First'.
Re^5: An efficient, scalable matrix transformation algorithm
by Luftkissenboot (Novice) on Jan 29, 2009 at 07:37 UTC

    Ah, too much good stuff!

    It seems that the transposition step is unnecessary for this algorithm, anyway, but that is a much better implementation, regardless, and I'll incorporate it for later use. Quite the performance jump that map() provides. Mmm, lispy goodness.

    It might further be worthwhile to pass it on in the RT to the Math::Matrix maintainer as a performance patch, since that's where I took the original function from, also.

    Thank you again, kind and knowledgeable good sir monk.