line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
PDL::Basic -- Basic utility functions for PDL |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 DESCRIPTION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
This module contains basic utility functions for |
9
|
|
|
|
|
|
|
creating and manipulating piddles. Most of these functions |
10
|
|
|
|
|
|
|
are simplified interfaces to the more flexible functions in |
11
|
|
|
|
|
|
|
the modules |
12
|
|
|
|
|
|
|
L |
13
|
|
|
|
|
|
|
and |
14
|
|
|
|
|
|
|
L. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use PDL::Basic; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 FUNCTIONS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
package PDL::Basic; |
25
|
122
|
|
|
122
|
|
870
|
use PDL::Core ''; |
|
122
|
|
|
|
|
251
|
|
|
122
|
|
|
|
|
840
|
|
26
|
122
|
|
|
122
|
|
770
|
use PDL::Types; |
|
122
|
|
|
|
|
248
|
|
|
122
|
|
|
|
|
17315
|
|
27
|
122
|
|
|
122
|
|
850
|
use PDL::Exporter; |
|
122
|
|
|
|
|
244
|
|
|
122
|
|
|
|
|
744
|
|
28
|
122
|
|
|
122
|
|
724
|
use PDL::Options; |
|
122
|
|
|
|
|
239
|
|
|
122
|
|
|
|
|
334326
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
@ISA=qw/PDL::Exporter/; |
31
|
|
|
|
|
|
|
@EXPORT_OK = qw/ ndcoords rvals axisvals allaxisvals xvals yvals zvals sec ins hist whist |
32
|
|
|
|
|
|
|
similar_assign transpose sequence xlinvals ylinvals |
33
|
|
|
|
|
|
|
zlinvals axislinvals/; |
34
|
|
|
|
|
|
|
%EXPORT_TAGS = (Func=>[@EXPORT_OK]); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Exportable functions |
37
|
|
|
|
|
|
|
*axisvals = \&PDL::axisvals; |
38
|
|
|
|
|
|
|
*allaxisvals = \&PDL::allaxisvals; |
39
|
|
|
|
|
|
|
*sec = \&PDL::sec; |
40
|
|
|
|
|
|
|
*ins = \&PDL::ins; |
41
|
|
|
|
|
|
|
*hist = \&PDL::hist; |
42
|
|
|
|
|
|
|
*whist = \&PDL::whist; |
43
|
|
|
|
|
|
|
*similar_assign = \&PDL::similar_assign; |
44
|
|
|
|
|
|
|
*transpose = \&PDL::transpose; |
45
|
|
|
|
|
|
|
*xlinvals = \&PDL::xlinvals; |
46
|
|
|
|
|
|
|
*ylinvals = \&PDL::ylinvals; |
47
|
|
|
|
|
|
|
*zlinvals = \&PDL::zlinvals; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 xvals |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=for ref |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Fills a piddle with X index values. Uses similar specifications to |
54
|
|
|
|
|
|
|
L and L. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
CAVEAT: |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
If you use the single argument piddle form (top row |
59
|
|
|
|
|
|
|
in the usage table) the output will have the same type as the input; |
60
|
|
|
|
|
|
|
this may give surprising results if, e.g., you have a byte array with |
61
|
|
|
|
|
|
|
a dimension of size greater than 256. To force a type, use the third form. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=for usage |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$x = xvals($somearray); |
66
|
|
|
|
|
|
|
$x = xvals([OPTIONAL TYPE],$nx,$ny,$nz...); |
67
|
|
|
|
|
|
|
$x = xvals([OPTIONAL TYPE], $somarray->dims); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
etc. see L. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=for example |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
pdl> print xvals zeroes(5,10) |
74
|
|
|
|
|
|
|
[ |
75
|
|
|
|
|
|
|
[0 1 2 3 4] |
76
|
|
|
|
|
|
|
[0 1 2 3 4] |
77
|
|
|
|
|
|
|
[0 1 2 3 4] |
78
|
|
|
|
|
|
|
[0 1 2 3 4] |
79
|
|
|
|
|
|
|
[0 1 2 3 4] |
80
|
|
|
|
|
|
|
[0 1 2 3 4] |
81
|
|
|
|
|
|
|
[0 1 2 3 4] |
82
|
|
|
|
|
|
|
[0 1 2 3 4] |
83
|
|
|
|
|
|
|
[0 1 2 3 4] |
84
|
|
|
|
|
|
|
[0 1 2 3 4] |
85
|
|
|
|
|
|
|
] |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 yvals |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=for ref |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Fills a piddle with Y index values. See the CAVEAT for L. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=for usage |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$x = yvals($somearray); yvals(inplace($somearray)); |
96
|
|
|
|
|
|
|
$x = yvals([OPTIONAL TYPE],$nx,$ny,$nz...); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
etc. see L. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=for example |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
pdl> print yvals zeroes(5,10) |
103
|
|
|
|
|
|
|
[ |
104
|
|
|
|
|
|
|
[0 0 0 0 0] |
105
|
|
|
|
|
|
|
[1 1 1 1 1] |
106
|
|
|
|
|
|
|
[2 2 2 2 2] |
107
|
|
|
|
|
|
|
[3 3 3 3 3] |
108
|
|
|
|
|
|
|
[4 4 4 4 4] |
109
|
|
|
|
|
|
|
[5 5 5 5 5] |
110
|
|
|
|
|
|
|
[6 6 6 6 6] |
111
|
|
|
|
|
|
|
[7 7 7 7 7] |
112
|
|
|
|
|
|
|
[8 8 8 8 8] |
113
|
|
|
|
|
|
|
[9 9 9 9 9] |
114
|
|
|
|
|
|
|
] |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 zvals |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=for ref |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Fills a piddle with Z index values. See the CAVEAT for L. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=for usage |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
$x = zvals($somearray); zvals(inplace($somearray)); |
125
|
|
|
|
|
|
|
$x = zvals([OPTIONAL TYPE],$nx,$ny,$nz...); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
etc. see L. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=for example |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
pdl> print zvals zeroes(3,4,2) |
132
|
|
|
|
|
|
|
[ |
133
|
|
|
|
|
|
|
[ |
134
|
|
|
|
|
|
|
[0 0 0] |
135
|
|
|
|
|
|
|
[0 0 0] |
136
|
|
|
|
|
|
|
[0 0 0] |
137
|
|
|
|
|
|
|
[0 0 0] |
138
|
|
|
|
|
|
|
] |
139
|
|
|
|
|
|
|
[ |
140
|
|
|
|
|
|
|
[1 1 1] |
141
|
|
|
|
|
|
|
[1 1 1] |
142
|
|
|
|
|
|
|
[1 1 1] |
143
|
|
|
|
|
|
|
[1 1 1] |
144
|
|
|
|
|
|
|
] |
145
|
|
|
|
|
|
|
] |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 xlinvals |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=for ref |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
X axis values between endpoints (see L). |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=for usage |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
$w = zeroes(100,100); |
156
|
|
|
|
|
|
|
$x = $w->xlinvals(0.5,1.5); |
157
|
|
|
|
|
|
|
$y = $w->ylinvals(-2,-1); |
158
|
|
|
|
|
|
|
# calculate Z for X between 0.5 and 1.5 and |
159
|
|
|
|
|
|
|
# Y between -2 and -1. |
160
|
|
|
|
|
|
|
$z = f($x,$y); |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
C, C and C return a piddle with the same shape |
163
|
|
|
|
|
|
|
as their first argument and linearly scaled values between the two other |
164
|
|
|
|
|
|
|
arguments along the given axis. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 ylinvals |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=for ref |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Y axis values between endpoints (see L). |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
See L for more information. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 zlinvals |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=for ref |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Z axis values between endpoints (see L). |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
See L for more information. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head2 xlogvals |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=for ref |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
X axis values logarithmically spaced between endpoints (see L). |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=for usage |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
$w = zeroes(100,100); |
191
|
|
|
|
|
|
|
$x = $w->xlogvals(1e-6,1e-3); |
192
|
|
|
|
|
|
|
$y = $w->ylinvals(1e-4,1e3); |
193
|
|
|
|
|
|
|
# calculate Z for X between 1e-6 and 1e-3 and |
194
|
|
|
|
|
|
|
# Y between 1e-4 and 1e3. |
195
|
|
|
|
|
|
|
$z = f($x,$y); |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
C, C and C return a piddle with the same shape |
198
|
|
|
|
|
|
|
as their first argument and logarithmically scaled values between the two other |
199
|
|
|
|
|
|
|
arguments along the given axis. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head2 ylogvals |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=for ref |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Y axis values logarithmically spaced between endpoints (see L). |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
See L for more information. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head2 zlogvals |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=for ref |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Z axis values logarithmically spaced between endpoints (see L). |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
See L for more information. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=cut |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
# Conveniently named interfaces to axisvals() |
220
|
|
|
|
|
|
|
|
221
|
140
|
100
|
100
|
140
|
1
|
4586
|
sub xvals { ref($_[0]) && ref($_[0]) ne 'PDL::Type' ? $_[0]->xvals : PDL->xvals(@_) } |
222
|
28
|
100
|
100
|
28
|
1
|
303
|
sub yvals { ref($_[0]) && ref($_[0]) ne 'PDL::Type' ? $_[0]->yvals : PDL->yvals(@_) } |
223
|
3
|
100
|
66
|
3
|
1
|
38
|
sub zvals { ref($_[0]) && ref($_[0]) ne 'PDL::Type' ? $_[0]->zvals : PDL->zvals(@_) } |
224
|
|
|
|
|
|
|
sub PDL::xvals { |
225
|
368
|
|
|
368
|
0
|
744
|
my $class = shift; |
226
|
368
|
100
|
|
|
|
1476
|
my $pdl = scalar(@_)? $class->new_from_specification(@_) : $class->new_or_inplace; |
227
|
368
|
|
|
|
|
1444
|
axisvals2($pdl,0); |
228
|
368
|
|
|
|
|
5843
|
return $pdl; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
sub PDL::yvals { |
231
|
35
|
|
|
35
|
0
|
84
|
my $class = shift; |
232
|
35
|
100
|
|
|
|
167
|
my $pdl = scalar(@_)? $class->new_from_specification(@_) : $class->new_or_inplace; |
233
|
35
|
|
|
|
|
186
|
axisvals2($pdl,1); |
234
|
35
|
|
|
|
|
3931
|
return $pdl; |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
sub PDL::zvals { |
237
|
5
|
|
|
5
|
0
|
11
|
my $class = shift; |
238
|
5
|
100
|
|
|
|
30
|
my $pdl = scalar(@_)? $class->new_from_specification(@_) : $class->new_or_inplace; |
239
|
5
|
|
|
|
|
19
|
axisvals2($pdl,2); |
240
|
5
|
|
|
|
|
2988
|
return $pdl; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub PDL::xlinvals { |
244
|
1
|
|
|
1
|
0
|
11
|
my $dim = $_[0]->getdim(0); |
245
|
1
|
50
|
|
|
|
4
|
barf "Must have at least two elements in dimension for xlinvals" |
246
|
|
|
|
|
|
|
if $dim <= 1; |
247
|
1
|
|
|
|
|
4
|
return $_[0]->xvals * (($_[2] - $_[1]) / ($dim-1)) + $_[1]; |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
sub PDL::ylinvals { |
251
|
1
|
|
|
1
|
0
|
94
|
my $dim = $_[0]->getdim(1); |
252
|
1
|
50
|
|
|
|
4
|
barf "Must have at least two elements in dimension for ylinvals" |
253
|
|
|
|
|
|
|
if $dim <= 1; |
254
|
1
|
|
|
|
|
4
|
return $_[0]->yvals * (($_[2] - $_[1]) / ($dim-1)) + $_[1]; |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
sub PDL::zlinvals { |
258
|
1
|
|
|
1
|
0
|
37
|
my $dim = $_[0]->getdim(2); |
259
|
1
|
50
|
|
|
|
5
|
barf "Must have at least two elements in dimension for zlinvals" |
260
|
|
|
|
|
|
|
if $dim <= 1; |
261
|
1
|
|
|
|
|
4
|
return $_[0]->zvals * (($_[2] - $_[1]) / ($dim-1)) + $_[1]; |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
sub PDL::xlogvals { |
265
|
1
|
|
|
1
|
0
|
12
|
my $dim = $_[0]->getdim(0); |
266
|
1
|
50
|
|
|
|
4
|
barf "Must have at least two elements in dimension for xlogvals" |
267
|
|
|
|
|
|
|
if $dim <= 1; |
268
|
1
|
|
|
|
|
4
|
my ($xmin,$xmax) = @_[1,2]; |
269
|
1
|
50
|
33
|
|
|
7
|
barf "xmin and xmax must be positive" |
270
|
|
|
|
|
|
|
if $xmin <= 0 || $xmax <= 0; |
271
|
1
|
|
|
|
|
7
|
my ($lxmin,$lxmax) = (log($xmin), log($xmax)); |
272
|
1
|
|
|
|
|
5
|
return exp($_[0]->xvals * (($lxmax - $lxmin) / ($dim-1)) + $lxmin); |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
sub PDL::ylogvals { |
276
|
1
|
|
|
1
|
0
|
10
|
my $dim = $_[0]->getdim(1); |
277
|
1
|
50
|
|
|
|
4
|
barf "Must have at least two elements in dimension for xlogvals" |
278
|
|
|
|
|
|
|
if $dim <= 1; |
279
|
1
|
|
|
|
|
3
|
my ($xmin,$xmax) = @_[1,2]; |
280
|
1
|
50
|
33
|
|
|
8
|
barf "xmin and xmax must be positive" |
281
|
|
|
|
|
|
|
if $xmin <= 0 || $xmax <= 0; |
282
|
1
|
|
|
|
|
3
|
my ($lxmin,$lxmax) = (log($xmin), log($xmax)); |
283
|
1
|
|
|
|
|
4
|
return exp($_[0]->yvals * (($lxmax - $lxmin) / ($dim-1)) + $lxmin); |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
sub PDL::zlogvals { |
287
|
1
|
|
|
1
|
0
|
10
|
my $dim = $_[0]->getdim(2); |
288
|
1
|
50
|
|
|
|
4
|
barf "Must have at least two elements in dimension for xlogvals" |
289
|
|
|
|
|
|
|
if $dim <= 1; |
290
|
1
|
|
|
|
|
3
|
my ($xmin,$xmax) = @_[1,2]; |
291
|
1
|
50
|
33
|
|
|
7
|
barf "xmin and xmax must be positive" |
292
|
|
|
|
|
|
|
if $xmin <= 0 || $xmax <= 0; |
293
|
1
|
|
|
|
|
3
|
my ($lxmin,$lxmax) = (log($xmin), log($xmax)); |
294
|
1
|
|
|
|
|
4
|
return exp($_[0]->zvals * (($lxmax - $lxmin) / ($dim-1)) + $lxmin); |
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=head2 allaxisvals |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=for ref |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
Synonym for L - enumerates all coordinates in a |
303
|
|
|
|
|
|
|
PDL or dim list, adding an extra dim on the front to accommodate |
304
|
|
|
|
|
|
|
the vector coordinate index (the form expected by L, |
305
|
|
|
|
|
|
|
L, and L). See L for more detail. |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=for usage |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
$indices = allaxisvals($pdl); |
310
|
|
|
|
|
|
|
$indices = allaxisvals(@dimlist); |
311
|
|
|
|
|
|
|
$indices = allaxisvals($type,@dimlist); |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=cut |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=head2 ndcoords |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
=for ref |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
Enumerate pixel coordinates for an N-D piddle |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
Returns an enumerated list of coordinates suitable for use in |
322
|
|
|
|
|
|
|
L or L: you feed |
323
|
|
|
|
|
|
|
in a dimension list and get out a piddle whose 0th dimension runs over |
324
|
|
|
|
|
|
|
dimension index and whose 1st through Nth dimensions are the |
325
|
|
|
|
|
|
|
dimensions given in the input. If you feed in a piddle instead of a |
326
|
|
|
|
|
|
|
perl list, then the dimension list is used, as in L etc. |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
Unlike L etc., if you supply a piddle input, you get |
329
|
|
|
|
|
|
|
out a piddle of the default piddle type: double. This causes less |
330
|
|
|
|
|
|
|
surprises than the previous default of keeping the data type of |
331
|
|
|
|
|
|
|
the input piddle since that rarely made sense in most usages. |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
=for usage |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
$indices = ndcoords($pdl); |
336
|
|
|
|
|
|
|
$indices = ndcoords(@dimlist); |
337
|
|
|
|
|
|
|
$indices = ndcoords($type,@dimlist); |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
=for example |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
pdl> print ndcoords(2,3) |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
[ |
344
|
|
|
|
|
|
|
[ |
345
|
|
|
|
|
|
|
[0 0] |
346
|
|
|
|
|
|
|
[1 0] |
347
|
|
|
|
|
|
|
] |
348
|
|
|
|
|
|
|
[ |
349
|
|
|
|
|
|
|
[0 1] |
350
|
|
|
|
|
|
|
[1 1] |
351
|
|
|
|
|
|
|
] |
352
|
|
|
|
|
|
|
[ |
353
|
|
|
|
|
|
|
[0 2] |
354
|
|
|
|
|
|
|
[1 2] |
355
|
|
|
|
|
|
|
] |
356
|
|
|
|
|
|
|
] |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
pdl> $w = zeroes(byte,2,3); # $w is a 2x3 byte piddle |
359
|
|
|
|
|
|
|
pdl> $y = ndcoords($w); # $y inherits $w's type |
360
|
|
|
|
|
|
|
pdl> $c = ndcoords(long,$w->dims); # $c is a long piddle, same dims as $y |
361
|
|
|
|
|
|
|
pdl> help $y; |
362
|
|
|
|
|
|
|
This variable is Byte D [2,2,3] P 0.01Kb |
363
|
|
|
|
|
|
|
pdl> help $c; |
364
|
|
|
|
|
|
|
This variable is Long D [2,2,3] P 0.05Kb |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
=cut |
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
sub PDL::ndcoords { |
370
|
44
|
|
|
44
|
0
|
70
|
my $type; |
371
|
44
|
50
|
|
|
|
125
|
if(ref $_[0] eq 'PDL::Type') { |
372
|
0
|
|
|
|
|
0
|
$type = shift; |
373
|
|
|
|
|
|
|
} |
374
|
|
|
|
|
|
|
|
375
|
44
|
50
|
|
|
|
134
|
my @dims = (ref $_[0]) ? (shift)->dims : @_; |
376
|
44
|
|
|
|
|
97
|
my @d = @dims; |
377
|
44
|
|
|
|
|
108
|
unshift(@d,scalar(@dims)); |
378
|
44
|
50
|
|
|
|
103
|
unshift(@d,$type) if defined($type); |
379
|
|
|
|
|
|
|
|
380
|
44
|
|
|
|
|
160
|
$out = PDL->zeroes(@d); |
381
|
|
|
|
|
|
|
|
382
|
44
|
|
|
|
|
178
|
for my $d(0..$#dims) { |
383
|
88
|
|
|
|
|
1158
|
my $w = $out->index($d)->mv($d,0); |
384
|
88
|
|
|
|
|
753
|
$w .= xvals($w); |
385
|
|
|
|
|
|
|
} |
386
|
|
|
|
|
|
|
|
387
|
44
|
|
|
|
|
257
|
$out; |
388
|
|
|
|
|
|
|
} |
389
|
|
|
|
|
|
|
*ndcoords = \&PDL::ndcoords; |
390
|
|
|
|
|
|
|
*allaxisvals = \&PDL::ndcoords; |
391
|
|
|
|
|
|
|
*PDL::allaxisvals = \&PDL::ndcoords; |
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
=head2 hist |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
=for ref |
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
Create histogram of a piddle |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
=for usage |
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
$hist = hist($data); |
403
|
|
|
|
|
|
|
($xvals,$hist) = hist($data); |
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
or |
406
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
$hist = hist($data,$min,$max,$step); |
408
|
|
|
|
|
|
|
($xvals,$hist) = hist($data,[$min,$max,$step]); |
409
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
If C is run in list context, C<$xvals> gives the |
411
|
|
|
|
|
|
|
computed bin centres as double values. |
412
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
A nice idiom (with |
414
|
|
|
|
|
|
|
L) is |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
bin hist $data; # Plot histogram |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
=for example |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
pdl> p $y |
421
|
|
|
|
|
|
|
[13 10 13 10 9 13 9 12 11 10 10 13 7 6 8 10 11 7 12 9 11 11 12 6 12 7] |
422
|
|
|
|
|
|
|
pdl> $h = hist $y,0,20,1; # hist with step 1, min 0 and 20 bins |
423
|
|
|
|
|
|
|
pdl> p $h |
424
|
|
|
|
|
|
|
[0 0 0 0 0 0 2 3 1 3 5 4 4 4 0 0 0 0 0 0] |
425
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
=cut |
427
|
|
|
|
|
|
|
|
428
|
|
|
|
|
|
|
sub PDL::hist { |
429
|
|
|
|
|
|
|
|
430
|
2
|
|
|
2
|
0
|
17
|
my $usage = "\n" . ' Usage: $hist = hist($data)' . "\n" . |
431
|
|
|
|
|
|
|
' $hist = hist($data,$min,$max,$step)' . "\n" . |
432
|
|
|
|
|
|
|
' ($xvals,$hist) = hist($data)' . "\n" . |
433
|
|
|
|
|
|
|
' ($xvals,$hist) = hist($data,$min,$max,$step)' . "\n" ; |
434
|
2
|
50
|
|
|
|
9
|
barf($usage) if $#_<0; |
435
|
|
|
|
|
|
|
|
436
|
2
|
|
|
|
|
6
|
my($pdl,$min,$max,$step)=@_; |
437
|
2
|
|
|
|
|
5
|
my $xvals; |
438
|
|
|
|
|
|
|
|
439
|
2
|
|
|
|
|
11
|
($step, $min, $bins, $xvals) = |
440
|
|
|
|
|
|
|
_hist_bin_calc($pdl, $min, $max, $step, wantarray()); |
441
|
|
|
|
|
|
|
|
442
|
2
|
|
|
|
|
10
|
PDL::Primitive::histogram($pdl->clump(-1),(my $hist = null), |
443
|
|
|
|
|
|
|
$step,$min,$bins); |
444
|
|
|
|
|
|
|
|
445
|
2
|
100
|
|
|
|
26
|
return wantarray() ? ($xvals,$hist) : $hist; |
446
|
|
|
|
|
|
|
} |
447
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
=head2 whist |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
=for ref |
451
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
Create a weighted histogram of a piddle |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
=for usage |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
$hist = whist($data, $wt, [$min,$max,$step]); |
457
|
|
|
|
|
|
|
($xvals,$hist) = whist($data, $wt, [$min,$max,$step]); |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
If requested, C<$xvals> gives the computed bin centres |
460
|
|
|
|
|
|
|
as type double values. C<$data> and C<$wt> should have |
461
|
|
|
|
|
|
|
the same dimensionality and extents. |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
A nice idiom (with |
464
|
|
|
|
|
|
|
L) is |
465
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
bin whist $data, $wt; # Plot histogram |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
=for example |
469
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
pdl> p $y |
471
|
|
|
|
|
|
|
[13 10 13 10 9 13 9 12 11 10 10 13 7 6 8 10 11 7 12 9 11 11 12 6 12 7] |
472
|
|
|
|
|
|
|
pdl> $wt = grandom($y->nelem) |
473
|
|
|
|
|
|
|
pdl> $h = whist $y, $wt, 0, 20, 1 # hist with step 1, min 0 and 20 bins |
474
|
|
|
|
|
|
|
pdl> p $h |
475
|
|
|
|
|
|
|
[0 0 0 0 0 0 -0.49552342 1.7987439 0.39450696 4.0073722 -2.6255299 -2.5084501 2.6458365 4.1671676 0 0 0 0 0 0] |
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
=cut |
479
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
sub PDL::whist { |
481
|
1
|
50
|
|
1
|
0
|
11
|
barf('Usage: ([$xvals],$hist) = whist($data,$wt,[$min,$max,$step])') |
482
|
|
|
|
|
|
|
if @_ < 2; |
483
|
1
|
|
|
|
|
3
|
my($pdl,$wt,$min,$max,$step)=@_; |
484
|
1
|
|
|
|
|
2
|
my $xvals; |
485
|
|
|
|
|
|
|
|
486
|
1
|
|
|
|
|
4
|
($step, $min, $bins, $xvals) = |
487
|
|
|
|
|
|
|
_hist_bin_calc($pdl, $min, $max, $step, wantarray()); |
488
|
|
|
|
|
|
|
|
489
|
1
|
|
|
|
|
7
|
PDL::Primitive::whistogram($pdl->clump(-1),$wt->clump(-1), |
490
|
|
|
|
|
|
|
(my $hist = null), $step, $min, $bins); |
491
|
1
|
50
|
|
|
|
16
|
return wantarray() ? ($xvals,$hist) : $hist; |
492
|
|
|
|
|
|
|
} |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
sub _hist_bin_calc { |
495
|
3
|
|
|
3
|
|
10
|
my($pdl,$min,$max,$step,$wantarray)=@_; |
496
|
3
|
50
|
|
|
|
8
|
$min = $pdl->min() unless defined $min; |
497
|
3
|
50
|
|
|
|
9
|
$max = $pdl->max() unless defined $max; |
498
|
3
|
|
|
|
|
26
|
my $nelem = $pdl->nelem; |
499
|
3
|
50
|
|
|
|
10
|
barf "empty piddle, no values to work with" if $nelem == 0; |
500
|
|
|
|
|
|
|
|
501
|
3
|
0
|
|
|
|
8
|
$step = ($max-$min)/(($nelem>10_000) ? 100 : sqrt($nelem)) unless defined $step; |
|
|
50
|
|
|
|
|
|
502
|
3
|
50
|
|
|
|
10
|
barf "step is zero (or all data equal to one value)" if $step == 0; |
503
|
|
|
|
|
|
|
|
504
|
3
|
|
|
|
|
11
|
my $bins = int(($max-$min)/$step+0.5); |
505
|
3
|
50
|
|
|
|
10
|
print "hist with step $step, min $min and $bins bins\n" |
506
|
|
|
|
|
|
|
if $PDL::debug; |
507
|
|
|
|
|
|
|
# Need to use double for $xvals here |
508
|
3
|
100
|
|
|
|
31
|
my $xvals = $min + $step/2 + sequence(PDL::Core::double,$bins)*$step if $wantarray; |
509
|
|
|
|
|
|
|
|
510
|
3
|
|
|
|
|
36
|
return ( $step, $min, $bins, $xvals ); |
511
|
|
|
|
|
|
|
} |
512
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
=head2 sequence |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
=for ref |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
Create array filled with a sequence of values |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
=for usage |
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
$w = sequence($y); $w = sequence [OPTIONAL TYPE], @dims; |
523
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
etc. see L. |
525
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
=for example |
527
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
pdl> p sequence(10) |
529
|
|
|
|
|
|
|
[0 1 2 3 4 5 6 7 8 9] |
530
|
|
|
|
|
|
|
pdl> p sequence(3,4) |
531
|
|
|
|
|
|
|
[ |
532
|
|
|
|
|
|
|
[ 0 1 2] |
533
|
|
|
|
|
|
|
[ 3 4 5] |
534
|
|
|
|
|
|
|
[ 6 7 8] |
535
|
|
|
|
|
|
|
[ 9 10 11] |
536
|
|
|
|
|
|
|
] |
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
=cut |
539
|
|
|
|
|
|
|
|
540
|
139
|
50
|
66
|
139
|
1
|
3252590
|
sub sequence { ref($_[0]) && ref($_[0]) ne 'PDL::Type' ? $_[0]->sequence : PDL->sequence(@_) } |
541
|
|
|
|
|
|
|
sub PDL::sequence { |
542
|
144
|
|
|
144
|
0
|
1431
|
my $class = shift; |
543
|
144
|
100
|
|
|
|
794
|
my $pdl = scalar(@_)? $class->new_from_specification(@_) : $class->new_or_inplace; |
544
|
144
|
|
|
|
|
708
|
my $bar = $pdl->clump(-1)->inplace; |
545
|
144
|
|
|
|
|
470
|
my $foo = $bar->xvals; |
546
|
144
|
|
|
|
|
2451
|
return $pdl; |
547
|
|
|
|
|
|
|
} |
548
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
=head2 rvals |
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
=for ref |
552
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
Fills a piddle with radial distance values from some centre. |
554
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
=for usage |
556
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
$r = rvals $piddle,{OPTIONS}; |
558
|
|
|
|
|
|
|
$r = rvals [OPTIONAL TYPE],$nx,$ny,...{OPTIONS}; |
559
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
=for options |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
Options: |
563
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
Centre => [$x,$y,$z...] # Specify centre |
565
|
|
|
|
|
|
|
Center => [$x,$y.$z...] # synonym. |
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
Squared => 1 # return distance squared (i.e., don't take the square root) |
568
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
=for example |
570
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
pdl> print rvals long,7,7,{Centre=>[2,2]} |
572
|
|
|
|
|
|
|
[ |
573
|
|
|
|
|
|
|
[2 2 2 2 2 3 4] |
574
|
|
|
|
|
|
|
[2 1 1 1 2 3 4] |
575
|
|
|
|
|
|
|
[2 1 0 1 2 3 4] |
576
|
|
|
|
|
|
|
[2 1 1 1 2 3 4] |
577
|
|
|
|
|
|
|
[2 2 2 2 2 3 4] |
578
|
|
|
|
|
|
|
[3 3 3 3 3 4 5] |
579
|
|
|
|
|
|
|
[4 4 4 4 4 5 5] |
580
|
|
|
|
|
|
|
] |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
If C is not specified, the midpoint for a given dimension of |
583
|
|
|
|
|
|
|
size C is given by C< int(N/2) > so that the midpoint always falls |
584
|
|
|
|
|
|
|
on an exact pixel point in the data. For dimensions of even size, |
585
|
|
|
|
|
|
|
that means the midpoint is shifted by 1/2 pixel from the true center |
586
|
|
|
|
|
|
|
of that dimension. |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
Also note that the calculation for C for integer values |
589
|
|
|
|
|
|
|
does not promote the datatype so you will have wraparound when |
590
|
|
|
|
|
|
|
the value calculated for C< r**2 > is greater than the datatype |
591
|
|
|
|
|
|
|
can hold. If you need exact values, be sure to use large integer |
592
|
|
|
|
|
|
|
or floating point datatypes. |
593
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
For a more general metric, one can define, e.g., |
595
|
|
|
|
|
|
|
|
596
|
|
|
|
|
|
|
sub distance { |
597
|
|
|
|
|
|
|
my ($w,$centre,$f) = @_; |
598
|
|
|
|
|
|
|
my ($r) = $w->allaxisvals-$centre; |
599
|
|
|
|
|
|
|
$f->($r); |
600
|
|
|
|
|
|
|
} |
601
|
|
|
|
|
|
|
sub l1 { sumover(abs($_[0])); } |
602
|
|
|
|
|
|
|
sub euclid { use PDL::Math 'pow'; pow(sumover(pow($_[0],2)),0.5); } |
603
|
|
|
|
|
|
|
sub linfty { maximum(abs($_[0])); } |
604
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
so now |
606
|
|
|
|
|
|
|
|
607
|
|
|
|
|
|
|
distance($w, $centre, \&euclid); |
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
will emulate rvals, while C<\&l1> and C<\&linfty> will generate other |
610
|
|
|
|
|
|
|
well-known norms. |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
=cut |
613
|
|
|
|
|
|
|
|
614
|
14
|
50
|
66
|
14
|
1
|
2435
|
sub rvals { ref($_[0]) && ref($_[0]) ne 'PDL::Type' ? $_[0]->rvals(@_[1..$#_]) : PDL->rvals(@_) } |
615
|
|
|
|
|
|
|
sub PDL::rvals { # Return radial distance from given point and offset |
616
|
14
|
|
|
14
|
0
|
29
|
my $class = shift; |
617
|
14
|
100
|
|
|
|
49
|
my $opt = pop @_ if ref($_[$#_]) eq "HASH"; |
618
|
14
|
100
|
|
|
|
60
|
my %opt = defined $opt ? |
619
|
|
|
|
|
|
|
iparse( { |
620
|
|
|
|
|
|
|
CENTRE => undef, # needed, otherwise centre/center handling painful |
621
|
|
|
|
|
|
|
Squared => 0, |
622
|
|
|
|
|
|
|
}, $opt ) : (); |
623
|
14
|
50
|
|
|
|
66
|
my $r = scalar(@_)? $class->new_from_specification(@_) : $class->new_or_inplace; |
624
|
|
|
|
|
|
|
|
625
|
14
|
|
|
|
|
33
|
my @pos; |
626
|
14
|
100
|
|
|
|
39
|
@pos = @{$opt{CENTRE}} if defined $opt{CENTRE}; |
|
7
|
|
|
|
|
16
|
|
627
|
14
|
|
|
|
|
20
|
my $offset; |
628
|
|
|
|
|
|
|
|
629
|
14
|
|
|
|
|
85
|
$r .= 0.0; |
630
|
14
|
|
|
|
|
53
|
my $tmp = $r->copy; |
631
|
14
|
|
|
|
|
25
|
my $i; |
632
|
14
|
|
|
|
|
77
|
for ($i=0; $i<$r->getndims; $i++) { |
633
|
28
|
100
|
|
|
|
116
|
$offset = (defined $pos[$i] ? $pos[$i] : int($r->getdim($i)/2)); |
634
|
|
|
|
|
|
|
# Note careful coding for speed and min memory footprint |
635
|
28
|
|
|
|
|
479
|
PDL::Primitive::axisvalues($tmp->xchg(0,$i)); |
636
|
28
|
|
|
|
|
188
|
$tmp -= $offset; $tmp *= $tmp; |
|
28
|
|
|
|
|
78
|
|
637
|
28
|
|
|
|
|
68
|
$r += $tmp; |
638
|
|
|
|
|
|
|
} |
639
|
14
|
100
|
|
|
|
73
|
return $opt{Squared} ? $r : $r->inplace->sqrt; |
640
|
|
|
|
|
|
|
} |
641
|
|
|
|
|
|
|
|
642
|
|
|
|
|
|
|
=head2 axisvals |
643
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
=for ref |
645
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
Fills a piddle with index values on Nth dimension |
647
|
|
|
|
|
|
|
|
648
|
|
|
|
|
|
|
=for usage |
649
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
$z = axisvals ($piddle, $nth); |
651
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
This is the routine, for which L, L etc |
653
|
|
|
|
|
|
|
are mere shorthands. C can be used to fill along any dimension, |
654
|
|
|
|
|
|
|
using a parameter. |
655
|
|
|
|
|
|
|
|
656
|
|
|
|
|
|
|
See also L, which generates all axis values |
657
|
|
|
|
|
|
|
simultaneously in a form useful for L, L, |
658
|
|
|
|
|
|
|
L, etc. |
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
Note the 'from specification' style (see L) is |
661
|
|
|
|
|
|
|
not available here, for obvious reasons. |
662
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
=cut |
664
|
|
|
|
|
|
|
|
665
|
|
|
|
|
|
|
sub PDL::axisvals { |
666
|
1
|
|
|
1
|
0
|
3
|
my($this,$nth) = @_; |
667
|
1
|
|
|
|
|
4
|
my $dummy = $this->new_or_inplace; |
668
|
1
|
50
|
|
|
|
6
|
if($dummy->getndims() <= $nth) { |
669
|
|
|
|
|
|
|
# This is 'kind of' consistency... |
670
|
0
|
|
|
|
|
0
|
$dummy .= 0; |
671
|
0
|
|
|
|
|
0
|
return $dummy; |
672
|
|
|
|
|
|
|
# barf("Too few dimensions given to axisvals $nth\n"); |
673
|
|
|
|
|
|
|
} |
674
|
1
|
|
|
|
|
5
|
my $bar = $dummy->xchg(0,$nth); |
675
|
1
|
|
|
|
|
14
|
PDL::Primitive::axisvalues($bar); |
676
|
1
|
|
|
|
|
5
|
return $dummy; |
677
|
|
|
|
|
|
|
} |
678
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
# We need this version for xvals etc to work in place |
680
|
|
|
|
|
|
|
sub axisvals2 { |
681
|
408
|
|
|
408
|
0
|
996
|
my($this,$nth) = @_; |
682
|
408
|
|
|
|
|
713
|
my $dummy = shift; |
683
|
408
|
50
|
|
|
|
2311
|
if($dummy->getndims() <= $nth) { |
684
|
|
|
|
|
|
|
# This is 'kind of' consistency... |
685
|
0
|
|
|
|
|
0
|
$dummy .= 0; |
686
|
0
|
|
|
|
|
0
|
return $dummy; |
687
|
|
|
|
|
|
|
# barf("Too few dimensions given to axisvals $nth\n"); |
688
|
|
|
|
|
|
|
} |
689
|
408
|
|
|
|
|
3490
|
my $bar = $dummy->xchg(0,$nth); |
690
|
408
|
|
|
|
|
23311
|
PDL::Primitive::axisvalues($bar); |
691
|
408
|
|
|
|
|
3038
|
return $dummy; |
692
|
|
|
|
|
|
|
} |
693
|
|
|
|
|
|
|
sub PDL::sec { |
694
|
0
|
|
|
0
|
0
|
0
|
my($this,@coords) = @_; |
695
|
0
|
|
|
|
|
0
|
my $i; my @maps; |
696
|
0
|
|
|
|
|
0
|
while($#coords > -1) { |
697
|
0
|
|
|
|
|
0
|
$i = int(shift @coords) ; |
698
|
0
|
|
|
|
|
0
|
push @maps, "$i:".int(shift @coords); |
699
|
|
|
|
|
|
|
} |
700
|
0
|
|
|
|
|
0
|
my $tmp = PDL->null; |
701
|
0
|
|
|
|
|
0
|
$tmp .= $this->slice(join ',',@maps); |
702
|
0
|
|
|
|
|
0
|
return $tmp; |
703
|
|
|
|
|
|
|
} |
704
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
sub PDL::ins { |
706
|
0
|
|
|
0
|
0
|
0
|
my($this,$what,@coords) = @_; |
707
|
0
|
|
|
|
|
0
|
my $w = PDL::Core::alltopdl($PDL::name,$what); |
708
|
0
|
|
|
|
|
0
|
my $tmp; |
709
|
0
|
0
|
|
|
|
0
|
if($this->is_inplace) { |
710
|
0
|
|
|
|
|
0
|
$this->set_inplace(0); |
711
|
|
|
|
|
|
|
} else { |
712
|
0
|
|
|
|
|
0
|
$this = $this->copy; |
713
|
|
|
|
|
|
|
} |
714
|
|
|
|
|
|
|
($tmp = $this->slice( |
715
|
0
|
0
|
|
|
|
0
|
(join ',',map {int($coords[$_]).":". |
|
0
|
|
|
|
|
0
|
|
716
|
|
|
|
|
|
|
((int($coords[$_])+$w->getdim($_)-1)<$this->getdim($_) ? |
717
|
|
|
|
|
|
|
(int($coords[$_])+$w->getdim($_)-1):$this->getdim($_)) |
718
|
|
|
|
|
|
|
} |
719
|
|
|
|
|
|
|
0..$#coords))) |
720
|
|
|
|
|
|
|
.= $w; |
721
|
0
|
|
|
|
|
0
|
return $this; |
722
|
|
|
|
|
|
|
} |
723
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
sub PDL::similar_assign { |
725
|
0
|
|
|
0
|
0
|
0
|
my($from,$to) = @_; |
726
|
0
|
0
|
|
|
|
0
|
if((join ',',@{$from->dims}) ne (join ',',@{$to->dims})) { |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
727
|
|
|
|
|
|
|
barf "Similar_assign: dimensions [". |
728
|
0
|
|
|
|
|
0
|
(join ',',@{$from->dims})."] and [". |
729
|
0
|
|
|
|
|
0
|
(join ',',@{$to->dims})."] do not match!\n"; |
|
0
|
|
|
|
|
0
|
|
730
|
|
|
|
|
|
|
} |
731
|
0
|
|
|
|
|
0
|
$to .= $from; |
732
|
|
|
|
|
|
|
} |
733
|
|
|
|
|
|
|
|
734
|
|
|
|
|
|
|
=head2 transpose |
735
|
|
|
|
|
|
|
|
736
|
|
|
|
|
|
|
=for ref |
737
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
transpose rows and columns. |
739
|
|
|
|
|
|
|
|
740
|
|
|
|
|
|
|
=for usage |
741
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
$y = transpose($w); |
743
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
=for example |
745
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
pdl> $w = sequence(3,2) |
747
|
|
|
|
|
|
|
pdl> p $w |
748
|
|
|
|
|
|
|
[ |
749
|
|
|
|
|
|
|
[0 1 2] |
750
|
|
|
|
|
|
|
[3 4 5] |
751
|
|
|
|
|
|
|
] |
752
|
|
|
|
|
|
|
pdl> p transpose( $w ) |
753
|
|
|
|
|
|
|
[ |
754
|
|
|
|
|
|
|
[0 3] |
755
|
|
|
|
|
|
|
[1 4] |
756
|
|
|
|
|
|
|
[2 5] |
757
|
|
|
|
|
|
|
] |
758
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
=cut |
760
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
sub PDL::transpose { |
762
|
13
|
|
|
13
|
0
|
55
|
my($this) = @_; |
763
|
13
|
100
|
|
|
|
114
|
if($this->getndims <= 1) { |
764
|
6
|
50
|
|
|
|
28
|
if($this->getndims==0) { |
765
|
0
|
|
|
|
|
0
|
return pdl $this->dummy(0)->dummy(0); |
766
|
|
|
|
|
|
|
} else { |
767
|
6
|
|
|
|
|
27
|
return pdl $this->dummy(0); |
768
|
|
|
|
|
|
|
} |
769
|
|
|
|
|
|
|
} |
770
|
7
|
|
|
|
|
71
|
return $this->xchg(0,1); |
771
|
|
|
|
|
|
|
} |
772
|
|
|
|
|
|
|
|
773
|
|
|
|
|
|
|
1; |
774
|
|
|
|
|
|
|
|