NDBin/Actions_PP.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 13 / 13 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« NDBin.pm ↑ Summary
1 #
2 # GENERATED WITH PDL::PP from actions.pd! Don't modify!
3 #
4 package PDL::NDBin::Actions_PP;
5  
6 our @EXPORT_OK = qw(_flatten_into _setnulltobad _icount_loop _imax_loop _imin_loop _isum_loop _iavg_loop _istddev_loop _istddev_post );
7 our %EXPORT_TAGS = (Func=>\@EXPORT_OK);
8  
9 11 ▶use PDL::Core;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use PDL::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use DynaLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 our $VERSION = '0.016';
15 our @ISA = ( 'PDL::Exporter','DynaLoader' );
16 push @PDL::Core::PP, __PACKAGE__;
17 bootstrap PDL::NDBin::Actions_PP $VERSION;
18  
19  
20  
21  
22 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 # ABSTRACT: XS actions for PDL::NDBin
25  
26 =head1 NAME
27  
28 PDL::NDBin::Actions_PP - XS actions for PDL::NDBin
29  
30 =head1 DESCRIPTION
31  
32 This module contains the implementation of the core loop of the action classes
33 in the PDL::NDBin::Action namespace. The subroutines are not intended to be
34 called by the user.
35  
36 =cut
37  
38 # silence Test::Pod::Coverage warning
39 =for Pod::Coverage set_boundscheck set_debugging
40  
41 =cut
42  
43  
44  
45 }
46  
47  
48  
49  
50  
51 =head1 FUNCTIONS
52  
53 =cut
54  
55  
56  
57  
58  
59  
60 =head2 _flatten_into
61  
62 =for sig
63  
64 Signature: (in(m); indx b(m); indx [o] idx(m); double step; double min; PDL_Indx n)
65 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
66 float double ldouble)
67  
68 =for usage
69  
70 $idx = _flatten_into($in, $b, $step, $min, $n);
71 _flatten_into($in, $b, $idx, $step, $min, $n); # all arguments given
72 $idx = $in->_flatten_into($b, $step, $min, $n); # method call
73 $in->_flatten_into($b, $idx, $step, $min, $n);
74  
75 =for ref
76  
77 Bin a series of values and flatten into an existing list of indices.
78  
79 =pod
80  
81 Broadcasts over its inputs.
82  
83 =for bad
84  
85 C<_flatten_into> processes bad values.
86 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
87  
88 =cut
89  
90  
91  
92  
93 *_flatten_into = \&PDL::_flatten_into;
94  
95  
96  
97  
98  
99  
100 =head2 _setnulltobad
101  
102 =for sig
103  
104 Signature: (in(); indx count(); [o] out())
105 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
106 float double ldouble)
107  
108 =for usage
109  
110 $out = _setnulltobad($in, $count);
111 _setnulltobad($in, $count, $out); # all arguments given
112 $out = $in->_setnulltobad($count); # method call
113 $in->_setnulltobad($count, $out);
114 $in->inplace->_setnulltobad($count); # can be used inplace
115 _setnulltobad($in->inplace, $count);
116  
117 =for ref
118  
119 Set empty bins to the bad value.
120  
121 =pod
122  
123 Can operate inplace with C<in> as output C<out>.
124 Broadcasts over its inputs.
125  
126 =for bad
127  
128 C<_setnulltobad> processes bad values.
129 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
130  
131 =cut
132  
133  
134  
135  
136 *_setnulltobad = \&PDL::_setnulltobad;
137  
138  
139  
140  
141  
142  
143 =head2 _icount_loop
144  
145 =for sig
146  
147 Signature: (in(n); indx idx(n); indx [o] out(m); PDL_Indx msize => m)
148 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
149 float double ldouble)
150  
151 =for usage
152  
153 $out = _icount_loop($in, $idx, $msize);
154 _icount_loop($in, $idx, $out, $msize); # all arguments given
155 $out = $in->_icount_loop($idx, $msize); # method call
156 $in->_icount_loop($idx, $out, $msize);
157  
158 Count the number of elements in each bin.
159  
160 This function returns a piddle of type I<indx> if you have a 64-bit-capable
161 PDL, otherwise it returns a piddle of type I<long>.
162  
163 =pod
164  
165 Broadcasts over its inputs.
166  
167 =for bad
168  
169 C<_icount_loop> processes bad values.
170 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
171  
172 =cut
173  
174  
175  
176  
177 *_icount_loop = \&PDL::_icount_loop;
178  
179  
180  
181  
182  
183  
184 =head2 _imax_loop
185  
186 =for sig
187  
188 Signature: (in(n); indx idx(n); [o] out(m); PDL_Indx msize => m)
189 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
190 float double ldouble)
191  
192 =for usage
193  
194 $out = _imax_loop($in, $idx, $msize);
195 _imax_loop($in, $idx, $out, $msize); # all arguments given
196 $out = $in->_imax_loop($idx, $msize); # method call
197 $in->_imax_loop($idx, $out, $msize);
198  
199 =for ref
200  
201 Find the maximum in each bin.
202  
203 =pod
204  
205 Broadcasts over its inputs.
206  
207 =for bad
208  
209 C<_imax_loop> processes bad values.
210 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
211  
212 =cut
213  
214  
215  
216  
217 *_imax_loop = \&PDL::_imax_loop;
218  
219  
220  
221  
222  
223  
224 =head2 _imin_loop
225  
226 =for sig
227  
228 Signature: (in(n); indx idx(n); [o] out(m); PDL_Indx msize => m)
229 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
230 float double ldouble)
231  
232 =for usage
233  
234 $out = _imin_loop($in, $idx, $msize);
235 _imin_loop($in, $idx, $out, $msize); # all arguments given
236 $out = $in->_imin_loop($idx, $msize); # method call
237 $in->_imin_loop($idx, $out, $msize);
238  
239 =for ref
240  
241 Find the minimum in each bin.
242  
243 =pod
244  
245 Broadcasts over its inputs.
246  
247 =for bad
248  
249 C<_imin_loop> processes bad values.
250 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
251  
252 =cut
253  
254  
255  
256  
257 *_imin_loop = \&PDL::_imin_loop;
258  
259  
260  
261  
262  
263  
264 =head2 _isum_loop
265  
266 =for sig
267  
268 Signature: (in(n); indx idx(n); int+ [o] out(m); indx [t] count(m); PDL_Indx msize => m)
269 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
270 float double ldouble)
271  
272 =for usage
273  
274 $out = _isum_loop($in, $idx, $msize);
275 _isum_loop($in, $idx, $out, $msize); # all arguments given
276 $out = $in->_isum_loop($idx, $msize); # method call
277 $in->_isum_loop($idx, $out, $msize);
278  
279 Sum the elements in each bin.
280  
281 This function returns a piddle of type I<int> or higher, to reduce the risk of
282 overflow when collecting sums.
283  
284 =pod
285  
286 Broadcasts over its inputs.
287  
288 =for bad
289  
290 C<_isum_loop> processes bad values.
291 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
292  
293 =cut
294  
295  
296  
297  
298 *_isum_loop = \&PDL::_isum_loop;
299  
300  
301  
302  
303  
304  
305 =head2 _iavg_loop
306  
307 =for sig
308  
309 Signature: (in(n); indx idx(n); double [o] out(m); indx [t] count(m); PDL_Indx msize => m)
310 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
311 float double ldouble)
312  
313 =for usage
314  
315 $out = _iavg_loop($in, $idx, $msize);
316 _iavg_loop($in, $idx, $out, $msize); # all arguments given
317 $out = $in->_iavg_loop($idx, $msize); # method call
318 $in->_iavg_loop($idx, $out, $msize);
319  
320 Compute the average of the elements in each bin.
321  
322 Credit for the algorithm goes to
323 L<I<ashawley> on commandlinefu.com|http://www.commandlinefu.com/commands/view/3437/compute-running-average-for-a-column-of-numbers>:
324  
325 awk '{ avg += ($1 - avg) / NR } END { print avg }'
326  
327 This is a wonderful solution solving many of the problems with more naive
328 implementations:
329  
330 =over 4
331  
332 =item 1.
333  
334 It's numerically well-behaved: out() is always of the order of magnitude of the
335 values themselves, unlike the sum of the values, which grows very large as the
336 number of elements grows large.
337  
338 =item 2.
339  
340 The subtraction in() - out() guarantees that the computation will be done in
341 the correct type (i.e., I<double> instead of the type of the input).
342  
343 =item 3.
344  
345 Requires only one temporary.
346  
347 =item 4.
348  
349 Requires only one pass over the data.
350  
351 =back
352  
353 I used to give the output array type I<float+>, but that creates more problems
354 than it solves. So now, averages are always computed in type I<double>. Besides
355 being the default type in PDL and the 'natural' floating-point type in C, it
356 also makes the implementation easier.
357  
358 =pod
359  
360 Broadcasts over its inputs.
361  
362 =for bad
363  
364 C<_iavg_loop> processes bad values.
365 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
366  
367 =cut
368  
369  
370  
371  
372 *_iavg_loop = \&PDL::_iavg_loop;
373  
374  
375  
376  
377  
378  
379 =head2 _istddev_loop
380  
381 =for sig
382  
383 Signature: (in(n); indx idx(n); double [o] out(m); indx [t] count(m); double [t] avg(m); PDL_Indx msize => m)
384 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
385 float double ldouble)
386  
387 =for usage
388  
389 $out = _istddev_loop($in, $idx, $msize);
390 _istddev_loop($in, $idx, $out, $msize); # all arguments given
391 $out = $in->_istddev_loop($idx, $msize); # method call
392 $in->_istddev_loop($idx, $out, $msize);
393  
394 Compute the standard deviation of the elements in each bin.
395  
396 Note that we compute the sample standard deviation, I<not> an estimate of the
397 population standard deviation (which differs by a factor).
398  
399 Credit for the algorithm goes to
400 L<I<ashawley> on commandlinefu.com|http://www.commandlinefu.com/commands/view/3442/display-the-standard-deviation-of-a-column-of-numbers-with-awk>;
401  
402 awk '{ delta = $1 - avg; avg += delta / NR; mean2 += delta * ($1 - avg) } END { print sqrt(mean2 / NR) }'
403  
404 This is a wonderful solution solving many of the problems with more naive
405 implementations:
406  
407 =over 4
408  
409 =item 1.
410  
411 It's numerically well-behaved.
412  
413 =item 2.
414  
415 The subtractions guarantee that the computations will be done in the correct
416 type (i.e., I<double> instead of the type of the input).
417  
418 =item 3.
419  
420 Requires only two temporaries (!).
421  
422 =item 4.
423  
424 Requires only one pass over the data.
425  
426 =back
427  
428 I used to give the output array type I<float+>, but that creates more problems
429 than it solves. So now, standard deviations are always computed in type
430 I<double>. Besides being the default type in PDL and the 'natural'
431 floating-point type in C, it also makes the implementation easier.
432  
433 =pod
434  
435 Broadcasts over its inputs.
436  
437 =for bad
438  
439 C<_istddev_loop> processes bad values.
440 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
441  
442 =cut
443  
444  
445  
446  
447 *_istddev_loop = \&PDL::_istddev_loop;
448  
449  
450  
451  
452  
453  
454 =head2 _istddev_post
455  
456 =for sig
457  
458 Signature: (in(); indx count(); [o] out())
459 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
460 float double ldouble)
461  
462 =for usage
463  
464 $out = _istddev_post($in, $count);
465 _istddev_post($in, $count, $out); # all arguments given
466 $out = $in->_istddev_post($count); # method call
467 $in->_istddev_post($count, $out);
468 $in->inplace->_istddev_post($count); # can be used inplace
469 _istddev_post($in->inplace, $count);
470  
471 =for ref
472  
473 Finalization for _istddev_loop().
474  
475 =pod
476  
477 Can operate inplace with C<in> as output C<out>.
478 Broadcasts over its inputs.
479  
480 =for bad
481  
482 C<_istddev_post> processes bad values.
483 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
484  
485 =cut
486  
487  
488  
489  
490 *_istddev_post = \&PDL::_istddev_post;
491  
492  
493  
494  
495  
496 #line 335 "actions.pd"
497  
498 =head1 AUTHOR
499  
500 Edward Baudrez <ebaudrez@cpan.org>
501  
502 =head1 COPYRIGHT AND LICENSE
503  
504 This software is copyright (c) 2014 by Edward Baudrez.
505  
506 This is free software; you can redistribute it and/or modify it under
507 the same terms as the Perl 5 programming language system itself.
508  
509 =cut
510 #line 511 "Actions_PP.pm"
511  
512 # Exit with OK status
513  
514 1;
« NDBin.pm ↑ Summary