line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
PDLA::Dbg - functions to support debugging of PDLA scripts |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use PDLA; |
8
|
|
|
|
|
|
|
use PDLA::Dbg; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$c = $x->slice("5:10,2:30")->px->diagonal(3,4); |
11
|
|
|
|
|
|
|
PDLA->px; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
These packages implements a couple of functions that should come in |
16
|
|
|
|
|
|
|
handy when debugging your PDLA scripts. They make a lot of sense while |
17
|
|
|
|
|
|
|
you're doing rapid prototyping of new PDLA code, let's say inside the |
18
|
|
|
|
|
|
|
perldla or pdla2 shell. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#' fool emacs |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
package PDLA::Dbg; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# used by info |
27
|
|
|
|
|
|
|
$PDLA::Dbg::Title = "Type Dimension Flow State Mem"; |
28
|
|
|
|
|
|
|
$PDLA::Dbg::Infostr = "%6T %-15D %3F %-5S %12M"; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
package PDLA; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 FUNCTIONS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 px |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=for ref |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Print info about a piddle (or all known piddles) |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=for example |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
pdla> PDLA->px |
43
|
|
|
|
|
|
|
pdla> $y += $x->clump(2)->px('clumptest')->sumover |
44
|
|
|
|
|
|
|
pdla> $x->px('%C (%A) Type: %T') # prints nothing unless $PDLA::debug |
45
|
|
|
|
|
|
|
pdla> $PDLA::debug = 1 |
46
|
|
|
|
|
|
|
pdla> $x->px('%C (%A) Type: %T') |
47
|
|
|
|
|
|
|
PDLA (52433464) Type: Double |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
This function prints some information about piddles. It can be invoked |
51
|
|
|
|
|
|
|
as a class method (e.g. Cpx> ) or as an instance method (e.g. |
52
|
|
|
|
|
|
|
C<$pdl-Epx($arg)>). If |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=over 2 |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item invoked as a class method |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
it prints info about all piddles found in the current package |
59
|
|
|
|
|
|
|
(I C variables). This comes in quite handy when you are |
60
|
|
|
|
|
|
|
not quite sure which pdls you have already defined, what data they |
61
|
|
|
|
|
|
|
hold , etc. C is supposed to support inheritance and prints info |
62
|
|
|
|
|
|
|
about all symbols for which an C is true. An optional |
63
|
|
|
|
|
|
|
string argument is interpreted as the package name for which to print |
64
|
|
|
|
|
|
|
symbols: |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
pdla> PDLA->px('PDLA::Mypack') |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
The default package is that of the caller. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item invoked as an instance method |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
it prints info about that particular piddle if C<$PDLA::debug> is |
73
|
|
|
|
|
|
|
true and returns the pdl object upon completion. It accepts an |
74
|
|
|
|
|
|
|
optional string argument that is simply prepended to the default info |
75
|
|
|
|
|
|
|
if it doesn't contain a C<%> character. If, however, the argument |
76
|
|
|
|
|
|
|
contains a C<%> then the string is passed to the C method to |
77
|
|
|
|
|
|
|
control the format of the printed information. This can be used to |
78
|
|
|
|
|
|
|
achieve customized output from C. See the documentation of |
79
|
|
|
|
|
|
|
C for further details. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=back |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
The output of px will be determined by the default formatting string |
84
|
|
|
|
|
|
|
that is passed to the C method (unless you pass a string |
85
|
|
|
|
|
|
|
containing C<%> to px when invoking as an instance method, see |
86
|
|
|
|
|
|
|
above). This default string is stored in C<$PDLA::Dbg::Infostr> and the |
87
|
|
|
|
|
|
|
default output format can be accordingly changed by setting this |
88
|
|
|
|
|
|
|
variable. If you do this you should also change the default title |
89
|
|
|
|
|
|
|
string that the class method branch prints at the top of the listing |
90
|
|
|
|
|
|
|
to match your new format string. The default title is stored in the |
91
|
|
|
|
|
|
|
variable C<$PDLA::Dbg::Title>. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
For historical reasons C is an alias for C. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub px { |
98
|
8
|
|
|
8
|
0
|
372
|
my $arg = shift; |
99
|
8
|
|
|
|
|
15
|
my $str=""; |
100
|
|
|
|
|
|
|
|
101
|
8
|
50
|
|
|
|
26
|
if (ref($arg)) { |
102
|
8
|
100
|
|
|
|
26
|
return $arg unless $PDLA::debug; |
103
|
6
|
0
|
|
|
|
30
|
my $info = $arg->info($#_ > -1 ? ($_[0] =~ /%/ ? |
|
|
50
|
|
|
|
|
|
104
|
|
|
|
|
|
|
$_[0] : "$_[0] $PDLA::Dbg::Infostr") : |
105
|
|
|
|
|
|
|
$PDLA::Dbg::Infostr); |
106
|
6
|
|
|
|
|
182
|
print "$info\n"; |
107
|
6
|
|
|
|
|
42
|
return $arg; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# we have been called as a class method |
111
|
0
|
0
|
|
|
|
|
my $package = $#_ > -1 ? shift : caller; |
112
|
0
|
|
|
|
|
|
my $classname = $arg; |
113
|
|
|
|
|
|
|
# find the correct package |
114
|
0
|
0
|
|
|
|
|
$package .= "::" unless $package =~ /::$/; |
115
|
0
|
|
|
|
|
|
*stab = *{"main::"}; |
|
0
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
while ($package =~ /(\w+?::)/g){ |
117
|
0
|
|
|
|
|
|
*stab = $ {stab}{$1}; |
118
|
|
|
|
|
|
|
} |
119
|
0
|
|
|
|
|
|
print "$classname variables in package $package\n\n"; |
120
|
0
|
|
|
|
|
|
my $title = "Name $PDLA::Dbg::Title\n"; |
121
|
0
|
|
|
|
|
|
print $title; |
122
|
0
|
|
|
|
|
|
print '-'x(length($title)+3)."\n"; |
123
|
0
|
|
|
|
|
|
my ($pdl,$npdls,$key,$val,$info) = ((),0,"","",""); |
124
|
|
|
|
|
|
|
# while (($key,$val) = each(%stab)) { |
125
|
0
|
|
|
|
|
|
foreach $key ( sort { lc($a) cmp lc($b) } keys(%stab) ) { |
|
0
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
$val = $stab{$key}; |
127
|
0
|
|
|
|
|
|
$pdl = ${"$package$key"}; |
|
0
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# print info for all objects derived from this class |
129
|
0
|
0
|
|
|
|
|
if (UNIVERSAL::isa($pdl,$classname)) { |
130
|
0
|
|
|
|
|
|
$npdls++; |
131
|
0
|
|
|
|
|
|
$info = $pdl->info($PDLA::Dbg::Infostr); |
132
|
0
|
0
|
|
|
|
|
printf "\$%-11s %s %s\n",$key,$info,(ref($pdl) eq $classname ? '' : |
133
|
|
|
|
|
|
|
ref($pdl)); |
134
|
|
|
|
|
|
|
# also print classname for derived classes |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
0
|
0
|
|
|
|
|
print "no $classname objects in package $package\n" |
138
|
|
|
|
|
|
|
unless $npdls; |
139
|
0
|
|
|
|
|
|
return $arg; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 vars |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=for ref |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Alias for C |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# make vars an alias |
151
|
|
|
|
|
|
|
# I hope this works with inheritance |
152
|
|
|
|
|
|
|
*vars = \&px; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; # return success |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 BUGS |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
There are probably some. Please report if you find any. Bug reports |
159
|
|
|
|
|
|
|
should be sent to the PDLA mailing list pdl-general@lists.sourceforge.net. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 AUTHOR |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Copyright(C) 1997 Christian Soeller (c.soeller@auckland.ac.nz). |
164
|
|
|
|
|
|
|
All rights reserved. There is no warranty. You are allowed |
165
|
|
|
|
|
|
|
to redistribute this software / documentation under certain |
166
|
|
|
|
|
|
|
conditions. For details, see the file COPYING in the PDLA |
167
|
|
|
|
|
|
|
distribution. If this file is separated from the PDLA distribution, |
168
|
|
|
|
|
|
|
the copyright notice should be included in the file. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|