line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# GENERATED WITH PDLA::PP! Don't modify! |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
package PDLA::Complex; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
@EXPORT_OK = qw( Ctan Catan re im i cplx real PDLA::PP r2C PDLA::PP i2C PDLA::PP Cr2p PDLA::PP Cp2r PDLA::PP Cadd PDLA::PP Csub PDLA::PP Cmul PDLA::PP Cprodover PDLA::PP Cscale PDLA::PP Cdiv PDLA::PP Ccmp PDLA::PP Cconj PDLA::PP Cabs PDLA::PP Cabs2 PDLA::PP Carg PDLA::PP Csin PDLA::PP Ccos PDLA::PP Cexp PDLA::PP Clog PDLA::PP Cpow PDLA::PP Csqrt PDLA::PP Casin PDLA::PP Cacos PDLA::PP Csinh PDLA::PP Ccosh PDLA::PP Ctanh PDLA::PP Casinh PDLA::PP Cacosh PDLA::PP Catanh PDLA::PP Cproj PDLA::PP Croots PDLA::PP rCpolynomial ); |
8
|
|
|
|
|
|
|
%EXPORT_TAGS = (Func=>[@EXPORT_OK]); |
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
489
|
use PDLA::Core; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
17
|
|
11
|
3
|
|
|
3
|
|
17
|
use PDLA::Exporter; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
15
|
|
12
|
3
|
|
|
3
|
|
17
|
use DynaLoader; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
165
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
BEGIN { |
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
3
|
|
56
|
@ISA = ( 'PDLA::Exporter','DynaLoader','PDLA' ); |
18
|
3
|
|
|
|
|
9
|
push @PDLA::Core::PP, __PACKAGE__; |
19
|
3
|
|
|
|
|
1413
|
bootstrap PDLA::Complex ; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our $VERSION = "2.019000"; |
25
|
3
|
|
|
3
|
|
147
|
use PDLA::Slices; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
17
|
|
26
|
3
|
|
|
3
|
|
18
|
use PDLA::Types; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
314
|
|
27
|
3
|
|
|
3
|
|
17
|
use PDLA::Bad; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
17
|
|
28
|
|
|
|
|
|
|
|
29
|
3
|
|
|
3
|
|
19
|
use vars qw($sep $sep2); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
292
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=encoding iso-8859-1 |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 NAME |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
PDLA::Complex - handle complex numbers |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 SYNOPSIS |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
use PDLA; |
42
|
|
|
|
|
|
|
use PDLA::Complex; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
This module features a growing number of functions manipulating complex |
47
|
|
|
|
|
|
|
numbers. These are usually represented as a pair C<[ real imag ]> or |
48
|
|
|
|
|
|
|
C<[ magnitude phase ]>. If not explicitly mentioned, the functions can work |
49
|
|
|
|
|
|
|
inplace (not yet implemented!!!) and require rectangular form. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
While there is a procedural interface available (C<< $x/$y*$c <=> Cmul |
52
|
|
|
|
|
|
|
(Cdiv ($x, $y), $c) >>), you can also opt to cast your pdl's into the |
53
|
|
|
|
|
|
|
C datatype, which works just like your normal piddles, but |
54
|
|
|
|
|
|
|
with all the normal perl operators overloaded. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
The latter means that C will be evaluated using the |
57
|
|
|
|
|
|
|
normal rules of complex numbers, while other pdl functions (like C) |
58
|
|
|
|
|
|
|
just treat the piddle as a real-valued piddle with a lowest dimension of |
59
|
|
|
|
|
|
|
size 2, so C will return the maximum of all real and imaginary parts, |
60
|
|
|
|
|
|
|
not the "highest" (for some definition) |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 TIPS, TRICKS & CAVEATS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=over 4 |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item * |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
C is a constant exported by this module, which represents |
69
|
|
|
|
|
|
|
C<-1**0.5>, i.e. the imaginary unit. it can be used to quickly and |
70
|
|
|
|
|
|
|
conveniently write complex constants like this: C<4+3*i>. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item * |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Use C to convert from real to complex, as in C<$r |
75
|
|
|
|
|
|
|
= Cpow $cplx, r2C 2>. The overloaded operators automatically do that for |
76
|
|
|
|
|
|
|
you, all the other functions, do not. So C will return all |
77
|
|
|
|
|
|
|
the fifths roots of 1+1*i (due to threading). |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item * |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
use C to cast from normal piddles into the |
82
|
|
|
|
|
|
|
complex datatype. Use C to cast back. This |
83
|
|
|
|
|
|
|
requires a copy, though. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item * |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This module has received some testing by Vanuxem Grégory |
88
|
|
|
|
|
|
|
(g.vanuxem at wanadoo dot fr). Please report any other errors you |
89
|
|
|
|
|
|
|
come across! |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=back |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 EXAMPLE WALK-THROUGH |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
The complex constant five is equal to C: |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
pdla> p $x = r2C 5 |
98
|
|
|
|
|
|
|
5 +0i |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Now calculate the three cubic roots of of five: |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
pdla> p $r = Croots $x, 3 |
103
|
|
|
|
|
|
|
[1.70998 +0i -0.854988 +1.48088i -0.854988 -1.48088i] |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Check that these really are the roots: |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
pdla> p $r ** 3 |
108
|
|
|
|
|
|
|
[5 +0i 5 -1.22465e-15i 5 -7.65714e-15i] |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Duh! Could be better. Now try by multiplying C<$r> three times with itself: |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
pdla> p $r*$r*$r |
113
|
|
|
|
|
|
|
[5 +0i 5 -4.72647e-15i 5 -7.53694e-15i] |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Well... maybe C (which is used by the C<**> operator) isn't as |
116
|
|
|
|
|
|
|
bad as I thought. Now multiply by C and negate, which is just a very |
117
|
|
|
|
|
|
|
expensive way of swapping real and imaginary parts. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
pdla> p -($r*i) |
120
|
|
|
|
|
|
|
[0 -1.70998i 1.48088 +0.854988i -1.48088 +0.854988i] |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Now plot the magnitude of (part of) the complex sine. First generate the |
123
|
|
|
|
|
|
|
coefficients: |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
pdla> $sin = i * zeroes(50)->xlinvals(2,4) + zeroes(50)->xlinvals(0,7) |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Now plot the imaginary part, the real part and the magnitude of the sine |
128
|
|
|
|
|
|
|
into the same diagram: |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
pdla> use PDLA::Graphics::Gnuplot |
131
|
|
|
|
|
|
|
pdla> gplot( with => 'lines', |
132
|
|
|
|
|
|
|
PDLA::cat(im ( sin $sin ), |
133
|
|
|
|
|
|
|
re ( sin $sin ), |
134
|
|
|
|
|
|
|
abs( sin $sin ) )) |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
An ASCII version of this plot looks like this: |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
30 ++-----+------+------+------+------+------+------+------+------+-----++ |
139
|
|
|
|
|
|
|
+ + + + + + + + + + + |
140
|
|
|
|
|
|
|
| $$| |
141
|
|
|
|
|
|
|
| $ | |
142
|
|
|
|
|
|
|
25 ++ $$ ++ |
143
|
|
|
|
|
|
|
| *** | |
144
|
|
|
|
|
|
|
| ** *** | |
145
|
|
|
|
|
|
|
| $$* *| |
146
|
|
|
|
|
|
|
20 ++ $** ++ |
147
|
|
|
|
|
|
|
| $$$* #| |
148
|
|
|
|
|
|
|
| $$$ * # | |
149
|
|
|
|
|
|
|
| $$ * # | |
150
|
|
|
|
|
|
|
15 ++ $$$ * # ++ |
151
|
|
|
|
|
|
|
| $$$ ** # | |
152
|
|
|
|
|
|
|
| $$$$ * # | |
153
|
|
|
|
|
|
|
| $$$$ * # | |
154
|
|
|
|
|
|
|
10 ++ $$$$$ * # ++ |
155
|
|
|
|
|
|
|
| $$$$$ * # | |
156
|
|
|
|
|
|
|
| $$$$$$$ * # | |
157
|
|
|
|
|
|
|
5 ++ $$$############ * # ++ |
158
|
|
|
|
|
|
|
|*****$$$### ### * # | |
159
|
|
|
|
|
|
|
* #***** # * # | |
160
|
|
|
|
|
|
|
| ### *** ### ** # | |
161
|
|
|
|
|
|
|
0 ## *** # * # ++ |
162
|
|
|
|
|
|
|
| * # * # | |
163
|
|
|
|
|
|
|
| *** # ** # | |
164
|
|
|
|
|
|
|
| * # * # | |
165
|
|
|
|
|
|
|
-5 ++ ** # * # ++ |
166
|
|
|
|
|
|
|
| *** ## ** # | |
167
|
|
|
|
|
|
|
| * #* # | |
168
|
|
|
|
|
|
|
| **** ***## # | |
169
|
|
|
|
|
|
|
-10 ++ **** # # ++ |
170
|
|
|
|
|
|
|
| # # | |
171
|
|
|
|
|
|
|
| ## ## | |
172
|
|
|
|
|
|
|
+ + + + + + + ### + ### + + + |
173
|
|
|
|
|
|
|
-15 ++-----+------+------+------+------+------+-----###-----+------+-----++ |
174
|
|
|
|
|
|
|
0 5 10 15 20 25 30 35 40 45 50 |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 OPERATORS |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
The following operators are overloaded: |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=over 4 |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item +, += (addition) |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=item -, -= (subtraction) |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item *, *= (multiplication; L) |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item /, /= (division; L) |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item **, **= (exponentiation; L) |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item atan2 (4-quadrant arc tangent) |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item <=> (nonsensical comparison operator; L) |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=item sin (L) |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item cos (L) |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=item exp (L) |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item abs (L) |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=item log (L) |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=item sqrt (L) |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=item <, <=, ==, !=, >=, > (just as nonsensical as L) |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=item ++, -- (increment, decrement; they affect the real part of the complex number only) |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item "" (stringification) |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=back |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=cut |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
my $i; |
220
|
3
|
|
|
3
|
|
20
|
BEGIN { $i = bless pdl 0,1 } |
221
|
53
|
|
|
53
|
0
|
7814
|
sub i () { $i->copy }; |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 FUNCTIONS |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=cut |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head2 cplx |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=for ref |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Cast a real-valued piddle to the complex datatype. |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
The first dimension of the piddle must be of size 2. After this the |
245
|
|
|
|
|
|
|
usual (complex) arithmetic operators are applied to this pdl, rather |
246
|
|
|
|
|
|
|
than the normal elementwise pdl operators. Dataflow to the complex |
247
|
|
|
|
|
|
|
parent works. Use C on the result if you don't want this. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=for usage |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
cplx($real_valued_pdl) |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=head2 complex |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=for ref |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
Cast a real-valued piddle to the complex datatype I dataflow |
258
|
|
|
|
|
|
|
and I. |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
Achieved by merely reblessing a piddle. The first dimension of the |
261
|
|
|
|
|
|
|
piddle must be of size 2. |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=for usage |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
complex($real_valued_pdl) |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=head2 real |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=for ref |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
Cast a complex valued pdl back to the "normal" pdl datatype. |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
Afterwards the normal elementwise pdl operators are used in |
274
|
|
|
|
|
|
|
operations. Dataflow to the real parent works. Use C on the |
275
|
|
|
|
|
|
|
result if you don't want this. |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=for usage |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
real($cplx_valued_pdl) |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=cut |
282
|
|
|
|
|
|
|
|
283
|
3
|
|
|
3
|
|
19
|
use Carp; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
972
|
|
284
|
|
|
|
|
|
|
sub cplx($) { |
285
|
4
|
50
|
|
4
|
1
|
748
|
return $_[0] if UNIVERSAL::isa($_[0],'PDLA::Complex'); # NOOP if just piddle |
286
|
4
|
50
|
33
|
|
|
17
|
croak "first dimsize must be 2" unless $_[0]->dims > 0 && $_[0]->dim(0) == 2; |
287
|
4
|
|
|
|
|
15
|
bless $_[0]->slice(''); |
288
|
|
|
|
|
|
|
} |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
sub complex($) { |
291
|
10
|
100
|
|
10
|
1
|
714
|
return $_[0] if UNIVERSAL::isa($_[0],'PDLA::Complex'); # NOOP if just piddle |
292
|
8
|
50
|
33
|
|
|
22
|
croak "first dimsize must be 2" unless $_[0]->dims > 0 && $_[0]->dim(0) == 2; |
293
|
8
|
|
|
|
|
48
|
bless $_[0]; |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
*PDLA::cplx = \&cplx; |
297
|
|
|
|
|
|
|
*PDLA::complex = \&complex; |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
sub real($) { |
300
|
62
|
50
|
|
62
|
1
|
3114
|
return $_[0] unless UNIVERSAL::isa($_[0],'PDLA::Complex'); # NOOP unless complex |
301
|
62
|
|
|
|
|
131
|
bless $_[0]->slice(''), 'PDLA'; |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
=head2 r2C |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
=for sig |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
Signature: (r(); [o]c(m=2)) |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=for ref |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
convert real to complex, assuming an imaginary part of zero |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
=for bad |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
r2C does not process bad values. |
321
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
=cut |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
*PDLA::r2C = \&PDLA::Complex::r2C; |
331
|
|
|
|
|
|
|
sub PDLA::Complex::r2C($) { |
332
|
73
|
50
|
|
73
|
1
|
1199
|
return $_[0] if UNIVERSAL::isa($_[0],'PDLA::Complex'); |
333
|
73
|
|
|
|
|
131
|
my $r = __PACKAGE__->initialize; |
334
|
73
|
|
|
|
|
695
|
&PDLA::Complex::_r2C_int($_[0], $r); |
335
|
73
|
|
|
|
|
681
|
$r } |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
|
339
|
3
|
|
|
3
|
|
195
|
BEGIN {*r2C = \&PDLA::Complex::r2C; |
340
|
|
|
|
|
|
|
} |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=head2 i2C |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
=for sig |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
Signature: (r(); [o]c(m=2)) |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
=for ref |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
convert imaginary to complex, assuming a real part of zero |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
=for bad |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
i2C does not process bad values. |
358
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
=cut |
362
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
|
366
|
3
|
|
|
3
|
1
|
10
|
*PDLA::i2C = \&PDLA::Complex::i2C; sub PDLA::Complex::i2C($) { my $r = __PACKAGE__->initialize; &PDLA::Complex::_i2C_int($_[0], $r); $r } |
|
3
|
|
|
|
|
42
|
|
|
3
|
|
|
|
|
21
|
|
367
|
|
|
|
|
|
|
|
368
|
3
|
|
|
3
|
|
75
|
BEGIN {*i2C = \&PDLA::Complex::i2C; |
369
|
|
|
|
|
|
|
} |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
=head2 Cr2p |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
=for sig |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
Signature: (r(m=2); float+ [o]p(m=2)) |
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
=for ref |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
convert complex numbers in rectangular form to polar (mod,arg) form. Works inplace |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
=for bad |
385
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
Cr2p does not process bad values. |
387
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
=cut |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
|
397
|
3
|
|
|
3
|
|
77
|
BEGIN {*Cr2p = \&PDLA::Complex::Cr2p; |
398
|
|
|
|
|
|
|
} |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
=head2 Cp2r |
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
=for sig |
406
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
Signature: (r(m=2); [o]p(m=2)) |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
=for ref |
410
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
convert complex numbers in polar (mod,arg) form to rectangular form. Works inplace |
412
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
=for bad |
414
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
Cp2r does not process bad values. |
416
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
=cut |
420
|
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
|
426
|
3
|
|
|
3
|
|
57
|
BEGIN {*Cp2r = \&PDLA::Complex::Cp2r; |
427
|
|
|
|
|
|
|
} |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
|
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
|
432
|
3
|
|
|
3
|
|
67
|
BEGIN {*Cadd = \&PDLA::Complex::Cadd; |
433
|
|
|
|
|
|
|
} |
434
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
|
438
|
3
|
|
|
3
|
|
64
|
BEGIN {*Csub = \&PDLA::Complex::Csub; |
439
|
|
|
|
|
|
|
} |
440
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
=head2 Cmul |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
=for sig |
447
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
Signature: (a(m=2); b(m=2); [o]c(m=2)) |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
=for ref |
451
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
complex multiplication |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
=for bad |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
Cmul does not process bad values. |
457
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
=cut |
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
|
467
|
3
|
|
|
3
|
|
69
|
BEGIN {*Cmul = \&PDLA::Complex::Cmul; |
468
|
|
|
|
|
|
|
} |
469
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
=head2 Cprodover |
474
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
=for sig |
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
Signature: (a(m=2,n); [o]c(m=2)) |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
=for ref |
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
Project via product to N-1 dimension |
482
|
|
|
|
|
|
|
|
483
|
|
|
|
|
|
|
=for bad |
484
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
Cprodover does not process bad values. |
486
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
487
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
=cut |
490
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
|
496
|
3
|
|
|
3
|
|
79
|
BEGIN {*Cprodover = \&PDLA::Complex::Cprodover; |
497
|
|
|
|
|
|
|
} |
498
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
=head2 Cscale |
503
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
=for sig |
505
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
Signature: (a(m=2); b(); [o]c(m=2)) |
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
=for ref |
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
mixed complex/real multiplication |
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
=for bad |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
Cscale does not process bad values. |
515
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
=cut |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
|
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
|
525
|
3
|
|
|
3
|
|
74
|
BEGIN {*Cscale = \&PDLA::Complex::Cscale; |
526
|
|
|
|
|
|
|
} |
527
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
=head2 Cdiv |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
=for sig |
534
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
Signature: (a(m=2); b(m=2); [o]c(m=2)) |
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
=for ref |
538
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
complex division |
540
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
=for bad |
542
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
Cdiv does not process bad values. |
544
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
545
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
|
547
|
|
|
|
|
|
|
=cut |
548
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
|
554
|
3
|
|
|
3
|
|
75
|
BEGIN {*Cdiv = \&PDLA::Complex::Cdiv; |
555
|
|
|
|
|
|
|
} |
556
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
|
559
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
=head2 Ccmp |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
=for sig |
563
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
Signature: (a(m=2); b(m=2); [o]c()) |
565
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
=for ref |
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
Complex comparison operator (spaceship). |
569
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
Ccmp orders by real first, then by imaginary. Hm, but it is mathematical nonsense! Complex numbers cannot be ordered. |
571
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
=for bad |
573
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
Ccmp does not process bad values. |
575
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
=cut |
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
|
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
|
585
|
3
|
|
|
3
|
|
56
|
BEGIN {*Ccmp = \&PDLA::Complex::Ccmp; |
586
|
|
|
|
|
|
|
} |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
=head2 Cconj |
592
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
=for sig |
594
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
Signature: (a(m=2); [o]c(m=2)) |
596
|
|
|
|
|
|
|
|
597
|
|
|
|
|
|
|
=for ref |
598
|
|
|
|
|
|
|
|
599
|
|
|
|
|
|
|
complex conjugation. Works inplace |
600
|
|
|
|
|
|
|
|
601
|
|
|
|
|
|
|
=for bad |
602
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
Cconj does not process bad values. |
604
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
605
|
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
|
607
|
|
|
|
|
|
|
=cut |
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
|
614
|
3
|
|
|
3
|
|
241
|
BEGIN {*Cconj = \&PDLA::Complex::Cconj; |
615
|
|
|
|
|
|
|
} |
616
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
=head2 Cabs |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
=for sig |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
Signature: (a(m=2); [o]c()) |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
=for ref |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
complex C (also known as I) |
629
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
=for bad |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
Cabs does not process bad values. |
633
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
634
|
|
|
|
|
|
|
|
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
=cut |
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
|
639
|
|
|
|
|
|
|
|
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
sub PDLA::Complex::Cabs($) { |
642
|
8
|
|
|
8
|
1
|
30
|
my $pdl= shift; |
643
|
8
|
|
|
|
|
18
|
my $abs = PDLA->null; |
644
|
8
|
|
|
|
|
110
|
&PDLA::Complex::_Cabs_int($pdl, $abs); |
645
|
8
|
|
|
|
|
121
|
$abs; |
646
|
|
|
|
|
|
|
} |
647
|
|
|
|
|
|
|
|
648
|
3
|
|
|
3
|
|
180
|
BEGIN {*Cabs = \&PDLA::Complex::Cabs; |
649
|
|
|
|
|
|
|
} |
650
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
|
653
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
=head2 Cabs2 |
655
|
|
|
|
|
|
|
|
656
|
|
|
|
|
|
|
=for sig |
657
|
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
Signature: (a(m=2); [o]c()) |
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
=for ref |
661
|
|
|
|
|
|
|
|
662
|
|
|
|
|
|
|
complex squared C (also known I) |
663
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
=for bad |
665
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
Cabs2 does not process bad values. |
667
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
668
|
|
|
|
|
|
|
|
669
|
|
|
|
|
|
|
|
670
|
|
|
|
|
|
|
=cut |
671
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
|
674
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
sub PDLA::Complex::Cabs2($) { |
676
|
2
|
|
|
2
|
1
|
350
|
my $pdl= shift; |
677
|
2
|
|
|
|
|
9
|
my $abs2 = PDLA->null; |
678
|
2
|
|
|
|
|
23
|
&PDLA::Complex::_Cabs2_int($pdl, $abs2); |
679
|
2
|
|
|
|
|
9
|
$abs2; |
680
|
|
|
|
|
|
|
} |
681
|
|
|
|
|
|
|
|
682
|
3
|
|
|
3
|
|
258
|
BEGIN {*Cabs2 = \&PDLA::Complex::Cabs2; |
683
|
|
|
|
|
|
|
} |
684
|
|
|
|
|
|
|
|
685
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
|
687
|
|
|
|
|
|
|
|
688
|
|
|
|
|
|
|
=head2 Carg |
689
|
|
|
|
|
|
|
|
690
|
|
|
|
|
|
|
=for sig |
691
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
Signature: (a(m=2); [o]c()) |
693
|
|
|
|
|
|
|
|
694
|
|
|
|
|
|
|
=for ref |
695
|
|
|
|
|
|
|
|
696
|
|
|
|
|
|
|
complex argument function ("angle") |
697
|
|
|
|
|
|
|
|
698
|
|
|
|
|
|
|
=for bad |
699
|
|
|
|
|
|
|
|
700
|
|
|
|
|
|
|
Carg does not process bad values. |
701
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
702
|
|
|
|
|
|
|
|
703
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
=cut |
705
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
|
707
|
|
|
|
|
|
|
|
708
|
|
|
|
|
|
|
|
709
|
|
|
|
|
|
|
sub PDLA::Complex::Carg($) { |
710
|
2
|
|
|
2
|
1
|
3
|
my $pdl= shift; |
711
|
2
|
|
|
|
|
7
|
my $arg = PDLA->null; |
712
|
2
|
|
|
|
|
34
|
&PDLA::Complex::_Carg_int($pdl, $arg); |
713
|
2
|
|
|
|
|
10
|
$arg; |
714
|
|
|
|
|
|
|
} |
715
|
|
|
|
|
|
|
|
716
|
3
|
|
|
3
|
|
125
|
BEGIN {*Carg = \&PDLA::Complex::Carg; |
717
|
|
|
|
|
|
|
} |
718
|
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
|
720
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
|
722
|
|
|
|
|
|
|
=head2 Csin |
723
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
=for sig |
725
|
|
|
|
|
|
|
|
726
|
|
|
|
|
|
|
Signature: (a(m=2); [o]c(m=2)) |
727
|
|
|
|
|
|
|
|
728
|
|
|
|
|
|
|
=for ref |
729
|
|
|
|
|
|
|
|
730
|
|
|
|
|
|
|
sin (a) = 1/(2*i) * (exp (a*i) - exp (-a*i)). Works inplace |
731
|
|
|
|
|
|
|
|
732
|
|
|
|
|
|
|
=for bad |
733
|
|
|
|
|
|
|
|
734
|
|
|
|
|
|
|
Csin does not process bad values. |
735
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
736
|
|
|
|
|
|
|
|
737
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
=cut |
739
|
|
|
|
|
|
|
|
740
|
|
|
|
|
|
|
|
741
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
|
743
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
|
745
|
3
|
|
|
3
|
|
70
|
BEGIN {*Csin = \&PDLA::Complex::Csin; |
746
|
|
|
|
|
|
|
} |
747
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
|
749
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
|
751
|
|
|
|
|
|
|
=head2 Ccos |
752
|
|
|
|
|
|
|
|
753
|
|
|
|
|
|
|
=for sig |
754
|
|
|
|
|
|
|
|
755
|
|
|
|
|
|
|
Signature: (a(m=2); [o]c(m=2)) |
756
|
|
|
|
|
|
|
|
757
|
|
|
|
|
|
|
=for ref |
758
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
cos (a) = 1/2 * (exp (a*i) + exp (-a*i)). Works inplace |
760
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
=for bad |
762
|
|
|
|
|
|
|
|
763
|
|
|
|
|
|
|
Ccos does not process bad values. |
764
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
765
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
|
767
|
|
|
|
|
|
|
=cut |
768
|
|
|
|
|
|
|
|
769
|
|
|
|
|
|
|
|
770
|
|
|
|
|
|
|
|
771
|
|
|
|
|
|
|
|
772
|
|
|
|
|
|
|
|
773
|
|
|
|
|
|
|
|
774
|
3
|
|
|
3
|
|
185
|
BEGIN {*Ccos = \&PDLA::Complex::Ccos; |
775
|
|
|
|
|
|
|
} |
776
|
|
|
|
|
|
|
|
777
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
|
779
|
|
|
|
|
|
|
=head2 Ctan |
780
|
|
|
|
|
|
|
|
781
|
|
|
|
|
|
|
=for ref |
782
|
|
|
|
|
|
|
|
783
|
|
|
|
|
|
|
Complex tangent |
784
|
|
|
|
|
|
|
|
785
|
|
|
|
|
|
|
tan (a) = -i * (exp (a*i) - exp (-a*i)) / (exp (a*i) + exp (-a*i)) |
786
|
|
|
|
|
|
|
|
787
|
|
|
|
|
|
|
Does not work inplace. |
788
|
|
|
|
|
|
|
|
789
|
|
|
|
|
|
|
=cut |
790
|
|
|
|
|
|
|
|
791
|
5
|
|
|
5
|
1
|
21
|
sub Ctan($) { Csin($_[0]) / Ccos($_[0]) } |
792
|
|
|
|
|
|
|
|
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
|
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
|
797
|
|
|
|
|
|
|
|
798
|
|
|
|
|
|
|
=head2 Cexp |
799
|
|
|
|
|
|
|
|
800
|
|
|
|
|
|
|
=for sig |
801
|
|
|
|
|
|
|
|
802
|
|
|
|
|
|
|
Signature: (a(m=2); [o]c(m=2)) |
803
|
|
|
|
|
|
|
|
804
|
|
|
|
|
|
|
=for ref |
805
|
|
|
|
|
|
|
|
806
|
|
|
|
|
|
|
exp (a) = exp (real (a)) * (cos (imag (a)) + i * sin (imag (a))). Works inplace |
807
|
|
|
|
|
|
|
|
808
|
|
|
|
|
|
|
=for bad |
809
|
|
|
|
|
|
|
|
810
|
|
|
|
|
|
|
Cexp does not process bad values. |
811
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
812
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
|
814
|
|
|
|
|
|
|
=cut |
815
|
|
|
|
|
|
|
|
816
|
|
|
|
|
|
|
|
817
|
|
|
|
|
|
|
|
818
|
|
|
|
|
|
|
|
819
|
|
|
|
|
|
|
|
820
|
|
|
|
|
|
|
|
821
|
3
|
|
|
3
|
|
62
|
BEGIN {*Cexp = \&PDLA::Complex::Cexp; |
822
|
|
|
|
|
|
|
} |
823
|
|
|
|
|
|
|
|
824
|
|
|
|
|
|
|
|
825
|
|
|
|
|
|
|
|
826
|
|
|
|
|
|
|
|
827
|
|
|
|
|
|
|
=head2 Clog |
828
|
|
|
|
|
|
|
|
829
|
|
|
|
|
|
|
=for sig |
830
|
|
|
|
|
|
|
|
831
|
|
|
|
|
|
|
Signature: (a(m=2); [o]c(m=2)) |
832
|
|
|
|
|
|
|
|
833
|
|
|
|
|
|
|
=for ref |
834
|
|
|
|
|
|
|
|
835
|
|
|
|
|
|
|
log (a) = log (cabs (a)) + i * carg (a). Works inplace |
836
|
|
|
|
|
|
|
|
837
|
|
|
|
|
|
|
=for bad |
838
|
|
|
|
|
|
|
|
839
|
|
|
|
|
|
|
Clog does not process bad values. |
840
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
841
|
|
|
|
|
|
|
|
842
|
|
|
|
|
|
|
|
843
|
|
|
|
|
|
|
=cut |
844
|
|
|
|
|
|
|
|
845
|
|
|
|
|
|
|
|
846
|
|
|
|
|
|
|
|
847
|
|
|
|
|
|
|
|
848
|
|
|
|
|
|
|
|
849
|
|
|
|
|
|
|
|
850
|
3
|
|
|
3
|
|
73
|
BEGIN {*Clog = \&PDLA::Complex::Clog; |
851
|
|
|
|
|
|
|
} |
852
|
|
|
|
|
|
|
|
853
|
|
|
|
|
|
|
|
854
|
|
|
|
|
|
|
|
855
|
|
|
|
|
|
|
|
856
|
|
|
|
|
|
|
=head2 Cpow |
857
|
|
|
|
|
|
|
|
858
|
|
|
|
|
|
|
=for sig |
859
|
|
|
|
|
|
|
|
860
|
|
|
|
|
|
|
Signature: (a(m=2); b(m=2); [o]c(m=2)) |
861
|
|
|
|
|
|
|
|
862
|
|
|
|
|
|
|
=for ref |
863
|
|
|
|
|
|
|
|
864
|
|
|
|
|
|
|
complex C (C<**>-operator) |
865
|
|
|
|
|
|
|
|
866
|
|
|
|
|
|
|
=for bad |
867
|
|
|
|
|
|
|
|
868
|
|
|
|
|
|
|
Cpow does not process bad values. |
869
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
870
|
|
|
|
|
|
|
|
871
|
|
|
|
|
|
|
|
872
|
|
|
|
|
|
|
=cut |
873
|
|
|
|
|
|
|
|
874
|
|
|
|
|
|
|
|
875
|
|
|
|
|
|
|
|
876
|
|
|
|
|
|
|
|
877
|
|
|
|
|
|
|
|
878
|
|
|
|
|
|
|
|
879
|
3
|
|
|
3
|
|
116
|
BEGIN {*Cpow = \&PDLA::Complex::Cpow; |
880
|
|
|
|
|
|
|
} |
881
|
|
|
|
|
|
|
|
882
|
|
|
|
|
|
|
|
883
|
|
|
|
|
|
|
|
884
|
|
|
|
|
|
|
|
885
|
|
|
|
|
|
|
=head2 Csqrt |
886
|
|
|
|
|
|
|
|
887
|
|
|
|
|
|
|
=for sig |
888
|
|
|
|
|
|
|
|
889
|
|
|
|
|
|
|
Signature: (a(m=2); [o]c(m=2)) |
890
|
|
|
|
|
|
|
|
891
|
|
|
|
|
|
|
=for ref |
892
|
|
|
|
|
|
|
|
893
|
|
|
|
|
|
|
Works inplace |
894
|
|
|
|
|
|
|
|
895
|
|
|
|
|
|
|
=for bad |
896
|
|
|
|
|
|
|
|
897
|
|
|
|
|
|
|
Csqrt does not process bad values. |
898
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
899
|
|
|
|
|
|
|
|
900
|
|
|
|
|
|
|
|
901
|
|
|
|
|
|
|
=cut |
902
|
|
|
|
|
|
|
|
903
|
|
|
|
|
|
|
|
904
|
|
|
|
|
|
|
|
905
|
|
|
|
|
|
|
|
906
|
|
|
|
|
|
|
|
907
|
|
|
|
|
|
|
|
908
|
3
|
|
|
3
|
|
57
|
BEGIN {*Csqrt = \&PDLA::Complex::Csqrt; |
909
|
|
|
|
|
|
|
} |
910
|
|
|
|
|
|
|
|
911
|
|
|
|
|
|
|
|
912
|
|
|
|
|
|
|
|
913
|
|
|
|
|
|
|
|
914
|
|
|
|
|
|
|
=head2 Casin |
915
|
|
|
|
|
|
|
|
916
|
|
|
|
|
|
|
=for sig |
917
|
|
|
|
|
|
|
|
918
|
|
|
|
|
|
|
Signature: (a(m=2); [o]c(m=2)) |
919
|
|
|
|
|
|
|
|
920
|
|
|
|
|
|
|
=for ref |
921
|
|
|
|
|
|
|
|
922
|
|
|
|
|
|
|
Works inplace |
923
|
|
|
|
|
|
|
|
924
|
|
|
|
|
|
|
=for bad |
925
|
|
|
|
|
|
|
|
926
|
|
|
|
|
|
|
Casin does not process bad values. |
927
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
928
|
|
|
|
|
|
|
|
929
|
|
|
|
|
|
|
|
930
|
|
|
|
|
|
|
=cut |
931
|
|
|
|
|
|
|
|
932
|
|
|
|
|
|
|
|
933
|
|
|
|
|
|
|
|
934
|
|
|
|
|
|
|
|
935
|
|
|
|
|
|
|
|
936
|
|
|
|
|
|
|
|
937
|
3
|
|
|
3
|
|
68
|
BEGIN {*Casin = \&PDLA::Complex::Casin; |
938
|
|
|
|
|
|
|
} |
939
|
|
|
|
|
|
|
|
940
|
|
|
|
|
|
|
|
941
|
|
|
|
|
|
|
|
942
|
|
|
|
|
|
|
|
943
|
|
|
|
|
|
|
=head2 Cacos |
944
|
|
|
|
|
|
|
|
945
|
|
|
|
|
|
|
=for sig |
946
|
|
|
|
|
|
|
|
947
|
|
|
|
|
|
|
Signature: (a(m=2); [o]c(m=2)) |
948
|
|
|
|
|
|
|
|
949
|
|
|
|
|
|
|
=for ref |
950
|
|
|
|
|
|
|
|
951
|
|
|
|
|
|
|
Works inplace |
952
|
|
|
|
|
|
|
|
953
|
|
|
|
|
|
|
=for bad |
954
|
|
|
|
|
|
|
|
955
|
|
|
|
|
|
|
Cacos does not process bad values. |
956
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
957
|
|
|
|
|
|
|
|
958
|
|
|
|
|
|
|
|
959
|
|
|
|
|
|
|
=cut |
960
|
|
|
|
|
|
|
|
961
|
|
|
|
|
|
|
|
962
|
|
|
|
|
|
|
|
963
|
|
|
|
|
|
|
|
964
|
|
|
|
|
|
|
|
965
|
|
|
|
|
|
|
|
966
|
3
|
|
|
3
|
|
226
|
BEGIN {*Cacos = \&PDLA::Complex::Cacos; |
967
|
|
|
|
|
|
|
} |
968
|
|
|
|
|
|
|
|
969
|
|
|
|
|
|
|
|
970
|
|
|
|
|
|
|
|
971
|
|
|
|
|
|
|
=head2 Catan |
972
|
|
|
|
|
|
|
|
973
|
|
|
|
|
|
|
=for ref |
974
|
|
|
|
|
|
|
|
975
|
|
|
|
|
|
|
Return the complex C. |
976
|
|
|
|
|
|
|
|
977
|
|
|
|
|
|
|
Does not work inplace. |
978
|
|
|
|
|
|
|
|
979
|
|
|
|
|
|
|
=cut |
980
|
|
|
|
|
|
|
|
981
|
|
|
|
|
|
|
sub Catan($) { |
982
|
2
|
|
|
2
|
1
|
378
|
my $z = shift; |
983
|
2
|
|
|
|
|
7
|
Cmul Clog(Cdiv (PDLA::Complex::i+$z, PDLA::Complex::i-$z)), pdl(0, 0.5); |
984
|
|
|
|
|
|
|
} |
985
|
|
|
|
|
|
|
|
986
|
|
|
|
|
|
|
|
987
|
|
|
|
|
|
|
|
988
|
|
|
|
|
|
|
|
989
|
|
|
|
|
|
|
|
990
|
|
|
|
|
|
|
=head2 Csinh |
991
|
|
|
|
|
|
|
|
992
|
|
|
|
|
|
|
=for sig |
993
|
|
|
|
|
|
|
|
994
|
|
|
|
|
|
|
Signature: (a(m=2); [o]c(m=2)) |
995
|
|
|
|
|
|
|
|
996
|
|
|
|
|
|
|
=for ref |
997
|
|
|
|
|
|
|
|
998
|
|
|
|
|
|
|
sinh (a) = (exp (a) - exp (-a)) / 2. Works inplace |
999
|
|
|
|
|
|
|
|
1000
|
|
|
|
|
|
|
=for bad |
1001
|
|
|
|
|
|
|
|
1002
|
|
|
|
|
|
|
Csinh does not process bad values. |
1003
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
1004
|
|
|
|
|
|
|
|
1005
|
|
|
|
|
|
|
|
1006
|
|
|
|
|
|
|
=cut |
1007
|
|
|
|
|
|
|
|
1008
|
|
|
|
|
|
|
|
1009
|
|
|
|
|
|
|
|
1010
|
|
|
|
|
|
|
|
1011
|
|
|
|
|
|
|
|
1012
|
|
|
|
|
|
|
|
1013
|
3
|
|
|
3
|
|
77
|
BEGIN {*Csinh = \&PDLA::Complex::Csinh; |
1014
|
|
|
|
|
|
|
} |
1015
|
|
|
|
|
|
|
|
1016
|
|
|
|
|
|
|
|
1017
|
|
|
|
|
|
|
|
1018
|
|
|
|
|
|
|
|
1019
|
|
|
|
|
|
|
=head2 Ccosh |
1020
|
|
|
|
|
|
|
|
1021
|
|
|
|
|
|
|
=for sig |
1022
|
|
|
|
|
|
|
|
1023
|
|
|
|
|
|
|
Signature: (a(m=2); [o]c(m=2)) |
1024
|
|
|
|
|
|
|
|
1025
|
|
|
|
|
|
|
=for ref |
1026
|
|
|
|
|
|
|
|
1027
|
|
|
|
|
|
|
cosh (a) = (exp (a) + exp (-a)) / 2. Works inplace |
1028
|
|
|
|
|
|
|
|
1029
|
|
|
|
|
|
|
=for bad |
1030
|
|
|
|
|
|
|
|
1031
|
|
|
|
|
|
|
Ccosh does not process bad values. |
1032
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
1033
|
|
|
|
|
|
|
|
1034
|
|
|
|
|
|
|
|
1035
|
|
|
|
|
|
|
=cut |
1036
|
|
|
|
|
|
|
|
1037
|
|
|
|
|
|
|
|
1038
|
|
|
|
|
|
|
|
1039
|
|
|
|
|
|
|
|
1040
|
|
|
|
|
|
|
|
1041
|
|
|
|
|
|
|
|
1042
|
3
|
|
|
3
|
|
76
|
BEGIN {*Ccosh = \&PDLA::Complex::Ccosh; |
1043
|
|
|
|
|
|
|
} |
1044
|
|
|
|
|
|
|
|
1045
|
|
|
|
|
|
|
|
1046
|
|
|
|
|
|
|
|
1047
|
|
|
|
|
|
|
|
1048
|
|
|
|
|
|
|
=head2 Ctanh |
1049
|
|
|
|
|
|
|
|
1050
|
|
|
|
|
|
|
=for sig |
1051
|
|
|
|
|
|
|
|
1052
|
|
|
|
|
|
|
Signature: (a(m=2); [o]c(m=2)) |
1053
|
|
|
|
|
|
|
|
1054
|
|
|
|
|
|
|
=for ref |
1055
|
|
|
|
|
|
|
|
1056
|
|
|
|
|
|
|
Works inplace |
1057
|
|
|
|
|
|
|
|
1058
|
|
|
|
|
|
|
=for bad |
1059
|
|
|
|
|
|
|
|
1060
|
|
|
|
|
|
|
Ctanh does not process bad values. |
1061
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
1062
|
|
|
|
|
|
|
|
1063
|
|
|
|
|
|
|
|
1064
|
|
|
|
|
|
|
=cut |
1065
|
|
|
|
|
|
|
|
1066
|
|
|
|
|
|
|
|
1067
|
|
|
|
|
|
|
|
1068
|
|
|
|
|
|
|
|
1069
|
|
|
|
|
|
|
|
1070
|
|
|
|
|
|
|
|
1071
|
3
|
|
|
3
|
|
64
|
BEGIN {*Ctanh = \&PDLA::Complex::Ctanh; |
1072
|
|
|
|
|
|
|
} |
1073
|
|
|
|
|
|
|
|
1074
|
|
|
|
|
|
|
|
1075
|
|
|
|
|
|
|
|
1076
|
|
|
|
|
|
|
|
1077
|
|
|
|
|
|
|
=head2 Casinh |
1078
|
|
|
|
|
|
|
|
1079
|
|
|
|
|
|
|
=for sig |
1080
|
|
|
|
|
|
|
|
1081
|
|
|
|
|
|
|
Signature: (a(m=2); [o]c(m=2)) |
1082
|
|
|
|
|
|
|
|
1083
|
|
|
|
|
|
|
=for ref |
1084
|
|
|
|
|
|
|
|
1085
|
|
|
|
|
|
|
Works inplace |
1086
|
|
|
|
|
|
|
|
1087
|
|
|
|
|
|
|
=for bad |
1088
|
|
|
|
|
|
|
|
1089
|
|
|
|
|
|
|
Casinh does not process bad values. |
1090
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
1091
|
|
|
|
|
|
|
|
1092
|
|
|
|
|
|
|
|
1093
|
|
|
|
|
|
|
=cut |
1094
|
|
|
|
|
|
|
|
1095
|
|
|
|
|
|
|
|
1096
|
|
|
|
|
|
|
|
1097
|
|
|
|
|
|
|
|
1098
|
|
|
|
|
|
|
|
1099
|
|
|
|
|
|
|
|
1100
|
3
|
|
|
3
|
|
76
|
BEGIN {*Casinh = \&PDLA::Complex::Casinh; |
1101
|
|
|
|
|
|
|
} |
1102
|
|
|
|
|
|
|
|
1103
|
|
|
|
|
|
|
|
1104
|
|
|
|
|
|
|
|
1105
|
|
|
|
|
|
|
|
1106
|
|
|
|
|
|
|
=head2 Cacosh |
1107
|
|
|
|
|
|
|
|
1108
|
|
|
|
|
|
|
=for sig |
1109
|
|
|
|
|
|
|
|
1110
|
|
|
|
|
|
|
Signature: (a(m=2); [o]c(m=2)) |
1111
|
|
|
|
|
|
|
|
1112
|
|
|
|
|
|
|
=for ref |
1113
|
|
|
|
|
|
|
|
1114
|
|
|
|
|
|
|
Works inplace |
1115
|
|
|
|
|
|
|
|
1116
|
|
|
|
|
|
|
=for bad |
1117
|
|
|
|
|
|
|
|
1118
|
|
|
|
|
|
|
Cacosh does not process bad values. |
1119
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
1120
|
|
|
|
|
|
|
|
1121
|
|
|
|
|
|
|
|
1122
|
|
|
|
|
|
|
=cut |
1123
|
|
|
|
|
|
|
|
1124
|
|
|
|
|
|
|
|
1125
|
|
|
|
|
|
|
|
1126
|
|
|
|
|
|
|
|
1127
|
|
|
|
|
|
|
|
1128
|
|
|
|
|
|
|
|
1129
|
3
|
|
|
3
|
|
59
|
BEGIN {*Cacosh = \&PDLA::Complex::Cacosh; |
1130
|
|
|
|
|
|
|
} |
1131
|
|
|
|
|
|
|
|
1132
|
|
|
|
|
|
|
|
1133
|
|
|
|
|
|
|
|
1134
|
|
|
|
|
|
|
|
1135
|
|
|
|
|
|
|
=head2 Catanh |
1136
|
|
|
|
|
|
|
|
1137
|
|
|
|
|
|
|
=for sig |
1138
|
|
|
|
|
|
|
|
1139
|
|
|
|
|
|
|
Signature: (a(m=2); [o]c(m=2)) |
1140
|
|
|
|
|
|
|
|
1141
|
|
|
|
|
|
|
=for ref |
1142
|
|
|
|
|
|
|
|
1143
|
|
|
|
|
|
|
Works inplace |
1144
|
|
|
|
|
|
|
|
1145
|
|
|
|
|
|
|
=for bad |
1146
|
|
|
|
|
|
|
|
1147
|
|
|
|
|
|
|
Catanh does not process bad values. |
1148
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
1149
|
|
|
|
|
|
|
|
1150
|
|
|
|
|
|
|
|
1151
|
|
|
|
|
|
|
=cut |
1152
|
|
|
|
|
|
|
|
1153
|
|
|
|
|
|
|
|
1154
|
|
|
|
|
|
|
|
1155
|
|
|
|
|
|
|
|
1156
|
|
|
|
|
|
|
|
1157
|
|
|
|
|
|
|
|
1158
|
3
|
|
|
3
|
|
67
|
BEGIN {*Catanh = \&PDLA::Complex::Catanh; |
1159
|
|
|
|
|
|
|
} |
1160
|
|
|
|
|
|
|
|
1161
|
|
|
|
|
|
|
|
1162
|
|
|
|
|
|
|
|
1163
|
|
|
|
|
|
|
|
1164
|
|
|
|
|
|
|
=head2 Cproj |
1165
|
|
|
|
|
|
|
|
1166
|
|
|
|
|
|
|
=for sig |
1167
|
|
|
|
|
|
|
|
1168
|
|
|
|
|
|
|
Signature: (a(m=2); [o]c(m=2)) |
1169
|
|
|
|
|
|
|
|
1170
|
|
|
|
|
|
|
=for ref |
1171
|
|
|
|
|
|
|
|
1172
|
|
|
|
|
|
|
compute the projection of a complex number to the riemann sphere. Works inplace |
1173
|
|
|
|
|
|
|
|
1174
|
|
|
|
|
|
|
=for bad |
1175
|
|
|
|
|
|
|
|
1176
|
|
|
|
|
|
|
Cproj does not process bad values. |
1177
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
1178
|
|
|
|
|
|
|
|
1179
|
|
|
|
|
|
|
|
1180
|
|
|
|
|
|
|
=cut |
1181
|
|
|
|
|
|
|
|
1182
|
|
|
|
|
|
|
|
1183
|
|
|
|
|
|
|
|
1184
|
|
|
|
|
|
|
|
1185
|
|
|
|
|
|
|
|
1186
|
|
|
|
|
|
|
|
1187
|
3
|
|
|
3
|
|
204
|
BEGIN {*Cproj = \&PDLA::Complex::Cproj; |
1188
|
|
|
|
|
|
|
} |
1189
|
|
|
|
|
|
|
|
1190
|
|
|
|
|
|
|
|
1191
|
|
|
|
|
|
|
|
1192
|
|
|
|
|
|
|
|
1193
|
|
|
|
|
|
|
=head2 Croots |
1194
|
|
|
|
|
|
|
|
1195
|
|
|
|
|
|
|
=for sig |
1196
|
|
|
|
|
|
|
|
1197
|
|
|
|
|
|
|
Signature: (a(m=2); [o]c(m=2,n); int n => n) |
1198
|
|
|
|
|
|
|
|
1199
|
|
|
|
|
|
|
=for ref |
1200
|
|
|
|
|
|
|
|
1201
|
|
|
|
|
|
|
Compute the C roots of C. C must be a positive integer. The result will always be a complex type! |
1202
|
|
|
|
|
|
|
|
1203
|
|
|
|
|
|
|
=for bad |
1204
|
|
|
|
|
|
|
|
1205
|
|
|
|
|
|
|
Croots does not process bad values. |
1206
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
1207
|
|
|
|
|
|
|
|
1208
|
|
|
|
|
|
|
|
1209
|
|
|
|
|
|
|
=cut |
1210
|
|
|
|
|
|
|
|
1211
|
|
|
|
|
|
|
|
1212
|
|
|
|
|
|
|
|
1213
|
|
|
|
|
|
|
|
1214
|
|
|
|
|
|
|
sub PDLA::Complex::Croots($$) { |
1215
|
3
|
|
|
3
|
1
|
721
|
my ($pdl, $n) = @_; |
1216
|
3
|
|
|
|
|
11
|
my $r = PDLA->null; |
1217
|
3
|
|
|
|
|
97
|
&PDLA::Complex::_Croots_int($pdl, $r, $n); |
1218
|
3
|
|
|
|
|
18
|
bless $r; |
1219
|
|
|
|
|
|
|
} |
1220
|
|
|
|
|
|
|
|
1221
|
3
|
|
|
3
|
|
379
|
BEGIN {*Croots = \&PDLA::Complex::Croots; |
1222
|
|
|
|
|
|
|
} |
1223
|
|
|
|
|
|
|
|
1224
|
|
|
|
|
|
|
|
1225
|
|
|
|
|
|
|
|
1226
|
|
|
|
|
|
|
=head2 re, im |
1227
|
|
|
|
|
|
|
|
1228
|
|
|
|
|
|
|
Return the real or imaginary part of the complex number(s) given. |
1229
|
|
|
|
|
|
|
|
1230
|
|
|
|
|
|
|
These are slicing operators, so data flow works. The real and |
1231
|
|
|
|
|
|
|
imaginary parts are returned as piddles (ref eq PDLA). |
1232
|
|
|
|
|
|
|
|
1233
|
|
|
|
|
|
|
=cut |
1234
|
|
|
|
|
|
|
|
1235
|
21
|
|
|
21
|
1
|
64
|
sub re($) { bless $_[0]->slice("(0)"), 'PDLA'; } |
1236
|
19
|
|
|
19
|
1
|
384
|
sub im($) { bless $_[0]->slice("(1)"), 'PDLA'; } |
1237
|
|
|
|
|
|
|
|
1238
|
|
|
|
|
|
|
*PDLA::Complex::re = \&re; |
1239
|
|
|
|
|
|
|
*PDLA::Complex::im = \&im; |
1240
|
|
|
|
|
|
|
|
1241
|
|
|
|
|
|
|
|
1242
|
|
|
|
|
|
|
|
1243
|
|
|
|
|
|
|
|
1244
|
|
|
|
|
|
|
|
1245
|
|
|
|
|
|
|
=head2 rCpolynomial |
1246
|
|
|
|
|
|
|
|
1247
|
|
|
|
|
|
|
=for sig |
1248
|
|
|
|
|
|
|
|
1249
|
|
|
|
|
|
|
Signature: (coeffs(n); x(c=2,m); [o]out(c=2,m)) |
1250
|
|
|
|
|
|
|
|
1251
|
|
|
|
|
|
|
=for ref |
1252
|
|
|
|
|
|
|
|
1253
|
|
|
|
|
|
|
evaluate the polynomial with (real) coefficients C at the (complex) position(s) C. C is the constant term. |
1254
|
|
|
|
|
|
|
|
1255
|
|
|
|
|
|
|
=for bad |
1256
|
|
|
|
|
|
|
|
1257
|
|
|
|
|
|
|
rCpolynomial does not process bad values. |
1258
|
|
|
|
|
|
|
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. |
1259
|
|
|
|
|
|
|
|
1260
|
|
|
|
|
|
|
|
1261
|
|
|
|
|
|
|
=cut |
1262
|
|
|
|
|
|
|
|
1263
|
|
|
|
|
|
|
|
1264
|
|
|
|
|
|
|
|
1265
|
|
|
|
|
|
|
|
1266
|
|
|
|
|
|
|
|
1267
|
|
|
|
|
|
|
sub rCpolynomial { |
1268
|
2
|
|
|
2
|
1
|
5
|
my $coeffs = shift; |
1269
|
2
|
|
|
|
|
2
|
my $x = shift; |
1270
|
2
|
|
|
|
|
7
|
my $out = $x->copy; |
1271
|
2
|
|
|
|
|
30
|
_rCpolynomial_int($coeffs,$x,$out); |
1272
|
2
|
|
|
|
|
7
|
return PDLA::complex($out); |
1273
|
|
|
|
|
|
|
} |
1274
|
|
|
|
|
|
|
|
1275
|
|
|
|
|
|
|
|
1276
|
3
|
|
|
3
|
|
2223
|
BEGIN {*rCpolynomial = \&PDLA::Complex::rCpolynomial; |
1277
|
|
|
|
|
|
|
} |
1278
|
|
|
|
|
|
|
|
1279
|
|
|
|
|
|
|
|
1280
|
|
|
|
|
|
|
; |
1281
|
|
|
|
|
|
|
|
1282
|
|
|
|
|
|
|
|
1283
|
|
|
|
|
|
|
# overload must be here, so that all the functions can be seen |
1284
|
|
|
|
|
|
|
|
1285
|
|
|
|
|
|
|
# undocumented compatibility functions (thanks to Luis Mochan!) |
1286
|
1
|
|
|
1
|
0
|
3
|
sub Catan2($$) { Clog( $_[1] + i*$_[0])/i } |
1287
|
0
|
|
|
0
|
1
|
0
|
sub atan2($$) { Clog( $_[1] + i*$_[0])/i } |
1288
|
|
|
|
|
|
|
|
1289
|
|
|
|
|
|
|
|
1290
|
|
|
|
|
|
|
=begin comment |
1291
|
|
|
|
|
|
|
|
1292
|
|
|
|
|
|
|
In _gen_biop, the '+' or '-' between the operator (e.g., '*') and the |
1293
|
|
|
|
|
|
|
function that it overloads (e.g., 'Cmul') flags whether the operation |
1294
|
|
|
|
|
|
|
is ('+') or is not ('-') commutative. See the discussion of argument |
1295
|
|
|
|
|
|
|
swapping in the section "Calling Conventions and Magic Autogeneration" |
1296
|
|
|
|
|
|
|
in "perldoc overload". |
1297
|
|
|
|
|
|
|
|
1298
|
|
|
|
|
|
|
This is a great example of taking almost as many lines to write cute |
1299
|
|
|
|
|
|
|
generating code as it would take to just clearly and explicitly write |
1300
|
|
|
|
|
|
|
down the overload. |
1301
|
|
|
|
|
|
|
|
1302
|
|
|
|
|
|
|
=end comment |
1303
|
|
|
|
|
|
|
|
1304
|
|
|
|
|
|
|
=cut |
1305
|
|
|
|
|
|
|
|
1306
|
|
|
|
|
|
|
sub _gen_biop { |
1307
|
21
|
|
|
21
|
|
38
|
local $_ = shift; |
1308
|
21
|
|
|
|
|
23
|
my $sub; |
1309
|
21
|
100
|
|
|
|
101
|
if (/(\S+)\+(\w+)/) { #commutes |
|
|
50
|
|
|
|
|
|
1310
|
6
|
100
|
|
35
|
|
516
|
$sub = eval 'sub { '.$2.' $_[0], ref $_[1] eq __PACKAGE__ ? $_[1] : r2C $_[1] }'; |
|
35
|
100
|
|
|
|
166
|
|
|
28
|
|
|
|
|
161
|
|
1311
|
|
|
|
|
|
|
} elsif (/(\S+)\-(\w+)/) { #does not commute |
1312
|
15
|
100
|
|
16
|
|
1451
|
$sub = eval 'sub { my $y = ref $_[1] eq __PACKAGE__ ? $_[1] : r2C $_[1]; |
|
16
|
100
|
|
|
|
238
|
|
|
16
|
100
|
|
|
|
106
|
|
|
5
|
50
|
|
|
|
187
|
|
|
5
|
50
|
|
|
|
34
|
|
|
1
|
50
|
|
|
|
9
|
|
|
1
|
50
|
|
|
|
7
|
|
|
10
|
50
|
|
|
|
38
|
|
|
10
|
50
|
|
|
|
55
|
|
|
7
|
50
|
|
|
|
24
|
|
|
7
|
|
|
|
|
42
|
|
1313
|
|
|
|
|
|
|
$_[2] ? '.$2.' $y, $_[0] : '.$2.' $_[0], $y }'; #need to swap? |
1314
|
|
|
|
|
|
|
} else { |
1315
|
0
|
|
|
|
|
0
|
die; |
1316
|
|
|
|
|
|
|
} |
1317
|
21
|
100
|
100
|
|
|
132
|
if($1 eq "atan2" || $1 eq "<=>") { return ($1, $sub) } |
|
6
|
|
|
|
|
31
|
|
1318
|
15
|
|
|
|
|
71
|
($1, $sub, "$1=", $sub); |
1319
|
|
|
|
|
|
|
} |
1320
|
|
|
|
|
|
|
|
1321
|
|
|
|
|
|
|
sub _gen_unop { |
1322
|
18
|
|
|
18
|
|
83
|
my ($op, $func) = ($_[0] =~ /(.+)@(\w+)/); |
1323
|
18
|
50
|
|
|
|
117
|
*$op = \&$func if $op =~ /\w+/; # create an alias |
1324
|
18
|
|
|
0
|
|
934
|
($op, eval 'sub { '.$func.' $_[0] }'); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
4
|
|
|
|
|
16
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
1325
|
|
|
|
|
|
|
} |
1326
|
|
|
|
|
|
|
|
1327
|
|
|
|
|
|
|
#sub _gen_cpop { |
1328
|
|
|
|
|
|
|
# ($_[0], eval 'sub { my $y = ref $_[1] eq __PACKAGE__ ? $_[1] : r2C $_[1]; |
1329
|
|
|
|
|
|
|
# ($_[2] ? $y <=> $_[0] : $_[0] <=> $y) '.$_[0].' 0 }'); |
1330
|
|
|
|
|
|
|
#} |
1331
|
|
|
|
|
|
|
|
1332
|
|
|
|
|
|
|
sub initialize { |
1333
|
|
|
|
|
|
|
# Bless a null PDLA into the supplied 1st arg package |
1334
|
|
|
|
|
|
|
# If 1st arg is a ref, get the package from it |
1335
|
521
|
100
|
|
521
|
0
|
6683
|
bless PDLA->null, ref($_[0]) ? ref($_[0]) : $_[0]; |
1336
|
|
|
|
|
|
|
} |
1337
|
|
|
|
|
|
|
|
1338
|
|
|
|
|
|
|
use overload |
1339
|
|
|
|
|
|
|
(map _gen_biop($_), qw(++Cadd --Csub *+Cmul /-Cdiv **-Cpow atan2-Catan2 <=>-Ccmp)), |
1340
|
|
|
|
|
|
|
(map _gen_unop($_), qw(sin@Csin cos@Ccos exp@Cexp abs@Cabs log@Clog sqrt@Csqrt)), |
1341
|
|
|
|
|
|
|
# (map _gen_cpop($_), qw(< <= == != >= >)), #segfaults with infinite recursion of the operator. |
1342
|
|
|
|
|
|
|
#final ternary used to make result a scalar, not a PDLA:::Complex (thx CED!) |
1343
|
2
|
50
|
|
2
|
|
22
|
"<" => sub { my $y = ref $_[1] eq __PACKAGE__ ? $_[1] : r2C $_[1]; |
1344
|
2
|
50
|
|
|
|
44
|
PDLA::lt( ($_[2] ? $y <=> $_[0] : $_[0] <=> $y), 0, 0) ? 1 : 0;}, |
|
|
50
|
|
|
|
|
|
1345
|
1
|
50
|
|
1
|
|
7
|
"<=" => sub { my $y = ref $_[1] eq __PACKAGE__ ? $_[1] : r2C $_[1]; |
1346
|
1
|
50
|
|
|
|
24
|
PDLA::le( ($_[2] ? $y <=> $_[0] : $_[0] <=> $y), 0, 0) ? 1 : 0;}, |
|
|
50
|
|
|
|
|
|
1347
|
1
|
50
|
|
1
|
|
7
|
"==" => sub { my $y = ref $_[1] eq __PACKAGE__ ? $_[1] : r2C $_[1]; |
1348
|
1
|
50
|
|
|
|
24
|
PDLA::eq( ($_[2] ? $y <=> $_[0] : $_[0] <=> $y), 0, 0) ? 1 : 0;}, |
|
|
50
|
|
|
|
|
|
1349
|
1
|
50
|
|
1
|
|
6
|
"!=" => sub { my $y = ref $_[1] eq __PACKAGE__ ? $_[1] : r2C $_[1]; |
1350
|
1
|
50
|
|
|
|
23
|
PDLA::ne( ($_[2] ? $y <=> $_[0] : $_[0] <=> $y), 0, 0) ? 1 : 0;}, |
|
|
50
|
|
|
|
|
|
1351
|
1
|
50
|
|
1
|
|
6
|
">=" => sub { my $y = ref $_[1] eq __PACKAGE__ ? $_[1] : r2C $_[1]; |
1352
|
1
|
50
|
|
|
|
25
|
PDLA::ge( ($_[2] ? $y <=> $_[0] : $_[0] <=> $y), 0, 0) ? 1 : 0;}, |
|
|
50
|
|
|
|
|
|
1353
|
1
|
50
|
|
1
|
|
7
|
">" => sub { my $y = ref $_[1] eq __PACKAGE__ ? $_[1] : r2C $_[1]; |
1354
|
1
|
50
|
|
|
|
24
|
PDLA::gt( ($_[2] ? $y <=> $_[0] : $_[0] <=> $y), 0, 0) ? 1 : 0;}, |
|
|
50
|
|
|
|
|
|
1355
|
1
|
|
|
1
|
|
4
|
'++' => sub { $_[0] += 1 }, |
1356
|
0
|
|
|
0
|
|
0
|
'--' => sub { $_[0] -= 1 }, |
1357
|
3
|
|
|
|
|
15
|
'""' => \&PDLA::Complex::string |
1358
|
3
|
|
|
3
|
|
21
|
; |
|
3
|
|
|
|
|
6
|
|
1359
|
|
|
|
|
|
|
|
1360
|
|
|
|
|
|
|
# overwrite PDLA's overloading to honour subclass methods in + - * / |
1361
|
|
|
|
|
|
|
{ package PDLA; |
1362
|
|
|
|
|
|
|
my $warningFlag; |
1363
|
|
|
|
|
|
|
# This strange usage of BEGINs is to ensure the |
1364
|
|
|
|
|
|
|
# warning messages get disabled and enabled in the |
1365
|
|
|
|
|
|
|
# proper order. Without the BEGIN's the 'use overload' |
1366
|
|
|
|
|
|
|
# would be called first. |
1367
|
3
|
|
|
3
|
|
944
|
BEGIN {$warningFlag = $^W; # Temporarily disable warnings caused by |
1368
|
3
|
|
|
|
|
1028
|
$^W = 0; # redefining PDLA's subs |
1369
|
|
|
|
|
|
|
} |
1370
|
|
|
|
|
|
|
|
1371
|
|
|
|
|
|
|
|
1372
|
|
|
|
|
|
|
sub cp(;@) { |
1373
|
8
|
|
|
8
|
0
|
15
|
my $foo; |
1374
|
8
|
100
|
100
|
|
|
45
|
if (ref $_[1] |
|
|
|
66
|
|
|
|
|
1375
|
|
|
|
|
|
|
&& (ref $_[1] ne 'PDLA') |
1376
|
|
|
|
|
|
|
&& defined ($foo = overload::Method($_[1],'+'))) |
1377
|
2
|
|
|
|
|
154
|
{ &$foo($_[1], $_[0], !$_[2])} |
1378
|
6
|
|
|
|
|
113
|
else { PDLA::plus (@_)} |
1379
|
|
|
|
|
|
|
} |
1380
|
|
|
|
|
|
|
|
1381
|
|
|
|
|
|
|
sub cm(;@) { |
1382
|
8
|
|
|
8
|
0
|
13
|
my $foo; |
1383
|
8
|
50
|
66
|
|
|
37
|
if (ref $_[1] |
|
|
|
33
|
|
|
|
|
1384
|
|
|
|
|
|
|
&& (ref $_[1] ne 'PDLA') |
1385
|
|
|
|
|
|
|
&& defined ($foo = overload::Method($_[1],'*'))) |
1386
|
0
|
|
|
|
|
0
|
{ &$foo($_[1], $_[0], !$_[2])} |
1387
|
8
|
|
|
|
|
266
|
else { PDLA::mult (@_)} |
1388
|
|
|
|
|
|
|
} |
1389
|
|
|
|
|
|
|
|
1390
|
|
|
|
|
|
|
sub cmi(;@) { |
1391
|
58
|
|
|
58
|
0
|
262
|
my $foo; |
1392
|
58
|
100
|
100
|
|
|
240
|
if (ref $_[1] |
|
|
|
66
|
|
|
|
|
1393
|
|
|
|
|
|
|
&& (ref $_[1] ne 'PDLA') |
1394
|
|
|
|
|
|
|
&& defined ($foo = overload::Method($_[1],'-'))) |
1395
|
1
|
|
|
|
|
86
|
{ &$foo($_[1], $_[0], !$_[2])} |
1396
|
57
|
|
|
|
|
914
|
else { PDLA::minus (@_)} |
1397
|
|
|
|
|
|
|
} |
1398
|
|
|
|
|
|
|
|
1399
|
|
|
|
|
|
|
sub cd(;@) { |
1400
|
0
|
|
|
0
|
0
|
0
|
my $foo; |
1401
|
0
|
0
|
0
|
|
|
0
|
if (ref $_[1] |
|
|
|
0
|
|
|
|
|
1402
|
|
|
|
|
|
|
&& (ref $_[1] ne 'PDLA') |
1403
|
|
|
|
|
|
|
&& defined ($foo = overload::Method($_[1],'/'))) |
1404
|
0
|
|
|
|
|
0
|
{ &$foo($_[1], $_[0], !$_[2])} |
1405
|
0
|
|
|
|
|
0
|
else { PDLA::divide (@_)} |
1406
|
|
|
|
|
|
|
} |
1407
|
|
|
|
|
|
|
|
1408
|
|
|
|
|
|
|
|
1409
|
|
|
|
|
|
|
# Used in overriding standard PDLA +, -, *, / ops in the complex subclass. |
1410
|
|
|
|
|
|
|
use overload ( |
1411
|
3
|
|
|
|
|
12
|
'+' => \&cp, |
1412
|
|
|
|
|
|
|
'*' => \&cm, |
1413
|
|
|
|
|
|
|
'-' => \&cmi, |
1414
|
|
|
|
|
|
|
'/' => \&cd, |
1415
|
3
|
|
|
3
|
|
19
|
); |
|
3
|
|
|
|
|
5
|
|
1416
|
|
|
|
|
|
|
|
1417
|
|
|
|
|
|
|
|
1418
|
|
|
|
|
|
|
|
1419
|
3
|
|
|
3
|
|
4469
|
BEGIN{ $^W = $warningFlag;} # Put Back Warnings |
1420
|
|
|
|
|
|
|
}; |
1421
|
|
|
|
|
|
|
|
1422
|
|
|
|
|
|
|
|
1423
|
|
|
|
|
|
|
{ |
1424
|
|
|
|
|
|
|
|
1425
|
|
|
|
|
|
|
our $floatformat = "%4.4g"; # Default print format for long numbers |
1426
|
|
|
|
|
|
|
our $doubleformat = "%6.6g"; |
1427
|
|
|
|
|
|
|
|
1428
|
|
|
|
|
|
|
$PDLA::Complex::_STRINGIZING = 0; |
1429
|
|
|
|
|
|
|
|
1430
|
|
|
|
|
|
|
sub PDLA::Complex::string { |
1431
|
7
|
|
|
7
|
0
|
3974
|
my($self,$format1,$format2)=@_; |
1432
|
7
|
|
|
|
|
19
|
my @dims = $self->dims; |
1433
|
7
|
50
|
|
|
|
17
|
return PDLA::string($self) if ($dims[0] != 2); |
1434
|
|
|
|
|
|
|
|
1435
|
7
|
50
|
|
|
|
13
|
if($PDLA::Complex::_STRINGIZING) { |
1436
|
0
|
|
|
|
|
0
|
return "ALREADY_STRINGIZING_NO_LOOPS"; |
1437
|
|
|
|
|
|
|
} |
1438
|
7
|
|
|
|
|
12
|
local $PDLA::Complex::_STRINGIZING = 1; |
1439
|
7
|
|
|
|
|
12
|
my $ndims = $self->getndims; |
1440
|
7
|
50
|
|
|
|
20
|
if($self->nelem > $PDLA::toolongtoprint) { |
1441
|
0
|
|
|
|
|
0
|
return "TOO LONG TO PRINT"; |
1442
|
|
|
|
|
|
|
} |
1443
|
7
|
50
|
|
|
|
14
|
if ($ndims==0){ |
1444
|
0
|
|
|
|
|
0
|
PDLA::Core::string($self,$format1); |
1445
|
|
|
|
|
|
|
} |
1446
|
7
|
50
|
|
|
|
21
|
return "Null" if $self->isnull; |
1447
|
7
|
50
|
|
|
|
20
|
return "Empty" if $self->isempty; # Empty piddle |
1448
|
7
|
50
|
|
|
|
16
|
local $sep = $PDLA::use_commas ? ", " : " "; |
1449
|
7
|
50
|
|
|
|
12
|
local $sep2 = $PDLA::use_commas ? ", " : ""; |
1450
|
7
|
100
|
|
|
|
14
|
if ($ndims < 3) { |
1451
|
6
|
|
|
|
|
14
|
return str1D($self,$format1,$format2); |
1452
|
|
|
|
|
|
|
} |
1453
|
|
|
|
|
|
|
else{ |
1454
|
1
|
|
|
|
|
4
|
return strND($self,$format1,$format2,0); |
1455
|
|
|
|
|
|
|
} |
1456
|
|
|
|
|
|
|
} |
1457
|
|
|
|
|
|
|
|
1458
|
|
|
|
|
|
|
|
1459
|
|
|
|
|
|
|
sub sum { |
1460
|
5
|
|
|
5
|
0
|
14
|
my($x) = @_; |
1461
|
5
|
50
|
|
|
|
12
|
return $x if $x->dims==1; |
1462
|
5
|
|
|
|
|
26
|
my $tmp = $x->mv(0,-1)->clump(-2)->mv(1,0)->sumover; |
1463
|
5
|
|
|
|
|
62
|
return $tmp; |
1464
|
|
|
|
|
|
|
} |
1465
|
|
|
|
|
|
|
|
1466
|
|
|
|
|
|
|
sub sumover{ |
1467
|
14
|
|
|
14
|
0
|
365
|
my $m = shift; |
1468
|
14
|
|
|
|
|
60
|
PDLA::Ufunc::sumover($m->xchg(0,1)); |
1469
|
|
|
|
|
|
|
} |
1470
|
|
|
|
|
|
|
|
1471
|
|
|
|
|
|
|
*PDLA::Complex::Csumover=\&sumover; # define through alias |
1472
|
|
|
|
|
|
|
|
1473
|
|
|
|
|
|
|
*PDLA::Complex::prodover=\&Cprodover; # define through alias |
1474
|
|
|
|
|
|
|
|
1475
|
|
|
|
|
|
|
sub prod { |
1476
|
4
|
|
|
4
|
0
|
13
|
my($x) = @_; |
1477
|
4
|
50
|
|
|
|
12
|
return $x if $x->dims==1; |
1478
|
4
|
|
|
|
|
26
|
my $tmp = $x->mv(0,-1)->clump(-2)->mv(1,0)->prodover; |
1479
|
4
|
|
|
|
|
45
|
return $tmp; |
1480
|
|
|
|
|
|
|
} |
1481
|
|
|
|
|
|
|
|
1482
|
|
|
|
|
|
|
|
1483
|
|
|
|
|
|
|
|
1484
|
|
|
|
|
|
|
sub strND { |
1485
|
1
|
|
|
1
|
0
|
4
|
my($self,$format1,$format2,$level)=@_; |
1486
|
1
|
|
|
|
|
3
|
my @dims = $self->dims; |
1487
|
|
|
|
|
|
|
|
1488
|
1
|
50
|
|
|
|
16
|
if ($#dims==2) { |
1489
|
1
|
|
|
|
|
7
|
return str2D($self,$format1,$format2,$level); |
1490
|
|
|
|
|
|
|
} |
1491
|
|
|
|
|
|
|
else { |
1492
|
0
|
|
|
|
|
0
|
my $secbas = join '',map {":,"} @dims[0..$#dims-1]; |
|
0
|
|
|
|
|
0
|
|
1493
|
0
|
|
|
|
|
0
|
my $ret="\n"." "x$level ."["; my $j; |
|
0
|
|
|
|
|
0
|
|
1494
|
0
|
|
|
|
|
0
|
for ($j=0; $j<$dims[$#dims]; $j++) { |
1495
|
0
|
|
|
|
|
0
|
my $sec = $secbas . "($j)"; |
1496
|
|
|
|
|
|
|
|
1497
|
0
|
|
|
|
|
0
|
$ret .= strND($self->slice($sec),$format1,$format2, $level+1); |
1498
|
0
|
|
|
|
|
0
|
chop $ret; $ret .= $sep2; |
|
0
|
|
|
|
|
0
|
|
1499
|
|
|
|
|
|
|
} |
1500
|
0
|
0
|
|
|
|
0
|
chop $ret if $PDLA::use_commas; |
1501
|
0
|
|
|
|
|
0
|
$ret .= "\n" ." "x$level ."]\n"; |
1502
|
0
|
|
|
|
|
0
|
return $ret; |
1503
|
|
|
|
|
|
|
} |
1504
|
|
|
|
|
|
|
} |
1505
|
|
|
|
|
|
|
|
1506
|
|
|
|
|
|
|
|
1507
|
|
|
|
|
|
|
# String 1D array in nice format |
1508
|
|
|
|
|
|
|
# |
1509
|
|
|
|
|
|
|
sub str1D { |
1510
|
6
|
|
|
6
|
0
|
11
|
my($self,$format1,$format2)=@_; |
1511
|
6
|
50
|
|
|
|
17
|
barf "Not 1D" if $self->getndims() > 2; |
1512
|
6
|
|
|
|
|
25
|
my $x = PDLA::Core::listref_c($self); |
1513
|
6
|
|
|
|
|
11
|
my ($ret,$dformat,$t, $i); |
1514
|
|
|
|
|
|
|
|
1515
|
6
|
|
|
|
|
10
|
my $dtype = $self->get_datatype(); |
1516
|
6
|
50
|
|
|
|
13
|
$dformat = $PDLA::Complex::floatformat if $dtype == $PDLA_F; |
1517
|
6
|
50
|
|
|
|
13
|
$dformat = $PDLA::Complex::doubleformat if $dtype == $PDLA_D; |
1518
|
|
|
|
|
|
|
|
1519
|
6
|
100
|
|
|
|
15
|
$ret = "[" if $self->getndims() > 1; |
1520
|
6
|
|
|
|
|
13
|
my $badflag = $self->badflag(); |
1521
|
6
|
|
|
|
|
15
|
for($i=0; $i<=$#$x; $i++){ |
1522
|
20
|
|
|
|
|
28
|
$t = $$x[$i]; |
1523
|
20
|
50
|
33
|
|
|
41
|
if ( $badflag and $t eq "BAD" ) { |
|
|
50
|
|
|
|
|
|
1524
|
|
|
|
|
|
|
# do nothing |
1525
|
|
|
|
|
|
|
} elsif ($format1) { |
1526
|
0
|
|
|
|
|
0
|
$t = sprintf $format1,$t; |
1527
|
|
|
|
|
|
|
} else{ # Default |
1528
|
20
|
50
|
33
|
|
|
67
|
if ($dformat && length($t)>7) { # Try smaller |
1529
|
0
|
|
|
|
|
0
|
$t = sprintf $dformat,$t; |
1530
|
|
|
|
|
|
|
} |
1531
|
|
|
|
|
|
|
} |
1532
|
20
|
100
|
|
|
|
143
|
$ret .= $i % 2 ? |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
1533
|
|
|
|
|
|
|
$i<$#$x ? $t."i$sep" : $t."i" |
1534
|
|
|
|
|
|
|
: substr($$x[$i+1],0,1) eq "-" ? "$t " : $t." +"; |
1535
|
|
|
|
|
|
|
} |
1536
|
6
|
100
|
|
|
|
23
|
$ret.="]" if $self->getndims() > 1; |
1537
|
6
|
|
|
|
|
39
|
return $ret; |
1538
|
|
|
|
|
|
|
} |
1539
|
|
|
|
|
|
|
|
1540
|
|
|
|
|
|
|
|
1541
|
|
|
|
|
|
|
sub str2D { |
1542
|
1
|
|
|
1
|
0
|
3
|
my($self,$format1,$format2,$level)=@_; |
1543
|
1
|
|
|
|
|
5
|
my @dims = $self->dims(); |
1544
|
1
|
50
|
|
|
|
4
|
barf "Not 2D" if scalar(@dims)!=3; |
1545
|
1
|
|
|
|
|
11
|
my $x = PDLA::Core::listref_c($self); |
1546
|
1
|
|
|
|
|
3
|
my ($i, $f, $t, $len1, $len2, $ret); |
1547
|
|
|
|
|
|
|
|
1548
|
1
|
|
|
|
|
5
|
my $dtype = $self->get_datatype(); |
1549
|
1
|
|
|
|
|
4
|
my $badflag = $self->badflag(); |
1550
|
|
|
|
|
|
|
|
1551
|
1
|
|
|
|
|
3
|
my $findmax = 0; |
1552
|
|
|
|
|
|
|
|
1553
|
1
|
0
|
33
|
|
|
6
|
if (!defined $format1 || !defined $format2 || |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
1554
|
|
|
|
|
|
|
$format1 eq '' || $format2 eq '') { |
1555
|
1
|
|
|
|
|
3
|
$len1= $len2 = 0; |
1556
|
|
|
|
|
|
|
|
1557
|
1
|
50
|
|
|
|
4
|
if ( $badflag ) { |
1558
|
0
|
|
|
|
|
0
|
for ($i=0; $i<=$#$x; $i++) { |
1559
|
0
|
0
|
|
|
|
0
|
if ( $$x[$i] eq "BAD" ) { |
1560
|
0
|
|
|
|
|
0
|
$f = 3; |
1561
|
|
|
|
|
|
|
} |
1562
|
|
|
|
|
|
|
else { |
1563
|
0
|
|
|
|
|
0
|
$f = length($$x[$i]); |
1564
|
|
|
|
|
|
|
} |
1565
|
0
|
0
|
|
|
|
0
|
if ($i % 2) { |
1566
|
0
|
0
|
|
|
|
0
|
$len2 = $f if $f > $len2; |
1567
|
|
|
|
|
|
|
} |
1568
|
|
|
|
|
|
|
else { |
1569
|
0
|
0
|
|
|
|
0
|
$len1 = $f if $f > $len1; |
1570
|
|
|
|
|
|
|
} |
1571
|
|
|
|
|
|
|
} |
1572
|
|
|
|
|
|
|
} else { |
1573
|
1
|
|
|
|
|
12
|
for ($i=0; $i<=$#$x; $i++) { |
1574
|
2
|
|
|
|
|
15
|
$f = length($$x[$i]); |
1575
|
2
|
100
|
|
|
|
6
|
if ($i % 2){ |
1576
|
1
|
50
|
|
|
|
4
|
$len2 = $f if $f > $len2; |
1577
|
|
|
|
|
|
|
} |
1578
|
|
|
|
|
|
|
else{ |
1579
|
1
|
50
|
|
|
|
5
|
$len1 = $f if $f > $len1; |
1580
|
|
|
|
|
|
|
} |
1581
|
|
|
|
|
|
|
} |
1582
|
|
|
|
|
|
|
} |
1583
|
|
|
|
|
|
|
|
1584
|
1
|
|
|
|
|
4
|
$format1 = '%'.$len1.'s'; |
1585
|
1
|
|
|
|
|
3
|
$format2 = '%'.$len2.'s'; |
1586
|
|
|
|
|
|
|
|
1587
|
1
|
50
|
|
|
|
10
|
if ($len1 > 5){ |
1588
|
1
|
50
|
|
|
|
7
|
if ($dtype == $PDLA_F) { |
|
|
50
|
|
|
|
|
|
1589
|
0
|
|
|
|
|
0
|
$format1 = $PDLA::Complex::floatformat; |
1590
|
0
|
|
|
|
|
0
|
$findmax = 1; |
1591
|
|
|
|
|
|
|
} elsif ($dtype == $PDLA_D) { |
1592
|
1
|
|
|
|
|
3
|
$format1 = $PDLA::Complex::doubleformat; |
1593
|
1
|
|
|
|
|
2
|
$findmax = 1; |
1594
|
|
|
|
|
|
|
} else { |
1595
|
0
|
|
|
|
|
0
|
$findmax = 0; |
1596
|
|
|
|
|
|
|
} |
1597
|
|
|
|
|
|
|
} |
1598
|
1
|
50
|
|
|
|
3
|
if($len2 > 5){ |
1599
|
1
|
50
|
|
|
|
5
|
if ($dtype == $PDLA_F) { |
|
|
50
|
|
|
|
|
|
1600
|
0
|
|
|
|
|
0
|
$format2 = $PDLA::Complex::floatformat; |
1601
|
0
|
|
|
|
|
0
|
$findmax = 1; |
1602
|
|
|
|
|
|
|
} elsif ($dtype == $PDLA_D) { |
1603
|
1
|
|
|
|
|
2
|
$format2 = $PDLA::Complex::doubleformat; |
1604
|
1
|
|
|
|
|
2
|
$findmax = 1; |
1605
|
|
|
|
|
|
|
} else { |
1606
|
0
|
0
|
|
|
|
0
|
$findmax = 0 unless $findmax; |
1607
|
|
|
|
|
|
|
} |
1608
|
|
|
|
|
|
|
} |
1609
|
|
|
|
|
|
|
} |
1610
|
|
|
|
|
|
|
|
1611
|
1
|
50
|
|
|
|
4
|
if($findmax) { |
1612
|
1
|
|
|
|
|
2
|
$len1 = $len2=0; |
1613
|
|
|
|
|
|
|
|
1614
|
1
|
50
|
|
|
|
3
|
if ( $badflag ) { |
1615
|
0
|
|
|
|
|
0
|
for($i=0; $i<=$#$x; $i++){ |
1616
|
0
|
|
|
|
|
0
|
$findmax = $i % 2; |
1617
|
0
|
0
|
|
|
|
0
|
if ( $$x[$i] eq 'BAD' ){ |
1618
|
0
|
|
|
|
|
0
|
$f = 3; |
1619
|
|
|
|
|
|
|
} |
1620
|
|
|
|
|
|
|
else{ |
1621
|
0
|
0
|
|
|
|
0
|
$f = $findmax ? length(sprintf $format2,$$x[$i]) : |
1622
|
|
|
|
|
|
|
length(sprintf $format1,$$x[$i]); |
1623
|
|
|
|
|
|
|
} |
1624
|
0
|
0
|
|
|
|
0
|
if ($findmax){ |
1625
|
0
|
0
|
|
|
|
0
|
$len2 = $f if $f > $len2; |
1626
|
|
|
|
|
|
|
} |
1627
|
|
|
|
|
|
|
else{ |
1628
|
0
|
0
|
|
|
|
0
|
$len1 = $f if $f > $len1; |
1629
|
|
|
|
|
|
|
} |
1630
|
|
|
|
|
|
|
} |
1631
|
|
|
|
|
|
|
} else { |
1632
|
1
|
|
|
|
|
20
|
for ($i=0; $i<=$#$x; $i++) { |
1633
|
2
|
100
|
|
|
|
7
|
if ($i % 2){ |
1634
|
1
|
|
|
|
|
5
|
$f = length(sprintf $format2,$$x[$i]); |
1635
|
1
|
50
|
|
|
|
5
|
$len2 = $f if $f > $len2; |
1636
|
|
|
|
|
|
|
} |
1637
|
|
|
|
|
|
|
else{ |
1638
|
1
|
|
|
|
|
10
|
$f = length(sprintf $format1,$$x[$i]); |
1639
|
1
|
50
|
|
|
|
14
|
$len1 = $f if $f > $len1; |
1640
|
|
|
|
|
|
|
} |
1641
|
|
|
|
|
|
|
} |
1642
|
|
|
|
|
|
|
} |
1643
|
|
|
|
|
|
|
|
1644
|
|
|
|
|
|
|
|
1645
|
|
|
|
|
|
|
} # if: $findmax |
1646
|
|
|
|
|
|
|
|
1647
|
1
|
|
|
|
|
5
|
$ret = "\n" . ' 'x$level . "[\n"; |
1648
|
|
|
|
|
|
|
{ |
1649
|
1
|
|
|
|
|
3
|
my $level = $level+1; |
|
1
|
|
|
|
|
2
|
|
1650
|
1
|
|
|
|
|
2
|
$ret .= ' 'x$level .'['; |
1651
|
1
|
|
|
|
|
2
|
$len2 += 2; |
1652
|
|
|
|
|
|
|
|
1653
|
1
|
|
|
|
|
3
|
for ($i=0; $i<=$#$x; $i++) { |
1654
|
2
|
|
|
|
|
3
|
$findmax = $i % 2; |
1655
|
2
|
100
|
|
|
|
3
|
if ($findmax){ |
1656
|
1
|
50
|
33
|
|
|
5
|
if ( $badflag and $$x[$i] eq 'BAD' ){ |
1657
|
|
|
|
|
|
|
#|| |
1658
|
|
|
|
|
|
|
#($findmax && $$x[$i - 1 ] eq 'BAD') || |
1659
|
|
|
|
|
|
|
#(!$findmax && $$x[$i +1 ] eq 'BAD')){ |
1660
|
0
|
|
|
|
|
0
|
$f = "BAD"; |
1661
|
|
|
|
|
|
|
} |
1662
|
|
|
|
|
|
|
else{ |
1663
|
1
|
|
|
|
|
3
|
$f = sprintf $format2, $$x[$i]; |
1664
|
1
|
50
|
|
|
|
6
|
if (substr($$x[$i],0,1) eq '-'){ |
1665
|
0
|
|
|
|
|
0
|
$f.='i'; |
1666
|
|
|
|
|
|
|
} |
1667
|
|
|
|
|
|
|
else{ |
1668
|
1
|
|
|
|
|
10
|
$f =~ s/(\s*)(.*)/+$2i/; |
1669
|
|
|
|
|
|
|
} |
1670
|
|
|
|
|
|
|
} |
1671
|
1
|
|
|
|
|
4
|
$t = $len2-length($f); |
1672
|
|
|
|
|
|
|
} |
1673
|
|
|
|
|
|
|
else{ |
1674
|
1
|
50
|
33
|
|
|
10
|
if ( $badflag and $$x[$i] eq 'BAD' ){ |
1675
|
0
|
|
|
|
|
0
|
$f = "BAD"; |
1676
|
|
|
|
|
|
|
} |
1677
|
|
|
|
|
|
|
else{ |
1678
|
1
|
|
|
|
|
6
|
$f = sprintf $format1, $$x[$i]; |
1679
|
1
|
|
|
|
|
4
|
$t = $len1-length($f); |
1680
|
|
|
|
|
|
|
} |
1681
|
|
|
|
|
|
|
} |
1682
|
|
|
|
|
|
|
|
1683
|
2
|
50
|
|
|
|
5
|
$f = ' 'x$t.$f if $t>0; |
1684
|
|
|
|
|
|
|
|
1685
|
2
|
|
|
|
|
4
|
$ret .= $f; |
1686
|
2
|
100
|
|
|
|
6
|
if (($i+1)%($dims[1]*2)) { |
1687
|
1
|
50
|
|
|
|
6
|
$ret.=$sep if $findmax; |
1688
|
|
|
|
|
|
|
} |
1689
|
|
|
|
|
|
|
else{ # End of output line |
1690
|
1
|
|
|
|
|
2
|
$ret.=']'; |
1691
|
1
|
50
|
|
|
|
3
|
if ($i==$#$x) { # very last number |
1692
|
1
|
|
|
|
|
4
|
$ret.="\n"; |
1693
|
|
|
|
|
|
|
} |
1694
|
|
|
|
|
|
|
else{ |
1695
|
0
|
|
|
|
|
0
|
$ret.= $sep2."\n" . ' 'x$level .'['; |
1696
|
|
|
|
|
|
|
} |
1697
|
|
|
|
|
|
|
} |
1698
|
|
|
|
|
|
|
} |
1699
|
|
|
|
|
|
|
} |
1700
|
1
|
|
|
|
|
4
|
$ret .= ' 'x$level."]\n"; |
1701
|
1
|
|
|
|
|
7
|
return $ret; |
1702
|
|
|
|
|
|
|
} |
1703
|
|
|
|
|
|
|
|
1704
|
|
|
|
|
|
|
} |
1705
|
|
|
|
|
|
|
|
1706
|
|
|
|
|
|
|
=head1 AUTHOR |
1707
|
|
|
|
|
|
|
|
1708
|
|
|
|
|
|
|
Copyright (C) 2000 Marc Lehmann . |
1709
|
|
|
|
|
|
|
All rights reserved. There is no warranty. You are allowed |
1710
|
|
|
|
|
|
|
to redistribute this software / documentation as described |
1711
|
|
|
|
|
|
|
in the file COPYING in the PDLA distribution. |
1712
|
|
|
|
|
|
|
|
1713
|
|
|
|
|
|
|
=head1 SEE ALSO |
1714
|
|
|
|
|
|
|
|
1715
|
|
|
|
|
|
|
perl(1), L. |
1716
|
|
|
|
|
|
|
|
1717
|
|
|
|
|
|
|
=cut |
1718
|
|
|
|
|
|
|
|
1719
|
|
|
|
|
|
|
|
1720
|
|
|
|
|
|
|
|
1721
|
|
|
|
|
|
|
|
1722
|
|
|
|
|
|
|
|
1723
|
|
|
|
|
|
|
|
1724
|
|
|
|
|
|
|
# Exit with OK status |
1725
|
|
|
|
|
|
|
|
1726
|
|
|
|
|
|
|
1; |
1727
|
|
|
|
|
|
|
|
1728
|
|
|
|
|
|
|
|