line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Array::Transpose; |
2
|
3
|
|
|
3
|
|
78896
|
use strict; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
126
|
|
3
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
123
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
BEGIN { |
6
|
3
|
|
|
3
|
|
17
|
use Exporter (); |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
78
|
|
7
|
3
|
|
|
3
|
|
17
|
use vars qw($VERSION @ISA @EXPORT); |
|
3
|
|
|
|
|
16
|
|
|
3
|
|
|
|
|
448
|
|
8
|
3
|
|
|
3
|
|
6
|
$VERSION = '0.06'; |
9
|
3
|
|
|
|
|
51
|
@ISA = qw(Exporter); |
10
|
3
|
|
|
|
|
6767
|
@EXPORT = qw(transpose); |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Array::Transpose - Transposes a 2-Dimensional Array |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Array::Transpose; |
20
|
|
|
|
|
|
|
@array=transpose(\@array); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use Array::Transpose qw{}; |
23
|
|
|
|
|
|
|
@array=Array::Transpose::transpose(\@array); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Example: |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use Array::Transpose; |
28
|
|
|
|
|
|
|
use Data::Dumper; |
29
|
|
|
|
|
|
|
my $array=transpose([ |
30
|
|
|
|
|
|
|
[ 0 .. 4 ], |
31
|
|
|
|
|
|
|
["a" .. "e"], |
32
|
|
|
|
|
|
|
]); |
33
|
|
|
|
|
|
|
print Data::Dumper->Dump([$array]); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Returns |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$VAR1 = [ |
38
|
|
|
|
|
|
|
[ 0, 'a' ], |
39
|
|
|
|
|
|
|
[ 1, 'b' ], |
40
|
|
|
|
|
|
|
[ 2, 'c' ], |
41
|
|
|
|
|
|
|
[ 3, 'd' ], |
42
|
|
|
|
|
|
|
[ 4, 'e' ] |
43
|
|
|
|
|
|
|
]; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 DESCRIPTION |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
This package exports one function named transpose. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
In linear algebra, the transpose of a matrix A is another matrix A' created by any one of the following equivalent actions: |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=over 2 |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item * |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
write the rows of A as the columns of A' |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item * |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
write the columns of A as the rows of A' |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item * |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
reflect A by its main diagonal (which starts from the top left) to obtain A' |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=back |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 USAGE |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
use Array::Transpose; |
70
|
|
|
|
|
|
|
@array=transpose(\@array); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 METHODS |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 transpose |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Returns a transposed 2-Dimensional Array given a 2-Dimensional Array |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $out=transpose($in); #$in=[[],[],[],...]; |
79
|
|
|
|
|
|
|
my @out=transpose(\@in); #@in=([],[],[],...); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub transpose { |
84
|
7
|
50
|
|
7
|
1
|
144683
|
die("Error: Expecting a single parameter") |
85
|
|
|
|
|
|
|
unless @_ == 1; |
86
|
7
|
|
|
|
|
16
|
my $in=shift; #[[],[],[]] |
87
|
7
|
50
|
|
|
|
36
|
die("Error: Expecting parameter to be an array reference") |
88
|
|
|
|
|
|
|
unless ref($in) eq "ARRAY"; |
89
|
7
|
|
|
|
|
19
|
my @out=(); |
90
|
7
|
100
|
|
|
|
34
|
if (@$in > 0) { |
91
|
5
|
|
50
|
|
|
10
|
my $cols=scalar(@{$in->[0]}) || 0; |
92
|
5
|
|
|
|
|
24
|
foreach my $col (0 .. $cols-1) { |
93
|
500016
|
|
|
|
|
618267
|
push @out, [map {$_->[$col]} @$in]; |
|
500056
|
|
|
|
|
1326377
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
7
|
100
|
|
|
|
50
|
return wantarray ? @out : \@out |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 LIMITATIONS |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
The transpose function assumes all rows have the same number of columns as the first row. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 BUGS |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Please log on RT and send an email to the author. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SUPPORT |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
DavisNetworks.com supports all Perl applications including this package. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 AUTHOR |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Michael R. Davis |
114
|
|
|
|
|
|
|
CPAN ID: MRDVT |
115
|
|
|
|
|
|
|
STOP, LLC |
116
|
|
|
|
|
|
|
domain=>stopllc,tld=>com,account=>mdavis |
117
|
|
|
|
|
|
|
http://www.stopllc.com/ |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 COPYRIGHT |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This program is free software licensed under the... |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
The BSD License |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
The full text of the license can be found in the LICENSE file included with this module. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 SEE ALSO |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 Similar Capabilities |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
L method transpose, L rotate method |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 Packages built on top of this package |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
L |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |