blib/lib/PDL/Complex.pm

filter: Statementstmt 93.1% 81 / 87 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 47 / 47 Podpod 100% 8 / 8 totaltotal 93.9% 139 / 148 CC 4 SCAR 1.6
CC
4
Cov
90%
Ceq
3.1
r2C
2.0
i2C
1.1
CRAP 1.2
« complex.pd ↑ Summary pp-Cproj.c »
1 #
2 # GENERATED WITH PDL::PP from complex.pd! Don't modify!
3 #
4 package PDL::Complex;
5  
6 1 our @EXPORT_OK = qw(Ctan Catan re im i cplx real r2C i2C Cr2p Cp2r Cadd Csub Cmul Cprodover Cscale Cdiv Ceq Cconj Cabs Cabs2 Carg Csin Ccos Cexp Clog Cpow Csqrt Casin Cacos Csinh Ccosh Ctanh Casinh Cacosh Catanh Cproj Croots rCpolynomial Ctricpy Cmstack Caugment );
7 1 our %EXPORT_TAGS = (Func=>\@EXPORT_OK);
8  
9 1 ▶use PDL::Core();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use PDL::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use DynaLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
14
15 1 our @ISA = ( 'PDL::Exporter','DynaLoader','PDL' );
16 1 push @PDL::Core::PP, __PACKAGE__;
17 1 bootstrap PDL::Complex ;
18 }
19  
20  
21  
22  
23  
24  
25  
26 #line 18 "complex.pd"
27  
28 use strict;
29 use warnings;
30 use Carp;
31 our $VERSION = '2.012';
32  
33 =encoding utf8
34  
35 =head1 NAME
36  
37 PDL::Complex - handle complex numbers (DEPRECATED - use native complex)
38  
39 =head1 SYNOPSIS
40  
41 use PDL;
42 use PDL::Complex;
43  
44 =head1 DESCRIPTION
45  
46 This module is deprecated in favour of using "native complex" data types, e.g.:
47  
48 use PDL;
49 my $complex_pdl = cdouble('[1+3i]');
50 print $complex_pdl * pdl('i'); # [-3+i]
51  
52 This module features a growing number of functions manipulating complex
53 numbers. These are usually represented as a pair C<[ real imag ]> or
54 C<[ magnitude phase ]>. If not explicitly mentioned, the functions can work
55 inplace (not yet implemented!!!) and require rectangular form.
56  
57 While there is a procedural interface available (C<< $x/$y*$c <=> Cmul
58 (Cdiv ($x, $y), $c) >>), you can also opt to cast your pdl's into the
59 C<PDL::Complex> datatype, which works just like your normal ndarrays, but
60 with all the normal perl operators overloaded.
61  
62 The latter means that C<sin($x) + $y/$c> will be evaluated using the
63 normal rules of complex numbers, while other pdl functions (like C<max>)
64 just treat the ndarray as a real-valued ndarray with a lowest dimension of
65 size 2, so C<max> will return the maximum of all real and imaginary parts,
66 not the "highest" (for some definition)
67  
68 =head2 Native complex support
69  
70 2.027 added changes in complex number handling, with support for C99
71 complex floating-point types, and most functions and modules in the core
72 distribution support these as well.
73  
74 PDL can now handle complex numbers natively as scalars. This has
75 the advantage that real and complex valued ndarrays have the same
76 dimensions. Consider this when writing code in the future.
77  
78 See L<PDL::Ops/re>, L<PDL::Ops/im>, L<PDL::Ops/abs>, L<PDL::Ops/carg>,
79 L<PDL::Ops/conj> for more.
80  
81 =head1 TIPS, TRICKS & CAVEATS
82  
83 =over 4
84  
85 =item *
86  
87 C<i> is a function (not, as of 2.047, a constant) exported by this module,
88 which represents C<-1**0.5>, i.e. the imaginary unit. it can be used to
89 quickly and conveniently write complex constants like this: C<4+3*i>.
90  
91 B<NB> This will override the PDL::Core function of the same name, which
92 returns a native complex value.
93  
94 =item *
95  
96 Use C<r2C(real-values)> to convert from real to complex, as in C<$r
97 = Cpow $cplx, r2C 2>. The overloaded operators automatically do that for
98 you, all the other functions, do not. So C<Croots 1, 5> will return all
99 the fifths roots of 1+1*i (due to broadcasting).
100  
101 =item *
102  
103 use C<cplx(real-valued-ndarray)> to cast from normal ndarrays into the
104 complex datatype. Use C<real(complex-valued-ndarray)> to cast back. This
105 requires a copy, though.
106  
107 =back
108  
109 =head1 EXAMPLE WALK-THROUGH
110  
111 The complex constant five is equal to C<pdl(1,0)>:
112  
113 pdl> p $x = r2C 5
114 5 +0i
115  
116 Now calculate the three cubic roots of five:
117  
118 pdl> p $r = Croots $x, 3
119 [1.70998 +0i -0.854988 +1.48088i -0.854988 -1.48088i]
120  
121 Check that these really are the roots:
122  
123 pdl> p $r ** 3
124 [5 +0i 5 -1.22465e-15i 5 -7.65714e-15i]
125  
126 Duh! Could be better. Now try by multiplying C<$r> three times with itself:
127  
128 pdl> p $r*$r*$r
129 [5 +0i 5 -4.72647e-15i 5 -7.53694e-15i]
130  
131 Well... maybe C<Cpow> (which is used by the C<**> operator) isn't as
132 bad as I thought. Now multiply by C<i> and negate, then take the complex
133 conjugate, which is just a very expensive way of swapping real and
134 imaginary parts.
135  
136 pdl> p Cconj(-($r*i))
137 [0 +1.70998i 1.48088 -0.854988i -1.48088 -0.854988i]
138  
139 Now plot the magnitude of (part of) the complex sine. First generate the
140 coefficients:
141  
142 pdl> $sin = i * zeroes(50)->xlinvals(2,4) + zeroes(50)->xlinvals(0,7)
143  
144 Now plot the imaginary part, the real part and the magnitude of the sine
145 into the same diagram:
146  
147 pdl> use PDL::Graphics::Gnuplot
148 pdl> gplot( with => 'lines',
149 PDL::cat(im ( sin $sin ),
150 re ( sin $sin ),
151 abs( sin $sin ) ))
152  
153 An ASCII version of this plot looks like this:
154  
155 30 ++-----+------+------+------+------+------+------+------+------+-----++
156 + + + + + + + + + + +
157 | $$|
158 | $ |
159 25 ++ $$ ++
160 | *** |
161 | ** *** |
162 | $$* *|
163 20 ++ $** ++
164 | $$$* #|
165 | $$$ * # |
166 | $$ * # |
167 15 ++ $$$ * # ++
168 | $$$ ** # |
169 | $$$$ * # |
170 | $$$$ * # |
171 10 ++ $$$$$ * # ++
172 | $$$$$ * # |
173 | $$$$$$$ * # |
174 5 ++ $$$############ * # ++
175 |*****$$$### ### * # |
176 * #***** # * # |
177 | ### *** ### ** # |
178 0 ## *** # * # ++
179 | * # * # |
180 | *** # ** # |
181 | * # * # |
182 -5 ++ ** # * # ++
183 | *** ## ** # |
184 | * #* # |
185 | **** ***## # |
186 -10 ++ **** # # ++
187 | # # |
188 | ## ## |
189 + + + + + + + ### + ### + + +
190 -15 ++-----+------+------+------+------+------+-----###-----+------+-----++
191 0 5 10 15 20 25 30 35 40 45 50
192  
193 =head1 OPERATORS
194  
195 The following operators are overloaded:
196  
197 =over 4
198  
199 =item +, += (addition)
200  
201 =item -, -= (subtraction)
202  
203 =item *, *= (multiplication; L</Cmul>)
204  
205 =item /, /= (division; L</Cdiv>)
206  
207 =item **, **= (exponentiation; L</Cpow>)
208  
209 =item atan2 (4-quadrant arc tangent)
210  
211 =item sin (L</Csin>)
212  
213 =item cos (L</Ccos>)
214  
215 =item exp (L</Cexp>)
216  
217 =item abs (L</Cabs>)
218  
219 =item log (L</Clog>)
220  
221 =item sqrt (L</Csqrt>)
222  
223 =item ++, -- (increment, decrement; they affect the real part of the complex number only)
224  
225 =item "" (stringification)
226  
227 =back
228  
229 Comparing complex numbers other than for equality is a fatal error.
230  
231 =cut
232  
233 my $i;
234 BEGIN { $i = bless PDL->pdl(0,1) }
235 {
236 no warnings 'redefine';
237 sub i { $i->copy + (@_ ? $_[0] : 0) };
238 }
239  
240 # sensible aliases from PDL::LinearAlgebra
241 *r2p = \&Cr2p;
242 *p2r = \&Cp2r;
243 *conj = \&Cconj;
244 *abs = \&Cabs;
245 *abs2 = \&Cabs2;
246 *arg = \&Carg;
247 *tan = \&Ctan;
248 *proj = \&Cproj;
249 *asin = \&Casin;
250 *acos = \&Cacos;
251 *atan = \&Catan;
252 *sinh = \&Csinh;
253 *cosh = \&Ccosh;
254 *tanh = \&Ctanh;
255 *asinh = \&Casinh;
256 *acosh = \&Cacosh;
257 *atanh = \&Catanh;
258 *tricpy = \&Ctricpy;
259 *mstack = \&Cmstack;
260 *augment = \&Caugment;
261 #line 262 "Complex.pm"
262  
263  
264 =head1 FUNCTIONS
265  
266 =cut
267  
268  
269  
270  
271  
272 #line 333 "complex.pd"
273  
274 =head2 from_native
275  
276 =for ref
277  
278 Class method to convert a native-complex ndarray to a PDL::Complex object.
279  
280 =for usage
281  
282 PDL::Complex->from_native($native_complex_ndarray)
283  
284 =cut
285  
286 sub from_native {
287 my ($class, $ndarray) = @_;
288 return $ndarray if UNIVERSAL::isa($ndarray,'PDL::Complex'); # NOOP if P:C
289 croak "not an ndarray" if !UNIVERSAL::isa($ndarray,'PDL');
290 croak "not a native complex ndarray" if $ndarray->type->real;
291 bless PDL::append($ndarray->re->dummy(0),$ndarray->im->dummy(0)), $class;
292 }
293  
294 =head2 as_native
295  
296 =for ref
297  
298 Object method to convert a PDL::Complex object to a native-complex ndarray.
299  
300 =for usage
301  
302 $pdl_complex_obj->as_native
303  
304 =cut
305  
306 sub as_native {
307 PDL::Ops::czip(map $_[0]->slice("($_)"), 0..1);
308 }
309  
310 =head2 cplx
311  
312 =for ref
313  
314 Cast a real-valued ndarray to the complex datatype.
315  
316 The first dimension of the ndarray must be of size 2. After this the
317 usual (complex) arithmetic operators are applied to this pdl, rather
318 than the normal elementwise pdl operators. Dataflow to the complex
319 parent works. Use C<sever> on the result if you don't want this.
320  
321 =for usage
322  
323 cplx($real_valued_pdl)
324  
325 =head2 complex
326  
327 =for ref
328  
329 Cast a real-valued ndarray to the complex datatype I<without> dataflow
330 and I<inplace>.
331  
332 Achieved by merely reblessing an ndarray. The first dimension of the
333 ndarray must be of size 2.
334  
335 =for usage
336  
337 complex($real_valued_pdl)
338  
339 =head2 real
340  
341 =for ref
342  
343 Cast a complex valued pdl back to the "normal" pdl datatype.
344  
345 Afterwards the normal elementwise pdl operators are used in
346 operations. Dataflow to the real parent works. Use C<sever> on the
347 result if you don't want this.
348  
349 =for usage
350  
351 real($cplx_valued_pdl)
352  
353 =cut
354  
355 sub cplx($) {
356 return $_[0] if UNIVERSAL::isa($_[0],'PDL::Complex'); # NOOP if just ndarray
357 croak "first dimsize must be 2" unless $_[0]->dims > 0 && $_[0]->dim(0) == 2;
358 bless $_[0]->slice('');
359 }
360  
361 sub complex($) {
362 return $_[0] if UNIVERSAL::isa($_[0],'PDL::Complex'); # NOOP if just ndarray
363 croak "first dimsize must be 2" unless $_[0]->dims > 0 && $_[0]->dim(0) == 2;
364 bless $_[0];
365 }
366  
367 *PDL::cplx = \&cplx;
368 *PDL::complex = \&complex;
369  
370 sub real($) {
371 return $_[0] unless UNIVERSAL::isa($_[0],'PDL::Complex'); # NOOP unless complex
372 bless $_[0]->slice(''), 'PDL';
373 }
374  
375 =head2 t
376  
377 =for usage
378  
379 $pdl = $pdl->t(SCALAR(conj))
380 conj : Conjugate Transpose = 1 | Transpose = 0, default = 0;
381  
382 =for ref
383  
384 Convenient function for transposing real or complex 2D array(s).
385 For complex data, if conj is true returns conjugate transposed array(s).
386 Supports broadcasting. Not exported.
387  
388 Originally by Grégory Vanuxem.
389  
390 =cut
391  
392 sub t {
393 my ($m, $conj) = @_;
394 my $ndims = $m->dims;
395 my $r = $ndims > 2 ? $m->xchg(1,2) :
396 $ndims > 1 ? $m->dummy(1) :
397 $m->dummy(1)->dummy(1);
398 $conj ? $r->conj : $r;
399 }
400 #line 401 "Complex.pm"
401  
402  
403 =head2 r2C
404  
405 =for sig
406  
407 Signature: (r(); [o]c(m=2))
408 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
409 float double ldouble)
410  
411 =for usage
412  
413 $c = r2C($r);
414 r2C($r, $c); # all arguments given
415 $c = $r->r2C; # method call
416 $r->r2C($c);
417  
418 =for ref
419  
420 convert real to complex, assuming an imaginary part of zero
421  
422 =pod
423  
424 Broadcasts over its inputs.
425  
426 =for bad
427  
428 C<r2C> does not process bad values.
429 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
430  
431 =cut
432  
433  
434  
435  
436  
437 0 undef &PDL::r2C;
438 0 *PDL::r2C = \&PDL::Complex::r2C;
439 133 ▶sub PDL::Complex::r2C {
Subroutine r2C: called CC=2 SCAR=7.0
Pod documented
440 133 ▶ return $_[0] if UNIVERSAL::isa($_[0],'PDL::Complex');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($_[0], "PDL::Complex") 0 133 133
441 133 my $r = __PACKAGE__->initialize;
442 133 &PDL::Complex::_r2C_int($_[0], $r);
443 133 $r }
444  
445  
446  
447  
448 1 ▶BEGIN {*r2C = \&PDL::Complex::r2C;
Subroutine BEGIN: called CC=1 SCAR=0.0
449 }
450  
451  
452  
453  
454  
455 =head2 i2C
456  
457 =for sig
458  
459 Signature: (r(); [o]c(m=2))
460 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
461 float double ldouble)
462  
463 =for usage
464  
465 $c = i2C($r);
466 i2C($r, $c); # all arguments given
467 $c = $r->i2C; # method call
468 $r->i2C($c);
469  
470 =for ref
471  
472 convert imaginary to complex, assuming a real part of zero
473  
474 =pod
475  
476 Broadcasts over its inputs.
477  
478 =for bad
479  
480 C<i2C> does not process bad values.
481 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
482  
483 =cut
484  
485  
486  
487  
488 0 ▶undef &PDL::i2C; *PDL::i2C = \&PDL::Complex::i2C; sub PDL::Complex::i2C { my $r = __PACKAGE__->initialize; &PDL::Complex::_i2C_int($_[0], $r); $r }
Subroutine i2C: called CC=1 SCAR=0.6
Pod documented
489  
490  
491 1 ▶BEGIN {*i2C = \&PDL::Complex::i2C;
Subroutine BEGIN: called CC=1 SCAR=0.0
492 }
493  
494  
495  
496  
497  
498 =head2 Cr2p
499  
500 =for sig
501  
502 Signature: (r(m=2); [o]p(m=2))
503 Types: (float double ldouble)
504  
505 =for usage
506  
507 $p = Cr2p($r);
508 Cr2p($r, $p); # all arguments given
509 $p = $r->Cr2p; # method call
510 $r->Cr2p($p);
511 $r->inplace->Cr2p; # can be used inplace
512 Cr2p($r->inplace);
513  
514 =for ref
515  
516 convert complex numbers in rectangular form to polar (mod,arg) form. Works inplace
517  
518 =pod
519  
520 Can operate inplace with C<r> as output C<p>.
521 Broadcasts over its inputs.
522  
523 =for bad
524  
525 C<Cr2p> does not process bad values.
526 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
527  
528 =cut
529  
530  
531  
532  
533 1 ▶BEGIN {*Cr2p = \&PDL::Complex::Cr2p;
Subroutine BEGIN: called CC=1 SCAR=0.0
534 }
535  
536  
537  
538  
539  
540 =head2 Cp2r
541  
542 =for sig
543  
544 Signature: (r(m=2); [o]p(m=2))
545 Types: (float double ldouble)
546  
547 =for usage
548  
549 $p = Cp2r($r);
550 Cp2r($r, $p); # all arguments given
551 $p = $r->Cp2r; # method call
552 $r->Cp2r($p);
553 $r->inplace->Cp2r; # can be used inplace
554 Cp2r($r->inplace);
555  
556 =for ref
557  
558 convert complex numbers in polar (mod,arg) form to rectangular form. Works inplace
559  
560 =pod
561  
562 Can operate inplace with C<r> as output C<p>.
563 Broadcasts over its inputs.
564  
565 =for bad
566  
567 C<Cp2r> does not process bad values.
568 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
569  
570 =cut
571  
572  
573  
574  
575 1 ▶BEGIN {*Cp2r = \&PDL::Complex::Cp2r;
Subroutine BEGIN: called CC=1 SCAR=0.0
576 }
577  
578  
579  
580 1 ▶BEGIN {*Cadd = \&PDL::Complex::Cadd;
Subroutine BEGIN: called CC=1 SCAR=0.0
581 }
582  
583  
584  
585 1 ▶BEGIN {*Csub = \&PDL::Complex::Csub;
Subroutine BEGIN: called CC=1 SCAR=0.0
586 }
587  
588  
589  
590  
591  
592 =head2 Cmul
593  
594 =for sig
595  
596 Signature: (a(m=2); b(m=2); [o]c(m=2))
597 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
598 float double ldouble)
599  
600 =for usage
601  
602 $c = Cmul($a, $b);
603 Cmul($a, $b, $c); # all arguments given
604 $c = $a->Cmul($b); # method call
605 $a->Cmul($b, $c);
606  
607 =for ref
608  
609 complex multiplication
610  
611 =pod
612  
613 Broadcasts over its inputs.
614  
615 =for bad
616  
617 C<Cmul> does not process bad values.
618 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
619  
620 =cut
621  
622  
623  
624  
625 1 ▶BEGIN {*Cmul = \&PDL::Complex::Cmul;
Subroutine BEGIN: called CC=1 SCAR=0.0
626 }
627  
628  
629  
630  
631  
632 =head2 Cprodover
633  
634 =for sig
635  
636 Signature: (a(m=2,n); [o]c(m=2))
637 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
638 float double ldouble)
639  
640 =for usage
641  
642 $c = Cprodover($a);
643 Cprodover($a, $c); # all arguments given
644 $c = $a->Cprodover; # method call
645 $a->Cprodover($c);
646  
647 =for ref
648  
649 Project via product to N-1 dimension
650  
651 =pod
652  
653 Broadcasts over its inputs.
654  
655 =for bad
656  
657 C<Cprodover> does not process bad values.
658 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
659  
660 =cut
661  
662  
663  
664  
665 1 ▶BEGIN {*Cprodover = \&PDL::Complex::Cprodover;
Subroutine BEGIN: called CC=1 SCAR=0.0
666 }
667  
668  
669  
670  
671  
672 =head2 Cscale
673  
674 =for sig
675  
676 Signature: (a(m=2); b(); [o]c(m=2))
677 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
678 float double ldouble)
679  
680 =for usage
681  
682 $c = Cscale($a, $b);
683 Cscale($a, $b, $c); # all arguments given
684 $c = $a->Cscale($b); # method call
685 $a->Cscale($b, $c);
686  
687 =for ref
688  
689 mixed complex/real multiplication
690  
691 =pod
692  
693 Broadcasts over its inputs.
694  
695 =for bad
696  
697 C<Cscale> does not process bad values.
698 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
699  
700 =cut
701  
702  
703  
704  
705 1 ▶BEGIN {*Cscale = \&PDL::Complex::Cscale;
Subroutine BEGIN: called CC=1 SCAR=0.0
706 }
707  
708  
709  
710  
711  
712 =head2 Cdiv
713  
714 =for sig
715  
716 Signature: (a(m=2); b(m=2); [o]c(m=2))
717 Types: (float double ldouble)
718  
719 =for usage
720  
721 $c = Cdiv($a, $b);
722 Cdiv($a, $b, $c); # all arguments given
723 $c = $a->Cdiv($b); # method call
724 $a->Cdiv($b, $c);
725  
726 =for ref
727  
728 complex division
729  
730 =pod
731  
732 Broadcasts over its inputs.
733  
734 =for bad
735  
736 C<Cdiv> does not process bad values.
737 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
738  
739 =cut
740  
741  
742  
743  
744 1 ▶BEGIN {*Cdiv = \&PDL::Complex::Cdiv;
Subroutine BEGIN: called CC=1 SCAR=0.0
745 }
746  
747  
748  
749  
750  
751 =head2 Ceq
752  
753 =for sig
754  
755 Signature: (a(m=2); b(m=2); [o]c())
756 Types: (float double ldouble)
757  
758 =for usage
759  
760 $c = Ceq($a, $b);
761 Ceq($a, $b, $c); # all arguments given
762 $c = $a->Ceq($b); # method call
763 $a->Ceq($b, $c);
764  
765 =for ref
766  
767 Complex equality operator.
768  
769 =pod
770  
771 Broadcasts over its inputs.
772  
773 =for bad
774  
775 C<Ceq> does not process bad values.
776 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
777  
778 =cut
779  
780  
781  
782  
783 8 ▶sub PDL::Complex::Ceq {
Subroutine Ceq: called CC=3 SCAR=11.4
Pod documented
784 8 ▶ my @args = !$_[2] ? @_[1,0] : @_[0,1];
Branch: 1 branch
BranchTrueFalseTotal
!$_[2] ? : 8 0 8
785 8 ▶ $args[1] = r2C($args[1]) if ref $args[1] ne __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
if ref $args[1] ne __PACKAGE__ 0 8 8
786 8 PDL::Complex::_Ceq_int($args[0], $args[1], my $r = PDL->null);
787 8 $r;
788 }
789  
790  
791  
792 1 ▶BEGIN {*Ceq = \&PDL::Complex::Ceq;
Subroutine BEGIN: called CC=1 SCAR=0.0
793 }
794  
795  
796  
797  
798  
799 =head2 Cconj
800  
801 =for sig
802  
803 Signature: (a(m=2); [o]c(m=2))
804 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
805 float double ldouble)
806  
807 =for usage
808  
809 $c = Cconj($a);
810 Cconj($a, $c); # all arguments given
811 $c = $a->Cconj; # method call
812 $a->Cconj($c);
813 $a->inplace->Cconj; # can be used inplace
814 Cconj($a->inplace);
815  
816 =for ref
817  
818 complex conjugation. Works inplace
819  
820 =pod
821  
822 Can operate inplace with C<a> as output C<c>.
823 Broadcasts over its inputs.
824  
825 =for bad
826  
827 C<Cconj> does not process bad values.
828 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
829  
830 =cut
831  
832  
833  
834  
835 1 ▶BEGIN {*Cconj = \&PDL::Complex::Cconj;
Subroutine BEGIN: called CC=1 SCAR=0.0
836 }
837  
838  
839  
840  
841  
842 =head2 Cabs
843  
844 =for sig
845  
846 Signature: (a(m=2); [o]c())
847 Types: (float double ldouble)
848  
849 =for usage
850  
851 $c = Cabs($a);
852 Cabs($a, $c); # all arguments given
853 $c = $a->Cabs; # method call
854 $a->Cabs($c);
855  
856 =for ref
857  
858 complex C<abs()> (also known as I<modulus>)
859  
860 =pod
861  
862 Broadcasts over its inputs.
863  
864 =for bad
865  
866 C<Cabs> 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 6 ▶sub PDL::Complex::Cabs($) {
Subroutine Cabs: called CC=1 SCAR=0.0
Pod documented
875 6 my $pdl= shift;
876 6 my $abs = PDL->null;
877 6 &PDL::Complex::_Cabs_int($pdl, $abs);
878 6 $abs;
879 }
880  
881  
882 1 ▶BEGIN {*Cabs = \&PDL::Complex::Cabs;
Subroutine BEGIN: called CC=1 SCAR=0.0
883 }
884  
885  
886  
887  
888  
889 =head2 Cabs2
890  
891 =for sig
892  
893 Signature: (a(m=2); [o]c())
894 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
895 float double ldouble)
896  
897 =for usage
898  
899 $c = Cabs2($a);
900 Cabs2($a, $c); # all arguments given
901 $c = $a->Cabs2; # method call
902 $a->Cabs2($c);
903  
904 =for ref
905  
906 complex squared C<abs()> (also known I<squared modulus>)
907  
908 =pod
909  
910 Broadcasts over its inputs.
911  
912 =for bad
913  
914 C<Cabs2> does not process bad values.
915 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
916  
917 =cut
918  
919  
920  
921  
922 2 ▶sub PDL::Complex::Cabs2($) {
Subroutine Cabs2: called CC=1 SCAR=0.0
Pod documented
923 2 my $pdl= shift;
924 2 my $abs2 = PDL->null;
925 2 &PDL::Complex::_Cabs2_int($pdl, $abs2);
926 2 $abs2;
927 }
928  
929  
930 1 ▶BEGIN {*Cabs2 = \&PDL::Complex::Cabs2;
Subroutine BEGIN: called CC=1 SCAR=0.0
931 }
932  
933  
934  
935  
936  
937 =head2 Carg
938  
939 =for sig
940  
941 Signature: (a(m=2); [o]c())
942 Types: (float double ldouble)
943  
944 =for usage
945  
946 $c = Carg($a);
947 Carg($a, $c); # all arguments given
948 $c = $a->Carg; # method call
949 $a->Carg($c);
950  
951 =for ref
952  
953 complex argument function ("angle")
954  
955 =pod
956  
957 Broadcasts over its inputs.
958  
959 =for bad
960  
961 C<Carg> does not process bad values.
962 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
963  
964 =cut
965  
966  
967  
968  
969 2 ▶sub PDL::Complex::Carg($) {
Subroutine Carg: called CC=1 SCAR=0.0
Pod documented
970 2 my $pdl= shift;
971 2 my $arg = PDL->null;
972 2 &PDL::Complex::_Carg_int($pdl, $arg);
973 2 $arg;
974 }
975  
976  
977 1 ▶BEGIN {*Carg = \&PDL::Complex::Carg;
Subroutine BEGIN: called CC=1 SCAR=0.0
978 }
979  
980  
981  
982  
983  
984 =head2 Csin
985  
986 =for sig
987  
988 Signature: (a(m=2); [o]c(m=2))
989 Types: (float double ldouble)
990  
991 =for usage
992  
993 $c = Csin($a);
994 Csin($a, $c); # all arguments given
995 $c = $a->Csin; # method call
996 $a->Csin($c);
997 $a->inplace->Csin; # can be used inplace
998 Csin($a->inplace);
999  
1000 =for ref
1001  
1002 sin (a) = 1/(2*i) * (exp (a*i) - exp (-a*i)). Works inplace
1003  
1004 =pod
1005  
1006 Can operate inplace with C<a> as output C<c>.
1007 Broadcasts over its inputs.
1008  
1009 =for bad
1010  
1011 C<Csin> does not process bad values.
1012 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1013  
1014 =cut
1015  
1016  
1017  
1018  
1019 1 ▶BEGIN {*Csin = \&PDL::Complex::Csin;
Subroutine BEGIN: called CC=1 SCAR=0.0
1020 }
1021  
1022  
1023  
1024  
1025  
1026 =head2 Ccos
1027  
1028 =for sig
1029  
1030 Signature: (a(m=2); [o]c(m=2))
1031 Types: (float double ldouble)
1032  
1033 =for usage
1034  
1035 $c = Ccos($a);
1036 Ccos($a, $c); # all arguments given
1037 $c = $a->Ccos; # method call
1038 $a->Ccos($c);
1039 $a->inplace->Ccos; # can be used inplace
1040 Ccos($a->inplace);
1041  
1042 =for ref
1043  
1044 cos (a) = 1/2 * (exp (a*i) + exp (-a*i)). Works inplace
1045  
1046 =pod
1047  
1048 Can operate inplace with C<a> as output C<c>.
1049 Broadcasts over its inputs.
1050  
1051 =for bad
1052  
1053 C<Ccos> does not process bad values.
1054 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1055  
1056 =cut
1057  
1058  
1059  
1060  
1061 1 ▶BEGIN {*Ccos = \&PDL::Complex::Ccos;
Subroutine BEGIN: called CC=1 SCAR=0.0
1062 }
1063  
1064  
1065  
1066  
1067 #line 713 "complex.pd"
1068  
1069 =head2 Ctan
1070  
1071 =for ref
1072  
1073 Complex tangent
1074  
1075 tan (a) = -i * (exp (a*i) - exp (-a*i)) / (exp (a*i) + exp (-a*i))
1076  
1077 Does not work inplace.
1078  
1079 =cut
1080  
1081 sub Ctan($) { Csin($_[0]) / Ccos($_[0]) }
1082 #line 1083 "Complex.pm"
1083  
1084  
1085 =head2 Cexp
1086  
1087 =for sig
1088  
1089 Signature: (a(m=2); [o]c(m=2))
1090 Types: (float double ldouble)
1091  
1092 =for usage
1093  
1094 $c = Cexp($a);
1095 Cexp($a, $c); # all arguments given
1096 $c = $a->Cexp; # method call
1097 $a->Cexp($c);
1098 $a->inplace->Cexp; # can be used inplace
1099 Cexp($a->inplace);
1100  
1101 =for ref
1102  
1103 exp (a) = exp (real (a)) * (cos (imag (a)) + i * sin (imag (a))). Works inplace
1104  
1105 =pod
1106  
1107 Can operate inplace with C<a> as output C<c>.
1108 Broadcasts over its inputs.
1109  
1110 =for bad
1111  
1112 C<Cexp> does not process bad values.
1113 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1114  
1115 =cut
1116  
1117  
1118  
1119  
1120 1 ▶BEGIN {*Cexp = \&PDL::Complex::Cexp;
Subroutine BEGIN: called CC=1 SCAR=0.0
1121 }
1122  
1123  
1124  
1125  
1126  
1127 =head2 Clog
1128  
1129 =for sig
1130  
1131 Signature: (a(m=2); [o]c(m=2))
1132 Types: (float double ldouble)
1133  
1134 =for usage
1135  
1136 $c = Clog($a);
1137 Clog($a, $c); # all arguments given
1138 $c = $a->Clog; # method call
1139 $a->Clog($c);
1140 $a->inplace->Clog; # can be used inplace
1141 Clog($a->inplace);
1142  
1143 =for ref
1144  
1145 log (a) = log (cabs (a)) + i * carg (a). Works inplace
1146  
1147 =pod
1148  
1149 Can operate inplace with C<a> as output C<c>.
1150 Broadcasts over its inputs.
1151  
1152 =for bad
1153  
1154 C<Clog> does not process bad values.
1155 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1156  
1157 =cut
1158  
1159  
1160  
1161  
1162 1 ▶BEGIN {*Clog = \&PDL::Complex::Clog;
Subroutine BEGIN: called CC=1 SCAR=0.0
1163 }
1164  
1165  
1166  
1167  
1168  
1169 =head2 Cpow
1170  
1171 =for sig
1172  
1173 Signature: (a(m=2); b(m=2); [o]c(m=2))
1174 Types: (float double ldouble)
1175  
1176 =for usage
1177  
1178 $c = Cpow($a, $b);
1179 Cpow($a, $b, $c); # all arguments given
1180 $c = $a->Cpow($b); # method call
1181 $a->Cpow($b, $c);
1182 $a->inplace->Cpow($b); # can be used inplace
1183 Cpow($a->inplace, $b);
1184  
1185 =for ref
1186  
1187 complex C<pow()> (C<**>-operator)
1188  
1189 =pod
1190  
1191 Can operate inplace with C<a> as output C<c>.
1192 Broadcasts over its inputs.
1193  
1194 =for bad
1195  
1196 C<Cpow> does not process bad values.
1197 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1198  
1199 =cut
1200  
1201  
1202  
1203  
1204 1 ▶BEGIN {*Cpow = \&PDL::Complex::Cpow;
Subroutine BEGIN: called CC=1 SCAR=0.0
1205 }
1206  
1207  
1208  
1209  
1210  
1211 =head2 Csqrt
1212  
1213 =for sig
1214  
1215 Signature: (a(m=2); [o]c(m=2))
1216 Types: (float double ldouble)
1217  
1218 =for usage
1219  
1220 $c = Csqrt($a);
1221 Csqrt($a, $c); # all arguments given
1222 $c = $a->Csqrt; # method call
1223 $a->Csqrt($c);
1224 $a->inplace->Csqrt; # can be used inplace
1225 Csqrt($a->inplace);
1226  
1227 =for ref
1228  
1229 Works inplace
1230  
1231 =pod
1232  
1233 Can operate inplace with C<a> as output C<c>.
1234 Broadcasts over its inputs.
1235  
1236 =for bad
1237  
1238 C<Csqrt> does not process bad values.
1239 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1240  
1241 =cut
1242  
1243  
1244  
1245  
1246 1 ▶BEGIN {*Csqrt = \&PDL::Complex::Csqrt;
Subroutine BEGIN: called CC=1 SCAR=0.0
1247 }
1248  
1249  
1250  
1251  
1252  
1253 =head2 Casin
1254  
1255 =for sig
1256  
1257 Signature: (a(m=2); [o]c(m=2))
1258 Types: (float double ldouble)
1259  
1260 =for usage
1261  
1262 $c = Casin($a);
1263 Casin($a, $c); # all arguments given
1264 $c = $a->Casin; # method call
1265 $a->Casin($c);
1266 $a->inplace->Casin; # can be used inplace
1267 Casin($a->inplace);
1268  
1269 =for ref
1270  
1271 Works inplace
1272  
1273 =pod
1274  
1275 Can operate inplace with C<a> as output C<c>.
1276 Broadcasts over its inputs.
1277  
1278 =for bad
1279  
1280 C<Casin> does not process bad values.
1281 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1282  
1283 =cut
1284  
1285  
1286  
1287  
1288 1 ▶BEGIN {*Casin = \&PDL::Complex::Casin;
Subroutine BEGIN: called CC=1 SCAR=0.0
1289 }
1290  
1291  
1292  
1293  
1294  
1295 =head2 Cacos
1296  
1297 =for sig
1298  
1299 Signature: (a(m=2); [o]c(m=2))
1300 Types: (float double ldouble)
1301  
1302 =for usage
1303  
1304 $c = Cacos($a);
1305 Cacos($a, $c); # all arguments given
1306 $c = $a->Cacos; # method call
1307 $a->Cacos($c);
1308 $a->inplace->Cacos; # can be used inplace
1309 Cacos($a->inplace);
1310  
1311 =for ref
1312  
1313 Works inplace
1314  
1315 =pod
1316  
1317 Can operate inplace with C<a> as output C<c>.
1318 Broadcasts over its inputs.
1319  
1320 =for bad
1321  
1322 C<Cacos> does not process bad values.
1323 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1324  
1325 =cut
1326  
1327  
1328  
1329  
1330 1 ▶BEGIN {*Cacos = \&PDL::Complex::Cacos;
Subroutine BEGIN: called CC=1 SCAR=0.0
1331 }
1332  
1333  
1334  
1335  
1336 #line 859 "complex.pd"
1337  
1338 =head2 Catan
1339  
1340 =for ref
1341  
1342 Return the complex C<atan()>.
1343  
1344 Does not work inplace.
1345  
1346 =cut
1347  
1348 sub Catan($) {
1349 my $z = shift;
1350 Cmul Clog(Cdiv (PDL::Complex::i()+$z, PDL::Complex::i()-$z)), PDL->pdl(0, 0.5);
1351 }
1352 #line 1353 "Complex.pm"
1353  
1354  
1355 =head2 Csinh
1356  
1357 =for sig
1358  
1359 Signature: (a(m=2); [o]c(m=2))
1360 Types: (float double ldouble)
1361  
1362 =for usage
1363  
1364 $c = Csinh($a);
1365 Csinh($a, $c); # all arguments given
1366 $c = $a->Csinh; # method call
1367 $a->Csinh($c);
1368 $a->inplace->Csinh; # can be used inplace
1369 Csinh($a->inplace);
1370  
1371 =for ref
1372  
1373 sinh (a) = (exp (a) - exp (-a)) / 2. Works inplace
1374  
1375 =pod
1376  
1377 Can operate inplace with C<a> as output C<c>.
1378 Broadcasts over its inputs.
1379  
1380 =for bad
1381  
1382 C<Csinh> does not process bad values.
1383 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1384  
1385 =cut
1386  
1387  
1388  
1389  
1390 1 ▶BEGIN {*Csinh = \&PDL::Complex::Csinh;
Subroutine BEGIN: called CC=1 SCAR=0.0
1391 }
1392  
1393  
1394  
1395  
1396  
1397 =head2 Ccosh
1398  
1399 =for sig
1400  
1401 Signature: (a(m=2); [o]c(m=2))
1402 Types: (float double ldouble)
1403  
1404 =for usage
1405  
1406 $c = Ccosh($a);
1407 Ccosh($a, $c); # all arguments given
1408 $c = $a->Ccosh; # method call
1409 $a->Ccosh($c);
1410 $a->inplace->Ccosh; # can be used inplace
1411 Ccosh($a->inplace);
1412  
1413 =for ref
1414  
1415 cosh (a) = (exp (a) + exp (-a)) / 2. Works inplace
1416  
1417 =pod
1418  
1419 Can operate inplace with C<a> as output C<c>.
1420 Broadcasts over its inputs.
1421  
1422 =for bad
1423  
1424 C<Ccosh> does not process bad values.
1425 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1426  
1427 =cut
1428  
1429  
1430  
1431  
1432 1 ▶BEGIN {*Ccosh = \&PDL::Complex::Ccosh;
Subroutine BEGIN: called CC=1 SCAR=0.0
1433 }
1434  
1435  
1436  
1437  
1438  
1439 =head2 Ctanh
1440  
1441 =for sig
1442  
1443 Signature: (a(m=2); [o]c(m=2))
1444 Types: (float double ldouble)
1445  
1446 =for usage
1447  
1448 $c = Ctanh($a);
1449 Ctanh($a, $c); # all arguments given
1450 $c = $a->Ctanh; # method call
1451 $a->Ctanh($c);
1452 $a->inplace->Ctanh; # can be used inplace
1453 Ctanh($a->inplace);
1454  
1455 =for ref
1456  
1457 Works inplace
1458  
1459 =pod
1460  
1461 Can operate inplace with C<a> as output C<c>.
1462 Broadcasts over its inputs.
1463  
1464 =for bad
1465  
1466 C<Ctanh> does not process bad values.
1467 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1468  
1469 =cut
1470  
1471  
1472  
1473  
1474 1 ▶BEGIN {*Ctanh = \&PDL::Complex::Ctanh;
Subroutine BEGIN: called CC=1 SCAR=0.0
1475 }
1476  
1477  
1478  
1479  
1480  
1481 =head2 Casinh
1482  
1483 =for sig
1484  
1485 Signature: (a(m=2); [o]c(m=2))
1486 Types: (float double ldouble)
1487  
1488 =for usage
1489  
1490 $c = Casinh($a);
1491 Casinh($a, $c); # all arguments given
1492 $c = $a->Casinh; # method call
1493 $a->Casinh($c);
1494 $a->inplace->Casinh; # can be used inplace
1495 Casinh($a->inplace);
1496  
1497 =for ref
1498  
1499 Works inplace
1500  
1501 =pod
1502  
1503 Can operate inplace with C<a> as output C<c>.
1504 Broadcasts over its inputs.
1505  
1506 =for bad
1507  
1508 C<Casinh> does not process bad values.
1509 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1510  
1511 =cut
1512  
1513  
1514  
1515  
1516 1 ▶BEGIN {*Casinh = \&PDL::Complex::Casinh;
Subroutine BEGIN: called CC=1 SCAR=0.0
1517 }
1518  
1519  
1520  
1521  
1522  
1523 =head2 Cacosh
1524  
1525 =for sig
1526  
1527 Signature: (a(m=2); [o]c(m=2))
1528 Types: (float double ldouble)
1529  
1530 =for usage
1531  
1532 $c = Cacosh($a);
1533 Cacosh($a, $c); # all arguments given
1534 $c = $a->Cacosh; # method call
1535 $a->Cacosh($c);
1536 $a->inplace->Cacosh; # can be used inplace
1537 Cacosh($a->inplace);
1538  
1539 =for ref
1540  
1541 Works inplace
1542  
1543 =pod
1544  
1545 Can operate inplace with C<a> as output C<c>.
1546 Broadcasts over its inputs.
1547  
1548 =for bad
1549  
1550 C<Cacosh> does not process bad values.
1551 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1552  
1553 =cut
1554  
1555  
1556  
1557  
1558 1 ▶BEGIN {*Cacosh = \&PDL::Complex::Cacosh;
Subroutine BEGIN: called CC=1 SCAR=0.0
1559 }
1560  
1561  
1562  
1563  
1564  
1565 =head2 Catanh
1566  
1567 =for sig
1568  
1569 Signature: (a(m=2); [o]c(m=2))
1570 Types: (float double ldouble)
1571  
1572 =for usage
1573  
1574 $c = Catanh($a);
1575 Catanh($a, $c); # all arguments given
1576 $c = $a->Catanh; # method call
1577 $a->Catanh($c);
1578 $a->inplace->Catanh; # can be used inplace
1579 Catanh($a->inplace);
1580  
1581 =for ref
1582  
1583 Works inplace
1584  
1585 =pod
1586  
1587 Can operate inplace with C<a> as output C<c>.
1588 Broadcasts over its inputs.
1589  
1590 =for bad
1591  
1592 C<Catanh> does not process bad values.
1593 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1594  
1595 =cut
1596  
1597  
1598  
1599  
1600 1 ▶BEGIN {*Catanh = \&PDL::Complex::Catanh;
Subroutine BEGIN: called CC=1 SCAR=0.0
1601 }
1602  
1603  
1604  
1605  
1606  
1607 =head2 Cproj
1608  
1609 =for sig
1610  
1611 Signature: (a(m=2); [o]c(m=2))
1612 Types: (float double ldouble)
1613  
1614 =for usage
1615  
1616 $c = Cproj($a);
1617 Cproj($a, $c); # all arguments given
1618 $c = $a->Cproj; # method call
1619 $a->Cproj($c);
1620 $a->inplace->Cproj; # can be used inplace
1621 Cproj($a->inplace);
1622  
1623 =for ref
1624  
1625 compute the projection of a complex number to the riemann sphere. Works inplace
1626  
1627 =pod
1628  
1629 Can operate inplace with C<a> as output C<c>.
1630 Broadcasts over its inputs.
1631  
1632 =for bad
1633  
1634 C<Cproj> does not process bad values.
1635 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1636  
1637 =cut
1638  
1639  
1640  
1641  
1642 1 ▶BEGIN {*Cproj = \&PDL::Complex::Cproj;
Subroutine BEGIN: called CC=1 SCAR=0.0
1643 }
1644  
1645  
1646  
1647  
1648  
1649 =head2 Croots
1650  
1651 =for sig
1652  
1653 Signature: (a(m=2); [o]c(m=2,n); int n => n)
1654 Types: (float double ldouble)
1655  
1656 =for usage
1657  
1658 $c = Croots($a, $n);
1659 Croots($a, $c, $n); # all arguments given
1660 $c = $a->Croots($n); # method call
1661 $a->Croots($c, $n);
1662  
1663 =for ref
1664  
1665 Compute the C<n> roots of C<a>. C<n> must be a positive integer. The result will always be a complex type!
1666  
1667 =pod
1668  
1669 Broadcasts over its inputs.
1670  
1671 =for bad
1672  
1673 C<Croots> does not process bad values.
1674 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1675  
1676 =cut
1677  
1678  
1679  
1680  
1681 1 ▶sub PDL::Complex::Croots($$) {
Subroutine Croots: called CC=1 SCAR=0.0
Pod documented
1682 1 my ($pdl, $n) = @_;
1683 1 my $r = PDL->null;
1684 1 &PDL::Complex::_Croots_int($pdl, $r, $n);
1685 1 bless $r;
1686 }
1687  
1688  
1689 1 ▶BEGIN {*Croots = \&PDL::Complex::Croots;
Subroutine BEGIN: called CC=1 SCAR=0.0
1690 }
1691  
1692  
1693  
1694  
1695 #line 1027 "complex.pd"
1696  
1697 =head2 re, im
1698  
1699 Return the real or imaginary part of the complex number(s) given.
1700  
1701 These are slicing operators, so data flow works. The real and
1702 imaginary parts are returned as ndarrays (ref eq PDL).
1703  
1704 =cut
1705  
1706 sub re($) { $_[0]->slice("(0)") }
1707 sub im($) { $_[0]->slice("(1)") }
1708  
1709 {
1710 no warnings 'redefine';
1711 # if the argument does anything other than pass through 0-th dim, re-bless
1712 sub slice :lvalue {
1713 my $first = ref $_[1] ? $_[1][0] : (split ',', $_[1])[0];
1714 my $class = ($first//'') =~ /^[:x]?$/i ? ref($_[0]) : 'PDL';
1715 my $ret = bless $_[0]->SUPER::slice(@_[1..$#_]), $class;
1716 $ret;
1717 }
1718 }
1719 #line 1720 "Complex.pm"
1720  
1721  
1722 =head2 rCpolynomial
1723  
1724 =for sig
1725  
1726 Signature: (coeffs(n); x(c=2,m); [o]out(c=2,m))
1727 Types: (float double ldouble)
1728  
1729 =for usage
1730  
1731 $out = rCpolynomial($coeffs, $x);
1732 rCpolynomial($coeffs, $x, $out); # all arguments given
1733 $out = $coeffs->rCpolynomial($x); # method call
1734 $coeffs->rCpolynomial($x, $out);
1735  
1736 =for ref
1737  
1738 evaluate the polynomial with (real) coefficients C<coeffs> at the (complex) position(s) C<x>. C<coeffs[0]> is the constant term.
1739  
1740 =pod
1741  
1742 Broadcasts over its inputs.
1743  
1744 =for bad
1745  
1746 C<rCpolynomial> does not process bad values.
1747 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1748  
1749 =cut
1750  
1751  
1752  
1753  
1754  
1755 0 ▶sub rCpolynomial {
Subroutine rCpolynomial: called CC=1 SCAR=0.0
Pod documented
1756 2 my $coeffs = shift;
1757 2 my $x = shift;
1758 2 my $out = $x->copy;
1759 2 _rCpolynomial_int($coeffs,$x,$out);
1760 2 return PDL::complex($out);
1761 }
1762  
1763  
1764  
1765 1 ▶BEGIN {*rCpolynomial = \&PDL::Complex::rCpolynomial;
Subroutine BEGIN: called CC=1 SCAR=0.0
1766 }
1767  
1768  
1769  
1770  
1771  
1772 =head2 Ctricpy
1773  
1774 =for sig
1775  
1776 Signature: (A(c=2,m,n);[o] C(c=2,m,n); int uplo)
1777 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
1778 float double ldouble)
1779  
1780 =for usage
1781  
1782 tricpy(PDL(A), int(uplo), PDL(C))
1783  
1784 =for example
1785  
1786 $c = $a->tricpy($uplo); # explicit uplo
1787 $c = $a->tricpy; # default upper
1788  
1789 or
1790  
1791 tricpy($a, $uplo, $c); # modify c
1792  
1793 =for ref
1794  
1795 Copy triangular part to another matrix. If uplo == 0 copy upper triangular
1796 part.
1797  
1798 Originally by Grégory Vanuxem.
1799  
1800 =pod
1801  
1802 Broadcasts over its inputs.
1803  
1804 =for bad
1805  
1806 C<Ctricpy> does not process bad values.
1807 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1808  
1809 =cut
1810  
1811  
1812  
1813  
1814 1 ▶BEGIN {*Ctricpy = \&PDL::Complex::Ctricpy;
Subroutine BEGIN: called CC=1 SCAR=0.0
1815 }
1816  
1817  
1818  
1819  
1820  
1821 =head2 Cmstack
1822  
1823 =for sig
1824  
1825 Signature: (x(c=2,n,m);y(c,n,p);[o]out(c,n,q=CALC($SIZE(m)+$SIZE(p))))
1826 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
1827 float double ldouble)
1828  
1829 =for usage
1830  
1831 $out = Cmstack($x, $y);
1832 Cmstack($x, $y, $out); # all arguments given
1833 $out = $x->Cmstack($y); # method call
1834 $x->Cmstack($y, $out);
1835 $x->Cmstack($y) .= $data; # usable as lvalue
1836  
1837 =for ref
1838  
1839 Combine two 2D ndarrays into a single ndarray, along the second
1840 ("vertical") dim.
1841 This routine does backward and forward dataflow automatically.
1842  
1843 Originally by Grégory Vanuxem.
1844  
1845 =pod
1846  
1847 Broadcasts over its inputs.
1848 Creates data-flow back and forth by default.
1849  
1850 =for bad
1851  
1852 C<Cmstack> does not process bad values.
1853 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1854  
1855 =cut
1856  
1857  
1858  
1859  
1860 1 ▶BEGIN {*Cmstack = \&PDL::Complex::Cmstack;
Subroutine BEGIN: called CC=1 SCAR=0.0
1861 }
1862  
1863  
1864  
1865  
1866  
1867 =head2 Caugment
1868  
1869 =for sig
1870  
1871 Signature: (x(c=2,n);y(c,p);[o]out(c,q=CALC($SIZE(n)+$SIZE(p))))
1872 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
1873 float double ldouble)
1874  
1875 =for usage
1876  
1877 $out = Caugment($x, $y);
1878 Caugment($x, $y, $out); # all arguments given
1879 $out = $x->Caugment($y); # method call
1880 $x->Caugment($y, $out);
1881 $x->Caugment($y) .= $data; # usable as lvalue
1882  
1883 =for ref
1884  
1885 Combine two ndarrays into a single ndarray along the 0-th ("horizontal") dim.
1886 This routine does backward and forward dataflow automatically.
1887  
1888 Originally by Grégory Vanuxem.
1889  
1890 =pod
1891  
1892 Broadcasts over its inputs.
1893 Creates data-flow back and forth by default.
1894  
1895 =for bad
1896  
1897 C<Caugment> does not process bad values.
1898 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
1899  
1900 =cut
1901  
1902  
1903  
1904  
1905 1 ▶BEGIN {*Caugment = \&PDL::Complex::Caugment;
Subroutine BEGIN: called CC=1 SCAR=0.0
1906 }
1907  
1908  
1909  
1910  
1911  
1912  
1913 #line 1169 "complex.pd"
1914  
1915 # undocumented compatibility functions (thanks to Luis Mochan!)
1916 sub Catan2 { Clog( $_[1] + i()*$_[0])/i }
1917 sub atan2 { Clog( $_[1] + i()*$_[0])/i }
1918  
1919 =begin comment
1920  
1921 In _gen_biop, the '+' or '-' between the operator (e.g., '*') and the
1922 function that it overloads (e.g., 'Cmul') flags whether the operation
1923 is ('+') or is not ('-') commutative. See the discussion of argument
1924 swapping in the section "Calling Conventions and Magic Autogeneration"
1925 in "perldoc overload".
1926  
1927 =end comment
1928  
1929 =cut
1930  
1931 my %NO_MUTATE; BEGIN { @NO_MUTATE{qw(atan2 .= ==)} = (); }
1932 sub _gen_biop {
1933 local $_ = shift;
1934 my $sub;
1935 die if !(my ($op, $commutes, $func) = /(\S+)([-+])(\w+)/);
1936 $sub = eval 'sub {
1937 my ($x, $y) = '.($commutes eq '+' ? '' : '$_[2] ? @_[1,0] : ').'@_[0,1];
1938 $_ = r2C $_ for grep ref $_ ne __PACKAGE__, $x, $y;
1939 '.$func.'($x, $y);
1940 }'; #need to swap?
1941 die if $@;
1942 ($op, $sub, exists $NO_MUTATE{$op} ? () : ("$op=", $sub));
1943 }
1944  
1945 sub _gen_unop {
1946 my ($op, $func) = split '@', $_[0];
1947 no strict 'refs';
1948 *$op = \&$func if $op =~ /\w+/; # create an alias
1949 ($op, eval 'sub { '.$func.' $_[0] }');
1950 }
1951  
1952 sub initialize {
1953 # Bless a null PDL into the supplied 1st arg package
1954 # If 1st arg is a ref, get the package from it
1955 bless PDL->null, ref($_[0]) || $_[0];
1956 }
1957  
1958 # so broadcasting doesn't also assign the real value into the imaginary
1959 sub Cassgn {
1960 my @args = !$_[2] ? @_[1,0] : @_[0,1];
1961 $args[1] = r2C($args[1]) if ref $args[1] ne __PACKAGE__;
1962 PDL::Ops::assgn(@args);
1963 $args[1];
1964 }
1965  
1966 use overload
1967 (map _gen_biop($_), qw(++Cadd --Csub *+Cmul /-Cdiv **-Cpow atan2-Catan2 ==+Ceq .=-Cassgn)),
1968 (map _gen_unop($_), qw(sin@Csin cos@Ccos exp@Cexp abs@Cabs log@Clog sqrt@Csqrt)),
1969 (map +($_ => sub { confess "Can't compare complex numbers" }), qw(< > <= >=)),
1970 "!=" => sub { !($_[0] == $_[1]) },
1971 '""' => sub { $_[0]->isnull ? "PDL::Complex->null" : $_[0]->as_native->string },
1972 ;
1973  
1974 sub sum {
1975 my($x) = @_;
1976 return $x if $x->dims==1;
1977 my $tmp = $x->mv(0,-1)->clump(-2)->mv(1,0)->sumover;
1978 return $tmp;
1979 }
1980  
1981 sub sumover{
1982 my $m = shift;
1983 PDL::Ufunc::sumover($m->transpose);
1984 }
1985  
1986 *PDL::Complex::Csumover=\&sumover; # define through alias
1987  
1988 *PDL::Complex::prodover=\&Cprodover; # define through alias
1989  
1990 sub prod {
1991 my($x) = @_;
1992 return $x if $x->dims==1;
1993 my $tmp = $x->mv(0,-1)->clump(-2)->mv(1,0)->prodover;
1994 return $tmp;
1995 }
1996  
1997 =head1 AUTHOR
1998  
1999 Copyright (C) 2000 Marc Lehmann <pcg@goof.com>.
2000 All rights reserved. There is no warranty. You are allowed
2001 to redistribute this software / documentation as described
2002 in the file COPYING in the PDL distribution.
2003  
2004 =head1 SEE ALSO
2005  
2006 perl(1), L<PDL>.
2007  
2008 =cut
2009 #line 2010 "Complex.pm"
2010  
2011 # Exit with OK status
2012  
2013 0 1;
« complex.pd ↑ Summary pp-Cproj.c »