lib/PDL/Ufunc.pm

filter: Statementstmt 100% 14 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 17 / 17 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« lib/PDL/Slices.pm ↑ Summary
1 #
2 # GENERATED WITH PDL::PP from lib/PDL/Ufunc.pd! Don't modify!
3 #
4 package PDL::Ufunc;
5  
6 71 our @EXPORT_OK = qw(prodover dprodover cumuprodover dcumuprodover sumover dsumover cumusumover dcumusumover andover bandover borover bxorover firstnonzeroover orover xorover zcover numdiff diffcentred partial diff2 intover average caverage daverage minimum minimum_ind minimum_n_ind maximum maximum_ind maximum_n_ind minmaximum avg sum prod davg dsum dprod zcheck and band or bor xorall bxor min max median mode oddmedian any all minmax medover oddmedover modeover pctover oddpctover pct oddpct qsort qsorti qsortvec qsortveci magnover );
7 71 our %EXPORT_TAGS = (Func=>\@EXPORT_OK);
8  
9 71 ▶use PDL::Core;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 71 ▶use PDL::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 71 ▶use DynaLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14
15 71 our @ISA = ( 'PDL::Exporter','DynaLoader' );
16 71 push @PDL::Core::PP, __PACKAGE__;
17 71 bootstrap PDL::Ufunc ;
18  
19  
20  
21  
22  
23  
24  
25  
26 #line 9 "lib/PDL/Ufunc.pd"
27  
28 use strict;
29 use warnings;
30  
31 =encoding utf8
32  
33 =head1 NAME
34  
35 PDL::Ufunc - primitive ufunc operations for pdl
36  
37 =head1 DESCRIPTION
38  
39 This module provides some primitive and useful functions defined
40 using PDL::PP based on functionality of what are sometimes called
41 I<ufuncs> (for example NumPY and Mathematica talk about these).
42 It collects all the functions generally used to C<reduce> or
43 C<accumulate> along a dimension. These all do their job across the
44 first dimension but by using the slicing functions you can do it
45 on any dimension.
46  
47 The L<PDL::Reduce> module provides an alternative interface
48 to many of the functions in this module.
49  
50 =head1 SYNOPSIS
51  
52 use PDL::Ufunc;
53  
54 =cut
55  
56 use PDL::Slices;
57 use Carp;
58 #line 59 "lib/PDL/Ufunc.pm"
59  
60  
61 =head1 FUNCTIONS
62  
63 =cut
64  
65  
66  
67  
68  
69  
70 =head2 prodover
71  
72 =for sig
73  
74 Signature: (a(n); int+ [o]b())
75 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
76 float double ldouble cfloat cdouble cldouble)
77  
78 =for usage
79  
80 $b = prodover($a);
81 prodover($a, $b); # all arguments given
82 $b = $a->prodover; # method call
83 $a->prodover($b);
84  
85 =for ref
86  
87 Project via product to N-1 dimensions
88  
89 This function reduces the dimensionality of an ndarray
90 by one by taking the product along the 1st dimension.
91  
92 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
93 I<any> dimension.
94  
95 =pod
96  
97 Broadcasts over its inputs.
98  
99 =for bad
100  
101 C<prodover> processes bad values.
102 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
103  
104 =cut
105  
106  
107  
108  
109 *prodover = \&PDL::prodover;
110  
111  
112  
113  
114  
115  
116 =head2 dprodover
117  
118 =for sig
119  
120 Signature: (a(n); double [o]b())
121 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
122 float double ldouble)
123  
124 =for usage
125  
126 $b = dprodover($a);
127 dprodover($a, $b); # all arguments given
128 $b = $a->dprodover; # method call
129 $a->dprodover($b);
130  
131 =for ref
132  
133 Project via product to N-1 dimensions
134  
135 This function reduces the dimensionality of an ndarray
136 by one by taking the product along the 1st dimension.
137  
138 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
139 I<any> dimension.
140  
141 Unlike L</prodover>, the calculations are performed in double precision.
142  
143 =pod
144  
145 Broadcasts over its inputs.
146  
147 =for bad
148  
149 C<dprodover> processes bad values.
150 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
151  
152 =cut
153  
154  
155  
156  
157 *dprodover = \&PDL::dprodover;
158  
159  
160  
161  
162  
163  
164 =head2 cumuprodover
165  
166 =for sig
167  
168 Signature: (a(n); int+ [o]b(n))
169 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
170 float double ldouble cfloat cdouble cldouble)
171  
172 =for usage
173  
174 $b = cumuprodover($a);
175 cumuprodover($a, $b); # all arguments given
176 $b = $a->cumuprodover; # method call
177 $a->cumuprodover($b);
178  
179 =for ref
180  
181 Cumulative product
182  
183 This function calculates the cumulative product
184 along the 1st dimension.
185  
186 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
187 I<any> dimension.
188  
189 The sum is started so that the first element in the cumulative product
190 is the first element of the parameter.
191  
192 =pod
193  
194 Broadcasts over its inputs.
195  
196 =for bad
197  
198 C<cumuprodover> processes bad values.
199 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
200  
201 =cut
202  
203  
204  
205  
206 *cumuprodover = \&PDL::cumuprodover;
207  
208  
209  
210  
211  
212  
213 =head2 dcumuprodover
214  
215 =for sig
216  
217 Signature: (a(n); double [o]b(n))
218 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
219 float double ldouble)
220  
221 =for usage
222  
223 $b = dcumuprodover($a);
224 dcumuprodover($a, $b); # all arguments given
225 $b = $a->dcumuprodover; # method call
226 $a->dcumuprodover($b);
227  
228 =for ref
229  
230 Cumulative product
231  
232 This function calculates the cumulative product
233 along the 1st dimension.
234  
235 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
236 I<any> dimension.
237  
238 The sum is started so that the first element in the cumulative product
239 is the first element of the parameter.
240  
241 Unlike L</cumuprodover>, the calculations are performed in double precision.
242  
243 =pod
244  
245 Broadcasts over its inputs.
246  
247 =for bad
248  
249 C<dcumuprodover> 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 *dcumuprodover = \&PDL::dcumuprodover;
258  
259  
260  
261  
262  
263  
264 =head2 sumover
265  
266 =for sig
267  
268 Signature: (a(n); int+ [o]b())
269 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
270 float double ldouble cfloat cdouble cldouble)
271  
272 =for usage
273  
274 $b = sumover($a);
275 sumover($a, $b); # all arguments given
276 $b = $a->sumover; # method call
277 $a->sumover($b);
278  
279 =for ref
280  
281 Project via sum to N-1 dimensions
282  
283 This function reduces the dimensionality of an ndarray
284 by one by taking the sum along the 1st dimension.
285  
286 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
287 I<any> dimension.
288  
289 =pod
290  
291 Broadcasts over its inputs.
292  
293 =for bad
294  
295 C<sumover> processes bad values.
296 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
297  
298 =cut
299  
300  
301  
302  
303 *sumover = \&PDL::sumover;
304  
305  
306  
307  
308  
309  
310 =head2 dsumover
311  
312 =for sig
313  
314 Signature: (a(n); double [o]b())
315 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
316 float double ldouble)
317  
318 =for usage
319  
320 $b = dsumover($a);
321 dsumover($a, $b); # all arguments given
322 $b = $a->dsumover; # method call
323 $a->dsumover($b);
324  
325 =for ref
326  
327 Project via sum to N-1 dimensions
328  
329 This function reduces the dimensionality of an ndarray
330 by one by taking the sum along the 1st dimension.
331  
332 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
333 I<any> dimension.
334  
335 Unlike L</sumover>, the calculations are performed in double precision.
336  
337 =pod
338  
339 Broadcasts over its inputs.
340  
341 =for bad
342  
343 C<dsumover> processes bad values.
344 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
345  
346 =cut
347  
348  
349  
350  
351 *dsumover = \&PDL::dsumover;
352  
353  
354  
355  
356  
357  
358 =head2 cumusumover
359  
360 =for sig
361  
362 Signature: (a(n); int+ [o]b(n))
363 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
364 float double ldouble cfloat cdouble cldouble)
365  
366 =for usage
367  
368 $b = cumusumover($a);
369 cumusumover($a, $b); # all arguments given
370 $b = $a->cumusumover; # method call
371 $a->cumusumover($b);
372  
373 =for ref
374  
375 Cumulative sum
376  
377 This function calculates the cumulative sum
378 along the 1st dimension.
379  
380 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
381 I<any> dimension.
382  
383 The sum is started so that the first element in the cumulative sum
384 is the first element of the parameter.
385  
386 =pod
387  
388 Broadcasts over its inputs.
389  
390 =for bad
391  
392 C<cumusumover> processes bad values.
393 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
394  
395 =cut
396  
397  
398  
399  
400 *cumusumover = \&PDL::cumusumover;
401  
402  
403  
404  
405  
406  
407 =head2 dcumusumover
408  
409 =for sig
410  
411 Signature: (a(n); double [o]b(n))
412 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
413 float double ldouble)
414  
415 =for usage
416  
417 $b = dcumusumover($a);
418 dcumusumover($a, $b); # all arguments given
419 $b = $a->dcumusumover; # method call
420 $a->dcumusumover($b);
421  
422 =for ref
423  
424 Cumulative sum
425  
426 This function calculates the cumulative sum
427 along the 1st dimension.
428  
429 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
430 I<any> dimension.
431  
432 The sum is started so that the first element in the cumulative sum
433 is the first element of the parameter.
434  
435 Unlike L</cumusumover>, the calculations are performed in double precision.
436  
437 =pod
438  
439 Broadcasts over its inputs.
440  
441 =for bad
442  
443 C<dcumusumover> processes bad values.
444 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
445  
446 =cut
447  
448  
449  
450  
451 *dcumusumover = \&PDL::dcumusumover;
452  
453  
454  
455  
456  
457  
458 =head2 andover
459  
460 =for sig
461  
462 Signature: (a(n); [o] b())
463 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
464 float double ldouble cfloat cdouble cldouble)
465  
466 =for usage
467  
468 $b = andover($a);
469 andover($a, $b); # all arguments given
470 $b = $a->andover; # method call
471 $a->andover($b);
472  
473 =for ref
474  
475 Project via logical and to N-1 dimensions
476  
477 This function reduces the dimensionality of an ndarray
478 by one by taking the logical and along the 1st dimension.
479  
480 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
481 I<any> dimension.
482  
483 =pod
484  
485 Broadcasts over its inputs.
486  
487 =for bad
488  
489 If C<a()> contains only bad data (and its bad flag is set),
490 C<b()> is set bad. Otherwise C<b()> will have its bad flag cleared,
491 as it will not contain any bad values.
492  
493 =cut
494  
495  
496  
497  
498 *andover = \&PDL::andover;
499  
500  
501  
502  
503  
504  
505 =head2 bandover
506  
507 =for sig
508  
509 Signature: (a(n); [o] b())
510 Types: (sbyte byte short ushort long ulong indx ulonglong longlong)
511  
512 =for usage
513  
514 $b = bandover($a);
515 bandover($a, $b); # all arguments given
516 $b = $a->bandover; # method call
517 $a->bandover($b);
518  
519 =for ref
520  
521 Project via bitwise and to N-1 dimensions
522  
523 This function reduces the dimensionality of an ndarray
524 by one by taking the bitwise and along the 1st dimension.
525  
526 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
527 I<any> dimension.
528  
529 =pod
530  
531 Broadcasts over its inputs.
532  
533 =for bad
534  
535 If C<a()> contains only bad data (and its bad flag is set),
536 C<b()> is set bad. Otherwise C<b()> will have its bad flag cleared,
537 as it will not contain any bad values.
538  
539 =cut
540  
541  
542  
543  
544 *bandover = \&PDL::bandover;
545  
546  
547  
548  
549  
550  
551 =head2 borover
552  
553 =for sig
554  
555 Signature: (a(n); [o] b())
556 Types: (sbyte byte short ushort long ulong indx ulonglong longlong)
557  
558 =for usage
559  
560 $b = borover($a);
561 borover($a, $b); # all arguments given
562 $b = $a->borover; # method call
563 $a->borover($b);
564  
565 =for ref
566  
567 Project via bitwise or to N-1 dimensions
568  
569 This function reduces the dimensionality of an ndarray
570 by one by taking the bitwise or along the 1st dimension.
571  
572 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
573 I<any> dimension.
574  
575 =pod
576  
577 Broadcasts over its inputs.
578  
579 =for bad
580  
581 If C<a()> contains only bad data (and its bad flag is set),
582 C<b()> is set bad. Otherwise C<b()> will have its bad flag cleared,
583 as it will not contain any bad values.
584  
585 =cut
586  
587  
588  
589  
590 *borover = \&PDL::borover;
591  
592  
593  
594  
595  
596  
597 =head2 bxorover
598  
599 =for sig
600  
601 Signature: (a(n); [o] b())
602 Types: (sbyte byte short ushort long ulong indx ulonglong longlong)
603  
604 =for usage
605  
606 $b = bxorover($a);
607 bxorover($a, $b); # all arguments given
608 $b = $a->bxorover; # method call
609 $a->bxorover($b);
610  
611 =for ref
612  
613 Project via bitwise xor to N-1 dimensions
614  
615 This function reduces the dimensionality of an ndarray
616 by one by taking the bitwise xor along the 1st dimension.
617  
618 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
619 I<any> dimension.
620  
621 =pod
622  
623 Broadcasts over its inputs.
624  
625 =for bad
626  
627 If C<a()> contains only bad data (and its bad flag is set),
628 C<b()> is set bad. Otherwise C<b()> will have its bad flag cleared,
629 as it will not contain any bad values.
630  
631 =cut
632  
633  
634  
635  
636 *bxorover = \&PDL::bxorover;
637  
638  
639  
640  
641  
642  
643 =head2 firstnonzeroover
644  
645 =for sig
646  
647 Signature: (a(n); [o] b())
648 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
649 float double ldouble cfloat cdouble cldouble)
650  
651 =for usage
652  
653 $b = firstnonzeroover($a);
654 firstnonzeroover($a, $b); # all arguments given
655 $b = $a->firstnonzeroover; # method call
656 $a->firstnonzeroover($b);
657  
658 =for ref
659  
660 Project via first non-zero value to N-1 dimensions
661  
662 This function reduces the dimensionality of an ndarray
663 by one by taking the first non-zero value along the 1st dimension.
664  
665 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
666 I<any> dimension.
667  
668 =pod
669  
670 Broadcasts over its inputs.
671  
672 =for bad
673  
674 If C<a()> contains only bad data (and its bad flag is set),
675 C<b()> is set bad. Otherwise C<b()> will have its bad flag cleared,
676 as it will not contain any bad values.
677  
678 =cut
679  
680  
681  
682  
683 *firstnonzeroover = \&PDL::firstnonzeroover;
684  
685  
686  
687  
688  
689  
690 =head2 orover
691  
692 =for sig
693  
694 Signature: (a(n); [o] b())
695 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
696 float double ldouble cfloat cdouble cldouble)
697  
698 =for usage
699  
700 $b = orover($a);
701 orover($a, $b); # all arguments given
702 $b = $a->orover; # method call
703 $a->orover($b);
704  
705 =for ref
706  
707 Project via logical or to N-1 dimensions
708  
709 This function reduces the dimensionality of an ndarray
710 by one by taking the logical or along the 1st dimension.
711  
712 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
713 I<any> dimension.
714  
715 =pod
716  
717 Broadcasts over its inputs.
718  
719 =for bad
720  
721 If C<a()> contains only bad data (and its bad flag is set),
722 C<b()> is set bad. Otherwise C<b()> will have its bad flag cleared,
723 as it will not contain any bad values.
724  
725 =cut
726  
727  
728  
729  
730 *orover = \&PDL::orover;
731  
732  
733  
734  
735  
736  
737 =head2 xorover
738  
739 =for sig
740  
741 Signature: (a(n); [o] b())
742 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
743 float double ldouble cfloat cdouble cldouble)
744  
745 =for usage
746  
747 $b = xorover($a);
748 xorover($a, $b); # all arguments given
749 $b = $a->xorover; # method call
750 $a->xorover($b);
751  
752 =for ref
753  
754 Project via logical xor to N-1 dimensions
755  
756 This function reduces the dimensionality of an ndarray
757 by one by taking the logical xor along the 1st dimension.
758  
759 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
760 I<any> dimension.
761  
762 =pod
763  
764 Broadcasts over its inputs.
765  
766 =for bad
767  
768 If C<a()> contains only bad data (and its bad flag is set),
769 C<b()> is set bad. Otherwise C<b()> will have its bad flag cleared,
770 as it will not contain any bad values.
771  
772 =cut
773  
774  
775  
776  
777 *xorover = \&PDL::xorover;
778  
779  
780  
781  
782  
783  
784 =head2 zcover
785  
786 =for sig
787  
788 Signature: (a(n); [o] b())
789 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
790 float double ldouble cfloat cdouble cldouble)
791  
792 =for usage
793  
794 $b = zcover($a);
795 zcover($a, $b); # all arguments given
796 $b = $a->zcover; # method call
797 $a->zcover($b);
798  
799 =for ref
800  
801 Project via == 0 to N-1 dimensions
802  
803 This function reduces the dimensionality of an ndarray
804 by one by taking the == 0 along the 1st dimension.
805  
806 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
807 I<any> dimension.
808  
809 =pod
810  
811 Broadcasts over its inputs.
812  
813 =for bad
814  
815 If C<a()> contains only bad data (and its bad flag is set),
816 C<b()> is set bad. Otherwise C<b()> will have its bad flag cleared,
817 as it will not contain any bad values.
818  
819 =cut
820  
821  
822  
823  
824 *zcover = \&PDL::zcover;
825  
826  
827  
828  
829  
830  
831 =head2 numdiff
832  
833 =for sig
834  
835 Signature: (x(t); [o]dx(t))
836 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
837 float double ldouble cfloat cdouble cldouble)
838  
839 =for usage
840  
841 $dx = numdiff($x);
842 numdiff($x, $dx); # all arguments given
843 $dx = $x->numdiff; # method call
844 $x->numdiff($dx);
845 $x->inplace->numdiff; # can be used inplace
846 numdiff($x->inplace);
847  
848 =for ref
849  
850 Numerical differencing. DX(t) = X(t) - X(t-1), DX(0) = X(0).
851 Combined with C<slice('-1:0')>, can be used for backward differencing.
852  
853 Unlike L</diff2>, output vector is same length.
854 Originally by Maggie J. Xiong.
855  
856 Compare to L</cumusumover>, which acts as the converse of this.
857 See also L</diff2>, L</diffcentred>, L</partial>, L<PDL::Primitive/pchip_chim>.
858  
859 =pod
860  
861 Can operate inplace with C<x> as output C<dx>.
862 Broadcasts over its inputs.
863  
864 =for bad
865  
866 C<numdiff> does not process bad values.
867 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
868  
869 =cut
870  
871  
872  
873  
874 *numdiff = \&PDL::numdiff;
875  
876  
877  
878  
879  
880  
881 =head2 diffcentred
882  
883 =for sig
884  
885 Signature: (a(n); [o]o(n))
886 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
887 float double ldouble cfloat cdouble cldouble)
888  
889 =for usage
890  
891 $o = diffcentred($a);
892 diffcentred($a, $o); # all arguments given
893 $o = $a->diffcentred; # method call
894 $a->diffcentred($o);
895  
896 =for ref
897  
898 Calculates centred differences along a vector's 0th dimension.
899 Always periodic on boundaries; currently to change this, you must
900 pad your data, and/or trim afterwards. This is so that when using
901 with L</partial>, the size of data stays the same and therefore
902 compatible if differentiated along different dimensions, e.g.
903 calculating "curl".
904  
905 By using L<PDL::Slices/xchg> etc. it is possible to use I<any> dimension.
906  
907 See also L</diff2>, L</partial>, L</numdiff>, L<PDL::Primitive/pchip_chim>.
908  
909 =pod
910  
911 Broadcasts over its inputs.
912  
913 =for bad
914  
915 A bad value at C<n> means the affected output values at C<n-2>,C<n>
916 (if in boounds) are set bad.
917  
918 =cut
919  
920  
921  
922  
923 *diffcentred = \&PDL::diffcentred;
924  
925  
926  
927  
928  
929 #line 249 "lib/PDL/Ufunc.pd"
930  
931 =head2 partial
932  
933 =for ref
934  
935 Take a numerical partial derivative along a given dimension, either
936 forward, backward, or centred.
937  
938 See also L</numdiff>, L</diffcentred>,
939 L<PDL::Primitive/pchip_chim>, L<PDL::Primitive/pchip_chsp>,
940 and L<PDL::Slices/mv>, which are currently used to implement this.
941  
942 Can be used to implement divergence and curl calculations (adapted
943 from Luis Mochán's work at
944 https://sourceforge.net/p/pdl/mailman/message/58843767/):
945  
946 use v5.36;
947 use PDL;
948 sub curl ($f) {
949 my ($f0, $f1, $f2) = $f->using(0..2);
950 my $o = {dir=>'c'};
951 pdl(
952 $f2->partial(1,$o) - $f1->partial(2,$o),
953 $f0->partial(2,$o) - $f2->partial(0,$o),
954 $f1->partial(0,$o) - $f0->partial(1,$o),
955 )->mv(-1,0);
956 }
957 sub div ($f) {
958 my ($f0, $f1, $f2) = $f->using(0..2);
959 my $o = {dir=>'c'};
960 $f0->partial(0,$o) + $f1->partial(1,$o) + $f2->partial(2,$o);
961 }
962 sub trim3d ($f) { $f->slice(':,1:-2,1:-2,1:-2') } # adjust if change "dir"
963 my $z=zeroes(5,5,5);
964 my $v=pdl(-$z->yvals, $z->xvals, $z->zvals)->mv(-1,0);
965 say trim3d(curl($v));
966 say div($v);
967  
968 =for usage
969  
970 $pdl->partial(2); # along dim 2, centred
971 $pdl->partial(2, {d=>'c'}); # along dim 2, centred
972 $pdl->partial(2, {d=>'f'}); # along dim 2, forward
973 $pdl->partial(2, {d=>'b'}); # along dim 2, backward
974 $pdl->partial(2, {d=>'p'}); # along dim 2, piecewise cubic Hermite
975 $pdl->partial(2, {d=>'s'}); # along dim 2, cubic spline
976  
977 =cut
978  
979 my %dirtype2func = (
980 f => \&numdiff,
981 b => sub { $_[0]->slice('-1:0')->numdiff },
982 c => \&diffcentred,
983 p => sub {(PDL::Primitive::pchip_chim($_[0]->xvals, $_[0]))[0]},
984 s => sub {(PDL::Primitive::pchip_chsp([0,0], [0,0], $_[0]->xvals, $_[0]))[0]},
985 );
986 *partial = \&PDL::partial;
987 sub PDL::partial {
988 my ($f, $dim, $opts) = @_;
989 $opts ||= {};
990 my $difftype = $opts->{dir} || $opts->{d} || 'c';
991 my $func = $dirtype2func{$difftype} || barf "partial: unknown 'dir' option '$difftype', only know (@{[sort keys %dirtype2func]})";
992 $f = $f->mv($dim, 0) if $dim;
993 my $ret = $f->$func;
994 $dim ? $ret->mv(0, $dim) : $ret;
995 }
996 #line 997 "lib/PDL/Ufunc.pm"
997  
998  
999 =head2 diff2
1000  
1001 =for sig
1002  
1003 Signature: (a(n); [o]o(nminus1=CALC($SIZE(n) - 1)))
1004 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
1005 float double ldouble cfloat cdouble cldouble)
1006  
1007 =for usage
1008  
1009 $o = diff2($a);
1010 diff2($a, $o); # all arguments given
1011 $o = $a->diff2; # method call
1012 $a->diff2($o);
1013  
1014 =for ref
1015  
1016 Numerically forward differentiates a vector along 0th dimension.
1017  
1018 By using L<PDL::Slices/xchg> etc. it is possible to use I<any> dimension.
1019 Unlike L</numdiff>, output vector is one shorter.
1020 Combined with C<slice('-1:0')>, can be used for backward differencing.
1021  
1022 See also L</numdiff>, L</diffcentred>, L</partial>, L<PDL::Primitive/pchip_chim>.
1023  
1024 =for example
1025  
1026 print pdl(q[3 4 2 3 2 3 1])->diff2;
1027 # [1 -2 1 -1 1 -2]
1028  
1029 =pod
1030  
1031 Broadcasts over its inputs.
1032  
1033 =for bad
1034  
1035 On bad value, output value is set bad. On next good value, output value
1036 is difference between that and last good value.
1037  
1038 =cut
1039  
1040  
1041  
1042  
1043 *diff2 = \&PDL::diff2;
1044  
1045  
1046  
1047  
1048  
1049  
1050 =head2 intover
1051  
1052 =for sig
1053  
1054 Signature: (a(n); float+ [o]b())
1055 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
1056 float double ldouble)
1057  
1058 =for usage
1059  
1060 $b = intover($a);
1061 intover($a, $b); # all arguments given
1062 $b = $a->intover; # method call
1063 $a->intover($b);
1064  
1065 =for ref
1066  
1067 Project via integral to N-1 dimensions
1068  
1069 This function reduces the dimensionality of an ndarray
1070 by one by taking the integral along the 1st dimension.
1071  
1072 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
1073 I<any> dimension.
1074  
1075 Notes:
1076  
1077 C<intover> uses a point spacing of one (i.e., delta-h==1). You will
1078 need to scale the result to correct for the true point delta.
1079  
1080 For C<n E<gt> 3>, these are all C<O(h^4)> (like Simpson's rule), but are
1081 integrals between the end points assuming the pdl gives values just at
1082 these centres: for such `functions', sumover is correct to C<O(h)>, but
1083 is the natural (and correct) choice for binned data, of course.
1084  
1085 =pod
1086  
1087 Broadcasts over its inputs.
1088  
1089 =for bad
1090  
1091 C<intover> ignores the bad-value flag of the input ndarrays.
1092 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1093  
1094 =cut
1095  
1096  
1097  
1098  
1099 *intover = \&PDL::intover;
1100  
1101  
1102  
1103  
1104  
1105  
1106 =head2 average, avgover
1107  
1108 =for sig
1109  
1110 Signature: (a(n); int+ [o]b())
1111 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
1112 float double ldouble)
1113  
1114 =for usage
1115  
1116 $b = average($a);
1117 average($a, $b); # all arguments given
1118 $b = $a->average; # method call
1119 $a->average($b);
1120  
1121 =for ref
1122  
1123 Project via average to N-1 dimensions
1124  
1125 This function reduces the dimensionality of an ndarray
1126 by one by taking the average along the 1st dimension.
1127  
1128 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
1129 I<any> dimension.
1130  
1131 =pod
1132  
1133 Broadcasts over its inputs.
1134  
1135 =for bad
1136  
1137 C<average> processes bad values.
1138 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1139  
1140 =cut
1141  
1142  
1143  
1144  
1145 *average = \&PDL::average;
1146 *PDL::avgover = *avgover = \&PDL::average;
1147  
1148  
1149  
1150  
1151  
1152  
1153 =head2 caverage, cavgover
1154  
1155 =for sig
1156  
1157 Signature: (a(n); cdouble [o]b())
1158 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
1159 float double ldouble)
1160  
1161 =for usage
1162  
1163 $b = caverage($a);
1164 caverage($a, $b); # all arguments given
1165 $b = $a->caverage; # method call
1166 $a->caverage($b);
1167  
1168 =for ref
1169  
1170 Project via average to N-1 dimensions
1171  
1172 This function reduces the dimensionality of an ndarray
1173 by one by taking the average along the 1st dimension.
1174  
1175 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
1176 I<any> dimension.
1177  
1178 Unlike L<average|/average>, the calculation is performed in complex double
1179 precision.
1180  
1181 =pod
1182  
1183 Broadcasts over its inputs.
1184  
1185 =for bad
1186  
1187 C<caverage> processes bad values.
1188 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1189  
1190 =cut
1191  
1192  
1193  
1194  
1195 *caverage = \&PDL::caverage;
1196 *PDL::cavgover = *cavgover = \&PDL::caverage;
1197  
1198  
1199  
1200  
1201  
1202  
1203 =head2 daverage, davgover
1204  
1205 =for sig
1206  
1207 Signature: (a(n); double [o]b())
1208 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
1209 float double ldouble)
1210  
1211 =for usage
1212  
1213 $b = daverage($a);
1214 daverage($a, $b); # all arguments given
1215 $b = $a->daverage; # method call
1216 $a->daverage($b);
1217  
1218 =for ref
1219  
1220 Project via average to N-1 dimensions
1221  
1222 This function reduces the dimensionality of an ndarray
1223 by one by taking the average along the 1st dimension.
1224  
1225 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
1226 I<any> dimension.
1227  
1228 Unlike L<average|/average>, the calculation is performed in double
1229 precision.
1230  
1231 =pod
1232  
1233 Broadcasts over its inputs.
1234  
1235 =for bad
1236  
1237 C<daverage> processes bad values.
1238 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1239  
1240 =cut
1241  
1242  
1243  
1244  
1245 *daverage = \&PDL::daverage;
1246 *PDL::davgover = *davgover = \&PDL::daverage;
1247  
1248  
1249  
1250  
1251  
1252  
1253 =head2 minimum, minover
1254  
1255 =for sig
1256  
1257 Signature: (a(n); [o]c())
1258 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
1259 float double ldouble)
1260  
1261 =for usage
1262  
1263 $c = minimum($a);
1264 minimum($a, $c); # all arguments given
1265 $c = $a->minimum; # method call
1266 $a->minimum($c);
1267  
1268 =for ref
1269  
1270 Project via minimum to N-1 dimensions
1271  
1272 This function reduces the dimensionality of an ndarray
1273 by one by taking the minimum along the 1st dimension.
1274  
1275 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
1276 I<any> dimension.
1277  
1278 =pod
1279  
1280 Broadcasts over its inputs.
1281  
1282 =for bad
1283  
1284 Output is set bad if no elements of the input are non-bad,
1285 otherwise the bad flag is cleared for the output ndarray.
1286  
1287 Note that C<NaNs> are considered to be valid values and will "win" over non-C<NaN>;
1288 see L<isfinite|PDL::Math/isfinite> and L<badmask|PDL::Bad/badmask>
1289 for ways of masking NaNs.
1290  
1291 =cut
1292  
1293  
1294  
1295  
1296 *minimum = \&PDL::minimum;
1297 *PDL::minover = *minover = \&PDL::minimum;
1298  
1299  
1300  
1301  
1302  
1303  
1304 =head2 minimum_ind, minover_ind
1305  
1306 =for sig
1307  
1308 Signature: (a(n); indx [o] c())
1309 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
1310 float double ldouble)
1311  
1312 =for usage
1313  
1314 $c = minimum_ind($a);
1315 minimum_ind($a, $c); # all arguments given
1316 $c = $a->minimum_ind; # method call
1317 $a->minimum_ind($c);
1318  
1319 =for ref
1320  
1321 Like minimum but returns the first matching index rather than the value
1322  
1323 =pod
1324  
1325 Broadcasts over its inputs.
1326  
1327 =for bad
1328  
1329 Output is set bad if no elements of the input are non-bad,
1330 otherwise the bad flag is cleared for the output ndarray.
1331  
1332 Note that C<NaNs> are considered to be valid values and will "win" over non-C<NaN>;
1333 see L<isfinite|PDL::Math/isfinite> and L<badmask|PDL::Bad/badmask>
1334 for ways of masking NaNs.
1335  
1336 =cut
1337  
1338  
1339  
1340  
1341 *minimum_ind = \&PDL::minimum_ind;
1342 *PDL::minover_ind = *minover_ind = \&PDL::minimum_ind;
1343  
1344  
1345  
1346  
1347  
1348  
1349 =head2 minimum_n_ind, minover_n_ind
1350  
1351 =for sig
1352  
1353 Signature: (a(n); indx [o]c(m); PDL_Indx m_size => m)
1354 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
1355 float double ldouble)
1356  
1357 =for ref
1358  
1359 Returns the index of first C<m_size> minimum elements. As of 2.077, you can
1360 specify how many by either passing in an ndarray of the given size
1361 (DEPRECATED - will be converted to indx if needed and the input arg will
1362 be set to that), or just the size, or a null and the size.
1363  
1364 =for usage
1365  
1366 minimum_n_ind($pdl, $out = zeroes(5)); # DEPRECATED
1367 $out = minimum_n_ind($pdl, 5);
1368 minimum_n_ind($pdl, $out = null, 5);
1369  
1370 =pod
1371  
1372 Broadcasts over its inputs.
1373  
1374 =for bad
1375  
1376 Output bad flag is cleared for the output ndarray if sufficient non-bad elements found,
1377 else remaining slots in C<$c()> are set bad.
1378  
1379 Note that C<NaNs> are considered to be valid values and will "win" over non-C<NaN>;
1380 see L<isfinite|PDL::Math/isfinite> and L<badmask|PDL::Bad/badmask>
1381 for ways of masking NaNs.
1382  
1383 =cut
1384  
1385  
1386  
1387  
1388  
1389 #line 507 "lib/PDL/Ufunc.pd"
1390 sub PDL::minimum_n_ind {
1391 my ($a, $c, $m_size) = @_;
1392 $m_size //= ref($c) ? $c->dim(0) : $c; # back-compat with pre-2.077
1393 my $set_out = 1;
1394 $set_out = 0, $c = null if !ref $c;
1395 $c = $c->indx if !$c->isnull;
1396 PDL::_minimum_n_ind_int($a, $c, $m_size);
1397 $set_out ? $_[1] = $c : $c;
1398 }
1399 #line 1400 "lib/PDL/Ufunc.pm"
1400  
1401 *minimum_n_ind = \&PDL::minimum_n_ind;
1402 *PDL::minover_n_ind = *minover_n_ind = \&PDL::minimum_n_ind;
1403  
1404  
1405  
1406  
1407  
1408  
1409 =head2 maximum, maxover
1410  
1411 =for sig
1412  
1413 Signature: (a(n); [o]c())
1414 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
1415 float double ldouble)
1416  
1417 =for usage
1418  
1419 $c = maximum($a);
1420 maximum($a, $c); # all arguments given
1421 $c = $a->maximum; # method call
1422 $a->maximum($c);
1423  
1424 =for ref
1425  
1426 Project via maximum to N-1 dimensions
1427  
1428 This function reduces the dimensionality of an ndarray
1429 by one by taking the maximum along the 1st dimension.
1430  
1431 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
1432 I<any> dimension.
1433  
1434 =pod
1435  
1436 Broadcasts over its inputs.
1437  
1438 =for bad
1439  
1440 Output is set bad if no elements of the input are non-bad,
1441 otherwise the bad flag is cleared for the output ndarray.
1442  
1443 Note that C<NaNs> are considered to be valid values and will "win" over non-C<NaN>;
1444 see L<isfinite|PDL::Math/isfinite> and L<badmask|PDL::Bad/badmask>
1445 for ways of masking NaNs.
1446  
1447 =cut
1448  
1449  
1450  
1451  
1452 *maximum = \&PDL::maximum;
1453 *PDL::maxover = *maxover = \&PDL::maximum;
1454  
1455  
1456  
1457  
1458  
1459  
1460 =head2 maximum_ind, maxover_ind
1461  
1462 =for sig
1463  
1464 Signature: (a(n); indx [o] c())
1465 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
1466 float double ldouble)
1467  
1468 =for usage
1469  
1470 $c = maximum_ind($a);
1471 maximum_ind($a, $c); # all arguments given
1472 $c = $a->maximum_ind; # method call
1473 $a->maximum_ind($c);
1474  
1475 =for ref
1476  
1477 Like maximum but returns the first matching index rather than the value
1478  
1479 =pod
1480  
1481 Broadcasts over its inputs.
1482  
1483 =for bad
1484  
1485 Output is set bad if no elements of the input are non-bad,
1486 otherwise the bad flag is cleared for the output ndarray.
1487  
1488 Note that C<NaNs> are considered to be valid values and will "win" over non-C<NaN>;
1489 see L<isfinite|PDL::Math/isfinite> and L<badmask|PDL::Bad/badmask>
1490 for ways of masking NaNs.
1491  
1492 =cut
1493  
1494  
1495  
1496  
1497 *maximum_ind = \&PDL::maximum_ind;
1498 *PDL::maxover_ind = *maxover_ind = \&PDL::maximum_ind;
1499  
1500  
1501  
1502  
1503  
1504  
1505 =head2 maximum_n_ind, maxover_n_ind
1506  
1507 =for sig
1508  
1509 Signature: (a(n); indx [o]c(m); PDL_Indx m_size => m)
1510 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
1511 float double ldouble)
1512  
1513 =for ref
1514  
1515 Returns the index of first C<m_size> maximum elements. As of 2.077, you can
1516 specify how many by either passing in an ndarray of the given size
1517 (DEPRECATED - will be converted to indx if needed and the input arg will
1518 be set to that), or just the size, or a null and the size.
1519  
1520 =for usage
1521  
1522 maximum_n_ind($pdl, $out = zeroes(5)); # DEPRECATED
1523 $out = maximum_n_ind($pdl, 5);
1524 maximum_n_ind($pdl, $out = null, 5);
1525  
1526 =pod
1527  
1528 Broadcasts over its inputs.
1529  
1530 =for bad
1531  
1532 Output bad flag is cleared for the output ndarray if sufficient non-bad elements found,
1533 else remaining slots in C<$c()> are set bad.
1534  
1535 Note that C<NaNs> are considered to be valid values and will "win" over non-C<NaN>;
1536 see L<isfinite|PDL::Math/isfinite> and L<badmask|PDL::Bad/badmask>
1537 for ways of masking NaNs.
1538  
1539 =cut
1540  
1541  
1542  
1543  
1544  
1545 #line 507 "lib/PDL/Ufunc.pd"
1546 sub PDL::maximum_n_ind {
1547 my ($a, $c, $m_size) = @_;
1548 $m_size //= ref($c) ? $c->dim(0) : $c; # back-compat with pre-2.077
1549 my $set_out = 1;
1550 $set_out = 0, $c = null if !ref $c;
1551 $c = $c->indx if !$c->isnull;
1552 PDL::_maximum_n_ind_int($a, $c, $m_size);
1553 $set_out ? $_[1] = $c : $c;
1554 }
1555 #line 1556 "lib/PDL/Ufunc.pm"
1556  
1557 *maximum_n_ind = \&PDL::maximum_n_ind;
1558 *PDL::maxover_n_ind = *maxover_n_ind = \&PDL::maximum_n_ind;
1559  
1560  
1561  
1562  
1563  
1564  
1565 =head2 minmaximum, minmaxover
1566  
1567 =for sig
1568  
1569 Signature: (a(n); [o]cmin(); [o] cmax(); indx [o]cmin_ind(); indx [o]cmax_ind())
1570 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
1571 float double ldouble)
1572  
1573 =for usage
1574  
1575 ($cmin, $cmax, $cmin_ind, $cmax_ind) = minmaximum($a);
1576 minmaximum($a, $cmin, $cmax, $cmin_ind, $cmax_ind); # all arguments given
1577 ($cmin, $cmax, $cmin_ind, $cmax_ind) = $a->minmaximum; # method call
1578 $a->minmaximum($cmin, $cmax, $cmin_ind, $cmax_ind);
1579  
1580 =for ref
1581  
1582 Find minimum and maximum and their indices for a given ndarray;
1583  
1584 =for example
1585  
1586 pdl> $x=pdl [[-2,3,4],[1,0,3]]
1587 pdl> ($min, $max, $min_ind, $max_ind)=minmaximum($x)
1588 pdl> p $min, $max, $min_ind, $max_ind
1589 [-2 0] [4 3] [0 1] [2 2]
1590  
1591 See also L</minmax>, which clumps the ndarray together.
1592  
1593 =pod
1594  
1595 Broadcasts over its inputs.
1596  
1597 =for bad
1598  
1599 If C<a()> contains only bad data, then the output ndarrays will
1600 be set bad, along with their bad flag.
1601 Otherwise they will have their bad flags cleared,
1602 since they will not contain any bad values.
1603  
1604 =cut
1605  
1606  
1607  
1608  
1609 *minmaximum = \&PDL::minmaximum;
1610 *PDL::minmaxover = *minmaxover = \&PDL::minmaximum;
1611  
1612  
1613  
1614  
1615  
1616 #line 640 "lib/PDL/Ufunc.pd"
1617  
1618 =head2 avg
1619  
1620 =for ref
1621  
1622 Return the average of all elements in an ndarray.
1623  
1624 See the documentation for L</average> for more information.
1625  
1626 =for usage
1627  
1628 $x = avg($data);
1629  
1630 =for bad
1631  
1632 This routine handles bad values.
1633  
1634 =cut
1635  
1636 *avg = \&PDL::avg;
1637 sub PDL::avg { $_[0]->flat->average }
1638  
1639 #line 640 "lib/PDL/Ufunc.pd"
1640  
1641 =head2 sum
1642  
1643 =for ref
1644  
1645 Return the sum of all elements in an ndarray.
1646  
1647 See the documentation for L</sumover> for more information.
1648  
1649 =for usage
1650  
1651 $x = sum($data);
1652  
1653 =for bad
1654  
1655 This routine handles bad values.
1656  
1657 =cut
1658  
1659 *sum = \&PDL::sum;
1660 sub PDL::sum { $_[0]->flat->sumover }
1661  
1662 #line 640 "lib/PDL/Ufunc.pd"
1663  
1664 =head2 prod
1665  
1666 =for ref
1667  
1668 Return the product of all elements in an ndarray.
1669  
1670 See the documentation for L</prodover> for more information.
1671  
1672 =for usage
1673  
1674 $x = prod($data);
1675  
1676 =for bad
1677  
1678 This routine handles bad values.
1679  
1680 =cut
1681  
1682 *prod = \&PDL::prod;
1683 sub PDL::prod { $_[0]->flat->prodover }
1684  
1685 #line 640 "lib/PDL/Ufunc.pd"
1686  
1687 =head2 davg
1688  
1689 =for ref
1690  
1691 Return the average (in double precision) of all elements in an ndarray.
1692  
1693 See the documentation for L</daverage> for more information.
1694  
1695 =for usage
1696  
1697 $x = davg($data);
1698  
1699 =for bad
1700  
1701 This routine handles bad values.
1702  
1703 =cut
1704  
1705 *davg = \&PDL::davg;
1706 sub PDL::davg { $_[0]->flat->daverage }
1707  
1708 #line 640 "lib/PDL/Ufunc.pd"
1709  
1710 =head2 dsum
1711  
1712 =for ref
1713  
1714 Return the sum (in double precision) of all elements in an ndarray.
1715  
1716 See the documentation for L</dsumover> for more information.
1717  
1718 =for usage
1719  
1720 $x = dsum($data);
1721  
1722 =for bad
1723  
1724 This routine handles bad values.
1725  
1726 =cut
1727  
1728 *dsum = \&PDL::dsum;
1729 sub PDL::dsum { $_[0]->flat->dsumover }
1730  
1731 #line 640 "lib/PDL/Ufunc.pd"
1732  
1733 =head2 dprod
1734  
1735 =for ref
1736  
1737 Return the product (in double precision) of all elements in an ndarray.
1738  
1739 See the documentation for L</dprodover> for more information.
1740  
1741 =for usage
1742  
1743 $x = dprod($data);
1744  
1745 =for bad
1746  
1747 This routine handles bad values.
1748  
1749 =cut
1750  
1751 *dprod = \&PDL::dprod;
1752 sub PDL::dprod { $_[0]->flat->dprodover }
1753  
1754 #line 640 "lib/PDL/Ufunc.pd"
1755  
1756 =head2 zcheck
1757  
1758 =for ref
1759  
1760 Return the check for zero of all elements in an ndarray.
1761  
1762 See the documentation for L</zcover> for more information.
1763  
1764 =for usage
1765  
1766 $x = zcheck($data);
1767  
1768 =for bad
1769  
1770 This routine handles bad values.
1771  
1772 =cut
1773  
1774 *zcheck = \&PDL::zcheck;
1775 sub PDL::zcheck { $_[0]->flat->zcover }
1776  
1777 #line 640 "lib/PDL/Ufunc.pd"
1778  
1779 =head2 and
1780  
1781 =for ref
1782  
1783 Return the logical and of all elements in an ndarray.
1784  
1785 See the documentation for L</andover> for more information.
1786  
1787 =for usage
1788  
1789 $x = and($data);
1790  
1791 =for bad
1792  
1793 This routine handles bad values.
1794  
1795 =cut
1796  
1797 *and = \&PDL::and;
1798 sub PDL::and { $_[0]->flat->andover }
1799  
1800 #line 640 "lib/PDL/Ufunc.pd"
1801  
1802 =head2 band
1803  
1804 =for ref
1805  
1806 Return the bitwise and of all elements in an ndarray.
1807  
1808 See the documentation for L</bandover> for more information.
1809  
1810 =for usage
1811  
1812 $x = band($data);
1813  
1814 =for bad
1815  
1816 This routine handles bad values.
1817  
1818 =cut
1819  
1820 *band = \&PDL::band;
1821 sub PDL::band { $_[0]->flat->bandover }
1822  
1823 #line 640 "lib/PDL/Ufunc.pd"
1824  
1825 =head2 or
1826  
1827 =for ref
1828  
1829 Return the logical or of all elements in an ndarray.
1830  
1831 See the documentation for L</orover> for more information.
1832  
1833 =for usage
1834  
1835 $x = or($data);
1836  
1837 =for bad
1838  
1839 This routine handles bad values.
1840  
1841 =cut
1842  
1843 *or = \&PDL::or;
1844 sub PDL::or { $_[0]->flat->orover }
1845  
1846 #line 640 "lib/PDL/Ufunc.pd"
1847  
1848 =head2 bor
1849  
1850 =for ref
1851  
1852 Return the bitwise or of all elements in an ndarray.
1853  
1854 See the documentation for L</borover> for more information.
1855  
1856 =for usage
1857  
1858 $x = bor($data);
1859  
1860 =for bad
1861  
1862 This routine handles bad values.
1863  
1864 =cut
1865  
1866 *bor = \&PDL::bor;
1867 sub PDL::bor { $_[0]->flat->borover }
1868  
1869 #line 640 "lib/PDL/Ufunc.pd"
1870  
1871 =head2 xorall
1872  
1873 =for ref
1874  
1875 Return the logical xor of all elements in an ndarray.
1876  
1877 See the documentation for L</xorover> for more information.
1878  
1879 =for usage
1880  
1881 $x = xorall($data);
1882  
1883 =for bad
1884  
1885 This routine handles bad values.
1886  
1887 =cut
1888  
1889 *xorall = \&PDL::xorall;
1890 sub PDL::xorall { $_[0]->flat->xorover }
1891  
1892 #line 640 "lib/PDL/Ufunc.pd"
1893  
1894 =head2 bxor
1895  
1896 =for ref
1897  
1898 Return the bitwise xor of all elements in an ndarray.
1899  
1900 See the documentation for L</bxorover> for more information.
1901  
1902 =for usage
1903  
1904 $x = bxor($data);
1905  
1906 =for bad
1907  
1908 This routine handles bad values.
1909  
1910 =cut
1911  
1912 *bxor = \&PDL::bxor;
1913 sub PDL::bxor { $_[0]->flat->bxorover }
1914  
1915 #line 640 "lib/PDL/Ufunc.pd"
1916  
1917 =head2 min
1918  
1919 =for ref
1920  
1921 Return the minimum of all elements in an ndarray.
1922  
1923 See the documentation for L</minimum> for more information.
1924  
1925 =for usage
1926  
1927 $x = min($data);
1928  
1929 =for bad
1930  
1931 This routine handles bad values.
1932  
1933 =cut
1934  
1935 *min = \&PDL::min;
1936 sub PDL::min { $_[0]->flat->minimum }
1937  
1938 #line 640 "lib/PDL/Ufunc.pd"
1939  
1940 =head2 max
1941  
1942 =for ref
1943  
1944 Return the maximum of all elements in an ndarray.
1945  
1946 See the documentation for L</maximum> for more information.
1947  
1948 =for usage
1949  
1950 $x = max($data);
1951  
1952 =for bad
1953  
1954 This routine handles bad values.
1955  
1956 =cut
1957  
1958 *max = \&PDL::max;
1959 sub PDL::max { $_[0]->flat->maximum }
1960  
1961 #line 640 "lib/PDL/Ufunc.pd"
1962  
1963 =head2 median
1964  
1965 =for ref
1966  
1967 Return the median of all elements in an ndarray.
1968  
1969 See the documentation for L</medover> for more information.
1970  
1971 =for usage
1972  
1973 $x = median($data);
1974  
1975 =for bad
1976  
1977 This routine handles bad values.
1978  
1979 =cut
1980  
1981 *median = \&PDL::median;
1982 sub PDL::median { $_[0]->flat->medover }
1983  
1984 #line 640 "lib/PDL/Ufunc.pd"
1985  
1986 =head2 mode
1987  
1988 =for ref
1989  
1990 Return the mode of all elements in an ndarray.
1991  
1992 See the documentation for L</modeover> for more information.
1993  
1994 =for usage
1995  
1996 $x = mode($data);
1997  
1998 =for bad
1999  
2000 This routine handles bad values.
2001  
2002 =cut
2003  
2004 *mode = \&PDL::mode;
2005 sub PDL::mode { $_[0]->flat->modeover }
2006  
2007 #line 640 "lib/PDL/Ufunc.pd"
2008  
2009 =head2 oddmedian
2010  
2011 =for ref
2012  
2013 Return the oddmedian of all elements in an ndarray.
2014  
2015 See the documentation for L</oddmedover> for more information.
2016  
2017 =for usage
2018  
2019 $x = oddmedian($data);
2020  
2021 =for bad
2022  
2023 This routine handles bad values.
2024  
2025 =cut
2026  
2027 *oddmedian = \&PDL::oddmedian;
2028 sub PDL::oddmedian { $_[0]->flat->oddmedover }
2029  
2030 #line 666 "lib/PDL/Ufunc.pd"
2031  
2032 =head2 any
2033  
2034 =for ref
2035  
2036 Return true if any element in ndarray set
2037  
2038 Useful in conditional expressions:
2039  
2040 =for example
2041  
2042 if (any $x>15) { print "some values are greater than 15\n" }
2043  
2044 =for bad
2045  
2046 See L</or> for comments on what happens when all elements
2047 in the check are bad.
2048  
2049 =cut
2050  
2051 *any = \&or;
2052 *PDL::any = \&PDL::or;
2053  
2054 =head2 all
2055  
2056 =for ref
2057  
2058 Return true if all elements in ndarray set
2059  
2060 Useful in conditional expressions:
2061  
2062 =for example
2063  
2064 if (all $x>15) { print "all values are greater than 15\n" }
2065  
2066 =for bad
2067  
2068 See L</and> for comments on what happens when all elements
2069 in the check are bad.
2070  
2071 =cut
2072  
2073 *all = \&and;
2074 *PDL::all = \&PDL::and;
2075  
2076 =head2 minmax
2077  
2078 =for ref
2079  
2080 Returns a list with minimum and maximum values of an ndarray.
2081  
2082 =for usage
2083  
2084 ($mn, $mx) = minmax($pdl);
2085  
2086 This routine does I<not> broadcast over the dimensions of C<$pdl>;
2087 it returns the minimum and maximum values of the whole ndarray.
2088 See L</minmaximum> if this is not what is required.
2089 The two values are returned as Perl scalars,
2090 and therefore ignore whether the values are bad.
2091  
2092 =for example
2093  
2094 pdl> $x = pdl [1,-2,3,5,0]
2095 pdl> ($min, $max) = minmax($x);
2096 pdl> p "$min $max\n";
2097 -2 5
2098  
2099 =cut
2100  
2101 *minmax = \&PDL::minmax;
2102 sub PDL::minmax { map $_->sclr, ($_[0]->flat->minmaximum)[0,1] }
2103 #line 2104 "lib/PDL/Ufunc.pm"
2104  
2105  
2106 =head2 medover
2107  
2108 =for sig
2109  
2110 Signature: (a(n); [o]b(); [t]tmp(n))
2111 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
2112 float double ldouble)
2113  
2114 =for usage
2115  
2116 $b = medover($a);
2117 medover($a, $b); # all arguments given
2118 $b = $a->medover; # method call
2119 $a->medover($b);
2120  
2121 =for ref
2122  
2123 Project via median to N-1 dimensions
2124  
2125 This function reduces the dimensionality of an ndarray
2126 by one by taking the median along the 1st dimension.
2127  
2128 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
2129 I<any> dimension.
2130  
2131 =pod
2132  
2133 Broadcasts over its inputs.
2134  
2135 =for bad
2136  
2137 C<medover> processes bad values.
2138 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
2139  
2140 =cut
2141  
2142  
2143  
2144  
2145 *medover = \&PDL::medover;
2146  
2147  
2148  
2149  
2150  
2151  
2152 =head2 oddmedover
2153  
2154 =for sig
2155  
2156 Signature: (a(n); [o]b(); [t]tmp(n))
2157 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
2158 float double ldouble)
2159  
2160 =for usage
2161  
2162 $b = oddmedover($a);
2163 oddmedover($a, $b); # all arguments given
2164 $b = $a->oddmedover; # method call
2165 $a->oddmedover($b);
2166  
2167 =for ref
2168  
2169 Project via oddmedian to N-1 dimensions
2170  
2171 This function reduces the dimensionality of an ndarray
2172 by one by taking the oddmedian along the 1st dimension.
2173  
2174 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
2175 I<any> dimension.
2176  
2177 The median is sometimes not a good choice as if the array has
2178 an even number of elements it lies half-way between the two
2179 middle values - thus it does not always correspond to a data
2180 value. The lower-odd median is just the lower of these two values
2181 and so it ALWAYS sits on an actual data value which is useful in
2182 some circumstances.
2183
2184  
2185 =pod
2186  
2187 Broadcasts over its inputs.
2188  
2189 =for bad
2190  
2191 C<oddmedover> processes bad values.
2192 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
2193  
2194 =cut
2195  
2196  
2197  
2198  
2199 *oddmedover = \&PDL::oddmedover;
2200  
2201  
2202  
2203  
2204  
2205  
2206 =head2 modeover
2207  
2208 =for sig
2209  
2210 Signature: (data(n); [o]out(); [t]sorted(n))
2211 Types: (sbyte byte short ushort long ulong indx ulonglong longlong)
2212  
2213 =for usage
2214  
2215 $out = modeover($data);
2216 modeover($data, $out); # all arguments given
2217 $out = $data->modeover; # method call
2218 $data->modeover($out);
2219  
2220 =for ref
2221  
2222 Project via mode to N-1 dimensions
2223  
2224 This function reduces the dimensionality of an ndarray
2225 by one by taking the mode along the 1st dimension.
2226  
2227 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
2228 I<any> dimension.
2229  
2230 The mode is the single element most frequently found in a
2231 discrete data set.
2232  
2233 It I<only> makes sense for integer data types, since
2234 floating-point types are demoted to integer before the
2235 mode is calculated.
2236  
2237 C<modeover> treats BAD the same as any other value: if
2238 BAD is the most common element, the returned value is also BAD.
2239  
2240 =pod
2241  
2242 Broadcasts over its inputs.
2243  
2244 =for bad
2245  
2246 C<modeover> does not process bad values.
2247 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
2248  
2249 =cut
2250  
2251  
2252  
2253  
2254 *modeover = \&PDL::modeover;
2255  
2256  
2257  
2258  
2259  
2260  
2261 =head2 pctover
2262  
2263 =for sig
2264  
2265 Signature: (a(n); p(); [o]b(); [t]tmp(n))
2266 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
2267 float double ldouble)
2268  
2269 =for usage
2270  
2271 $b = pctover($a, $p);
2272 pctover($a, $p, $b); # all arguments given
2273 $b = $a->pctover($p); # method call
2274 $a->pctover($p, $b);
2275  
2276 =for ref
2277  
2278 Project via specified percentile to N-1 dimensions
2279  
2280 This function reduces the dimensionality of an ndarray
2281 by one by taking the specified percentile along the 1st dimension.
2282  
2283 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
2284 I<any> dimension.
2285  
2286 The specified
2287 percentile must be between 0.0 and 1.0. When the specified percentile
2288 falls between data points, the result is interpolated. Values outside
2289 the allowed range are clipped to 0.0 or 1.0 respectively. The algorithm
2290 implemented here is based on the interpolation variant described at
2291 L<http://en.wikipedia.org/wiki/Percentile> as used by Microsoft Excel
2292 and recommended by NIST.
2293  
2294 =pod
2295  
2296 Broadcasts over its inputs.
2297  
2298 =for bad
2299  
2300 C<pctover> processes bad values.
2301 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
2302  
2303 =cut
2304  
2305  
2306  
2307  
2308 *pctover = \&PDL::pctover;
2309  
2310  
2311  
2312  
2313  
2314  
2315 =head2 oddpctover
2316  
2317 =for sig
2318  
2319 Signature: (a(n); p(); [o]b(); [t]tmp(n))
2320 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
2321 float double ldouble)
2322  
2323 =for usage
2324  
2325 $b = oddpctover($a, $p);
2326 oddpctover($a, $p, $b); # all arguments given
2327 $b = $a->oddpctover($p); # method call
2328 $a->oddpctover($p, $b);
2329  
2330 =for ref
2331  
2332 Project via specified percentile to N-1 dimensions
2333  
2334 This function reduces the dimensionality of an ndarray
2335 by one by taking the specified percentile along the 1st dimension.
2336  
2337 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
2338 I<any> dimension.
2339  
2340 The specified
2341 percentile must be between 0.0 and 1.0. When the specified percentile
2342 falls between two values, the nearest data value is the result.
2343 The algorithm implemented is from the textbook version described
2344 first at L<http://en.wikipedia.org/wiki/Percentile>.
2345  
2346 =pod
2347  
2348 Broadcasts over its inputs.
2349  
2350 =for bad
2351  
2352 C<oddpctover> processes bad values.
2353 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
2354  
2355 =cut
2356  
2357  
2358  
2359  
2360 *oddpctover = \&PDL::oddpctover;
2361  
2362  
2363  
2364  
2365  
2366 #line 1014 "lib/PDL/Ufunc.pd"
2367  
2368 =head2 pct
2369  
2370 =for ref
2371  
2372 Return the specified percentile of all elements in an ndarray. The
2373 specified percentile (p) must be between 0.0 and 1.0. When the
2374 specified percentile falls between data points, the result is interpolated.
2375  
2376 =for usage
2377  
2378 $x = pct($data, $pct);
2379  
2380 =cut
2381  
2382 *pct = \&PDL::pct;
2383 sub PDL::pct {
2384 my($x, $p) = @_;
2385 $x->flat->pctover($p, my $tmp=PDL->nullcreate($x));
2386 $tmp;
2387 }
2388  
2389 #line 1014 "lib/PDL/Ufunc.pd"
2390  
2391 =head2 oddpct
2392  
2393 =for ref
2394  
2395 Return the specified percentile of all elements in an ndarray. The
2396 specified percentile (p) must be between 0.0 and 1.0. When the
2397 specified percentile falls between data points, the nearest data value is the result.
2398  
2399 =for usage
2400  
2401 $x = oddpct($data, $pct);
2402  
2403 =cut
2404  
2405 *oddpct = \&PDL::oddpct;
2406 sub PDL::oddpct {
2407 my($x, $p) = @_;
2408 $x->flat->oddpctover($p, my $tmp=PDL->nullcreate($x));
2409 $tmp;
2410 }
2411 #line 2412 "lib/PDL/Ufunc.pm"
2412  
2413  
2414 =head2 qsort
2415  
2416 =for sig
2417  
2418 Signature: (!complex a(n); !complex [o]b(n))
2419 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
2420 float double ldouble)
2421  
2422 =for usage
2423  
2424 $b = qsort($a);
2425 qsort($a, $b); # all arguments given
2426 $b = $a->qsort; # method call
2427 $a->qsort($b);
2428 $a->inplace->qsort; # can be used inplace
2429 qsort($a->inplace);
2430  
2431 =for ref
2432  
2433 Quicksort a vector into ascending order.
2434  
2435 =pod
2436  
2437 Can operate inplace with C<a> as output C<b>.
2438 Broadcasts over its inputs.
2439  
2440 =for bad
2441  
2442 Bad values are moved to the end of the array:
2443  
2444 pdl> p $y
2445 [42 47 98 BAD 22 96 74 41 79 76 96 BAD 32 76 25 59 BAD 96 32 BAD]
2446 pdl> p qsort($y)
2447 [22 25 32 32 41 42 47 59 74 76 76 79 96 96 96 98 BAD BAD BAD BAD]
2448  
2449 =cut
2450  
2451  
2452  
2453  
2454 *qsort = \&PDL::qsort;
2455  
2456  
2457  
2458  
2459  
2460  
2461 =head2 qsorti
2462  
2463 =for sig
2464  
2465 Signature: (!complex a(n); indx [o]indx(n))
2466 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
2467 float double ldouble)
2468  
2469 =for usage
2470  
2471 $indx = qsorti($a);
2472 qsorti($a, $indx); # all arguments given
2473 $indx = $a->qsorti; # method call
2474 $a->qsorti($indx);
2475  
2476 =for ref
2477  
2478 Quicksort a vector and return index of elements in ascending order.
2479  
2480 =for example
2481  
2482 $ix = qsorti $x;
2483 print $x->index($ix); # Sorted list
2484  
2485 =pod
2486  
2487 Broadcasts over its inputs.
2488  
2489 =for bad
2490  
2491 Bad elements are moved to the end of the array:
2492  
2493 pdl> p $y
2494 [42 47 98 BAD 22 96 74 41 79 76 96 BAD 32 76 25 59 BAD 96 32 BAD]
2495 pdl> p $y->index( qsorti($y) )
2496 [22 25 32 32 41 42 47 59 74 76 76 79 96 96 96 98 BAD BAD BAD BAD]
2497  
2498 =cut
2499  
2500  
2501  
2502  
2503 *qsorti = \&PDL::qsorti;
2504  
2505  
2506  
2507  
2508  
2509  
2510 =head2 qsortvec
2511  
2512 =for sig
2513  
2514 Signature: (!complex a(n,m); !complex [o]b(n,m))
2515 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
2516 float double ldouble)
2517  
2518 =for usage
2519  
2520 $b = qsortvec($a);
2521 qsortvec($a, $b); # all arguments given
2522 $b = $a->qsortvec; # method call
2523 $a->qsortvec($b);
2524 $a->inplace->qsortvec; # can be used inplace
2525 qsortvec($a->inplace);
2526  
2527 =for ref
2528  
2529 Sort a list of vectors lexicographically.
2530  
2531 The 0th dimension of the source ndarray is dimension in the vector;
2532 the 1st dimension is list order. Higher dimensions are broadcasted over.
2533  
2534 =for example
2535  
2536 print qsortvec pdl([[1,2],[0,500],[2,3],[4,2],[3,4],[3,5]]);
2537 [
2538 [ 0 500]
2539 [ 1 2]
2540 [ 2 3]
2541 [ 3 4]
2542 [ 3 5]
2543 [ 4 2]
2544 ]
2545  
2546 =pod
2547  
2548 Can operate inplace with C<a> as output C<b>.
2549 Broadcasts over its inputs.
2550  
2551 =for bad
2552  
2553 Vectors with bad components are moved to the end of the array:
2554  
2555 pdl> p $p = pdl("[0 0] [-100 0] [BAD 0] [100 0]")->qsortvec
2556  
2557 [
2558 [-100 0]
2559 [ 0 0]
2560 [ 100 0]
2561 [ BAD 0]
2562 ]
2563  
2564 =cut
2565  
2566  
2567  
2568  
2569 *qsortvec = \&PDL::qsortvec;
2570  
2571  
2572  
2573  
2574  
2575  
2576 =head2 qsortveci
2577  
2578 =for sig
2579  
2580 Signature: (!complex a(n,m); indx [o]indx(m))
2581 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
2582 float double ldouble)
2583  
2584 =for usage
2585  
2586 $indx = qsortveci($a);
2587 qsortveci($a, $indx); # all arguments given
2588 $indx = $a->qsortveci; # method call
2589 $a->qsortveci($indx);
2590  
2591 =for ref
2592  
2593 Sort a list of vectors lexicographically, returning the indices of the
2594 sorted vectors rather than the sorted list itself.
2595  
2596 As with C<qsortvec>, the input PDL should be an NxM array containing M
2597 separate N-dimensional vectors. The return value is an integer M-PDL
2598 containing the M-indices of original array rows, in sorted order.
2599  
2600 As with C<qsortvec>, the zeroth element of the vectors runs slowest in the
2601 sorted list.
2602  
2603 Additional dimensions are broadcasted over: each plane is sorted separately,
2604 so qsortveci may be thought of as a collapse operator of sorts (groan).
2605  
2606 =pod
2607  
2608 Broadcasts over its inputs.
2609  
2610 =for bad
2611  
2612 Vectors with bad components are moved to the end of the array as
2613 for L</qsortvec>.
2614  
2615 =cut
2616  
2617  
2618  
2619  
2620 *qsortveci = \&PDL::qsortveci;
2621  
2622  
2623  
2624  
2625  
2626  
2627 =head2 magnover
2628  
2629 =for sig
2630  
2631 Signature: (a(n); real [o]b())
2632 Types: (double ldouble cfloat cdouble cldouble float)
2633  
2634 =for usage
2635  
2636 $b = magnover($a);
2637 magnover($a, $b); # all arguments given
2638 $b = $a->magnover; # method call
2639 $a->magnover($b);
2640  
2641 =for ref
2642  
2643 Project via Euclidean (aka Pythagorean) distance to N-1 dimensions
2644  
2645 This function reduces the dimensionality of an ndarray
2646 by one by taking the Euclidean (aka Pythagorean) distance along the 1st dimension.
2647  
2648 By using L<xchg|PDL::Slices/xchg> etc. it is possible to use
2649 I<any> dimension.
2650  
2651 Minimum C<float> precision output.
2652 See also L<PDL::Primitive/inner>, L<PDL::Primitive/norm>.
2653  
2654 =pod
2655  
2656 Broadcasts over its inputs.
2657  
2658 =for bad
2659  
2660 C<magnover> processes bad values.
2661 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
2662  
2663 =cut
2664  
2665  
2666  
2667  
2668 *magnover = \&PDL::magnover;
2669  
2670  
2671  
2672  
2673  
2674  
2675  
2676 #line 1258 "lib/PDL/Ufunc.pd"
2677  
2678 =head1 AUTHOR
2679  
2680 Copyright (C) Tuomas J. Lukka 1997 (lukka@husc.harvard.edu).
2681 Contributions by Christian Soeller (c.soeller@auckland.ac.nz)
2682 and Karl Glazebrook (kgb@aaoepp.aao.gov.au). All rights
2683 reserved. There is no warranty. You are allowed to redistribute this
2684 software / documentation under certain conditions. For details, see
2685 the file COPYING in the PDL distribution. If this file is separated
2686 from the PDL distribution, the copyright notice should be included in
2687 the file.
2688  
2689 =cut
2690 #line 2691 "lib/PDL/Ufunc.pm"
2691  
2692 # Exit with OK status
2693  
2694 1;
« lib/PDL/Slices.pm ↑ Summary