line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
sub sapply {
|
4
|
|
|
|
|
|
|
|
5
|
1110
|
|
|
1110
|
1
|
3217
|
check_prototype(@_, '\@\&');
|
6
|
|
|
|
|
|
|
|
7
|
1110
|
|
|
|
|
1855
|
my $array = shift;
|
8
|
1110
|
|
|
|
|
1463
|
my $function = shift;
|
9
|
|
|
|
|
|
|
|
10
|
1110
|
|
|
|
|
1570
|
my $sapply = [];
|
11
|
1110
|
|
|
|
|
2185
|
@$sapply = map { my $scalar = $function->($_);
|
|
3004
|
|
|
|
|
6037
|
|
12
|
3004
|
|
|
|
|
7412
|
$scalar;
|
13
|
|
|
|
|
|
|
} @$array;
|
14
|
|
|
|
|
|
|
|
15
|
1110
|
|
|
|
|
3019
|
return $sapply;
|
16
|
|
|
|
|
|
|
}
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub mapply {
|
20
|
|
|
|
|
|
|
|
21
|
77
|
|
|
77
|
1
|
339
|
check_prototype(@_, '(\@|$)+\&');
|
22
|
|
|
|
|
|
|
|
23
|
77
|
|
|
|
|
191
|
my $function = pop; # the last argument
|
24
|
77
|
|
|
|
|
279
|
my @array = @_;
|
25
|
|
|
|
|
|
|
|
26
|
77
|
|
|
|
|
250
|
for (0..$#array) {
|
27
|
154
|
100
|
|
|
|
475
|
if(! is_array_ref($array[$_])) {
|
28
|
16
|
|
|
|
|
73
|
$array[$_] = [$array[$_]];
|
29
|
|
|
|
|
|
|
}
|
30
|
|
|
|
|
|
|
}
|
31
|
|
|
|
|
|
|
|
32
|
77
|
|
|
|
|
381
|
my $length = sapply(\@array, \&len);
|
33
|
77
|
|
|
|
|
338
|
my $max_length = max($length);
|
34
|
|
|
|
|
|
|
|
35
|
77
|
|
|
154
|
|
779
|
my $check_length = sapply($length, sub {$max_length % $_[0] != 0});
|
|
154
|
|
|
|
|
434
|
|
36
|
77
|
50
|
|
|
|
420
|
if(sum($check_length)) {
|
37
|
0
|
|
|
|
|
0
|
croak "ERROR: Longer object length is not a multiple of shorter object length.";
|
38
|
|
|
|
|
|
|
}
|
39
|
|
|
|
|
|
|
|
40
|
77
|
|
|
154
|
|
110
|
@array = @{ sapply(\@array, sub{_cycle($_[0], $max_length)}) };
|
|
77
|
|
|
|
|
390
|
|
|
154
|
|
|
|
|
376
|
|
41
|
|
|
|
|
|
|
|
42
|
77
|
|
|
|
|
373
|
my $mapply = [];
|
43
|
77
|
|
|
|
|
260
|
for my $i (0..($max_length-1)) {
|
44
|
561
|
|
|
1105
|
|
2169
|
my $param = sapply(\@array, sub {$_[0]->[$i]});
|
|
1105
|
|
|
|
|
1966
|
|
45
|
561
|
|
|
|
|
1434
|
$mapply->[$i] = do { my $scalar = $function->(@$param);
|
|
561
|
|
|
|
|
1459
|
|
46
|
561
|
|
|
|
|
1840
|
$scalar; };
|
47
|
|
|
|
|
|
|
}
|
48
|
|
|
|
|
|
|
|
49
|
77
|
|
|
|
|
387
|
return $mapply;
|
50
|
|
|
|
|
|
|
}
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _cycle {
|
54
|
154
|
|
|
154
|
|
212
|
my $array = shift;
|
55
|
154
|
|
33
|
|
|
359
|
my $size = shift || len($array);
|
56
|
154
|
|
|
|
|
405
|
my $scalar = len($array);
|
57
|
|
|
|
|
|
|
|
58
|
154
|
100
|
|
|
|
397
|
if($size == $scalar) {
|
|
|
50
|
|
|
|
|
|
59
|
138
|
|
|
|
|
285
|
return $array;
|
60
|
|
|
|
|
|
|
}
|
61
|
|
|
|
|
|
|
elsif($size < $scalar) {
|
62
|
0
|
|
|
|
|
0
|
$size --;
|
63
|
0
|
|
|
|
|
0
|
return subset($array, [0..$size]);
|
64
|
|
|
|
|
|
|
}
|
65
|
|
|
|
|
|
|
else {
|
66
|
16
|
|
|
|
|
25
|
$size --;
|
67
|
16
|
|
|
128
|
|
172
|
my $index = sapply([0..$size], sub {$_ % $scalar});
|
|
128
|
|
|
|
|
190
|
|
68
|
16
|
|
|
|
|
113
|
return subset($array, $index);
|
69
|
|
|
|
|
|
|
}
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub happly {
|
74
|
|
|
|
|
|
|
|
75
|
3
|
|
|
3
|
1
|
37
|
check_prototype(@_, '\%\&');
|
76
|
|
|
|
|
|
|
|
77
|
3
|
|
|
|
|
5
|
my $hash = shift;
|
78
|
3
|
|
|
|
|
5
|
my $function = shift;
|
79
|
|
|
|
|
|
|
|
80
|
3
|
|
|
|
|
6
|
my $happly = {};
|
81
|
3
|
|
|
|
|
11
|
foreach (keys %$hash) {
|
82
|
10
|
|
|
|
|
13
|
$happly->{$_} = do { my $scalar = $function->($hash->{$_});
|
|
10
|
|
|
|
|
23
|
|
83
|
10
|
|
|
|
|
52
|
$scalar; };
|
84
|
|
|
|
|
|
|
}
|
85
|
3
|
|
|
|
|
32
|
return $happly;
|
86
|
|
|
|
|
|
|
}
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub tapply {
|
90
|
|
|
|
|
|
|
|
91
|
4
|
|
|
4
|
1
|
52
|
check_prototype(@_, '\@(\@)+\&');
|
92
|
|
|
|
|
|
|
|
93
|
4
|
|
|
|
|
9
|
my $array = shift;
|
94
|
4
|
|
|
|
|
7
|
my $function = pop;
|
95
|
4
|
|
|
|
|
8
|
my @category = @_;
|
96
|
|
|
|
|
|
|
|
97
|
4
|
|
|
|
|
16
|
my $length = sapply(\@category, \&len);
|
98
|
4
|
|
|
|
|
14
|
push(@$length, len($array));
|
99
|
4
|
50
|
|
|
|
16
|
if(max($length) != min($length)) {
|
100
|
0
|
|
|
|
|
0
|
croak "ERROR: Length of the vector must be equal to the length of all categories.\n";
|
101
|
|
|
|
|
|
|
}
|
102
|
|
|
|
|
|
|
|
103
|
4
|
|
|
|
|
19
|
my $category = paste(@category, "|");
|
104
|
|
|
|
|
|
|
|
105
|
4
|
|
|
|
|
22
|
my $label = unique($category);
|
106
|
4
|
|
|
|
|
10
|
my $tapply = {};
|
107
|
4
|
|
|
|
|
11
|
for (0..$#$label) {
|
108
|
18
|
|
|
|
|
28
|
my $current_label = $label->[$_];
|
109
|
18
|
|
|
180
|
|
86
|
my $index = test($category, sub {$_[0] eq $current_label});
|
|
180
|
|
|
|
|
574
|
|
110
|
18
|
|
|
|
|
99
|
$index = which($index);
|
111
|
18
|
|
|
|
|
32
|
my @data = @{subset($array, $index)};
|
|
18
|
|
|
|
|
50
|
|
112
|
18
|
|
|
|
|
31
|
$tapply->{$current_label} = do { my $scalar = $function->(@data);
|
|
18
|
|
|
|
|
44
|
|
113
|
18
|
|
|
|
|
115
|
$scalar; };
|
114
|
|
|
|
|
|
|
}
|
115
|
4
|
|
|
|
|
66
|
return $tapply;
|
116
|
|
|
|
|
|
|
}
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1;
|