1Ops(3) User Contributed Perl Documentation Ops(3)
2
3
4
6 PDL::Ops - Fundamental mathematical operators
7
9 This module provides the functions used by PDL to overload the basic
10 mathematical operators ("+ - / *" etc.) and functions ("sin sqrt" etc.)
11
12 It also includes the function "log10", which should be a perl function
13 so that we can overload it!
14
15 Matrix multiplication (the operator "x") is handled by the module
16 PDL::Primitive.
17
19 none
20
22 plus
23 Signature: (a(); b(); [o]c(); int swap)
24
25 add two ndarrays
26
27 $c = plus $x, $y, 0; # explicit call with trailing 0
28 $c = $x + $y; # overloaded call
29 $x->inplace->plus($y,0); # modify $x inplace
30
31 It can be made to work inplace with the "$x->inplace" syntax. This
32 function is used to overload the binary "+" operator. Note that when
33 calling this function explicitly you need to supply a third argument
34 that should generally be zero (see first example). This restriction is
35 expected to go away in future releases.
36
37 plus processes bad values. The state of the bad-value flag of the
38 output ndarrays is unknown.
39
40 mult
41 Signature: (a(); b(); [o]c(); int swap)
42
43 multiply two ndarrays
44
45 $c = mult $x, $y, 0; # explicit call with trailing 0
46 $c = $x * $y; # overloaded call
47 $x->inplace->mult($y,0); # modify $x inplace
48
49 It can be made to work inplace with the "$x->inplace" syntax. This
50 function is used to overload the binary "*" operator. Note that when
51 calling this function explicitly you need to supply a third argument
52 that should generally be zero (see first example). This restriction is
53 expected to go away in future releases.
54
55 mult processes bad values. The state of the bad-value flag of the
56 output ndarrays is unknown.
57
58 minus
59 Signature: (a(); b(); [o]c(); int swap)
60
61 subtract two ndarrays
62
63 $c = minus $x, $y, 0; # explicit call with trailing 0
64 $c = $x - $y; # overloaded call
65 $x->inplace->minus($y,0); # modify $x inplace
66
67 It can be made to work inplace with the "$x->inplace" syntax. This
68 function is used to overload the binary "-" operator. Note that when
69 calling this function explicitly you need to supply a third argument
70 that should generally be zero (see first example). This restriction is
71 expected to go away in future releases.
72
73 minus processes bad values. The state of the bad-value flag of the
74 output ndarrays is unknown.
75
76 divide
77 Signature: (a(); b(); [o]c(); int swap)
78
79 divide two ndarrays
80
81 $c = divide $x, $y, 0; # explicit call with trailing 0
82 $c = $x / $y; # overloaded call
83 $x->inplace->divide($y,0); # modify $x inplace
84
85 It can be made to work inplace with the "$x->inplace" syntax. This
86 function is used to overload the binary "/" operator. Note that when
87 calling this function explicitly you need to supply a third argument
88 that should generally be zero (see first example). This restriction is
89 expected to go away in future releases.
90
91 divide processes bad values. The state of the bad-value flag of the
92 output ndarrays is unknown.
93
94 gt
95 Signature: (a(); b(); [o]c(); int swap)
96
97 the binary > (greater than) operation
98
99 $c = gt $x, $y, 0; # explicit call with trailing 0
100 $c = $x > $y; # overloaded call
101 $x->inplace->gt($y,0); # modify $x inplace
102
103 It can be made to work inplace with the "$x->inplace" syntax. This
104 function is used to overload the binary ">" operator. Note that when
105 calling this function explicitly you need to supply a third argument
106 that should generally be zero (see first example). This restriction is
107 expected to go away in future releases.
108
109 gt processes bad values. The state of the bad-value flag of the output
110 ndarrays is unknown.
111
112 lt
113 Signature: (a(); b(); [o]c(); int swap)
114
115 the binary < (less than) operation
116
117 $c = lt $x, $y, 0; # explicit call with trailing 0
118 $c = $x < $y; # overloaded call
119 $x->inplace->lt($y,0); # modify $x inplace
120
121 It can be made to work inplace with the "$x->inplace" syntax. This
122 function is used to overload the binary "<" operator. Note that when
123 calling this function explicitly you need to supply a third argument
124 that should generally be zero (see first example). This restriction is
125 expected to go away in future releases.
126
127 lt processes bad values. The state of the bad-value flag of the output
128 ndarrays is unknown.
129
130 le
131 Signature: (a(); b(); [o]c(); int swap)
132
133 the binary <= (less equal) operation
134
135 $c = le $x, $y, 0; # explicit call with trailing 0
136 $c = $x <= $y; # overloaded call
137 $x->inplace->le($y,0); # modify $x inplace
138
139 It can be made to work inplace with the "$x->inplace" syntax. This
140 function is used to overload the binary "<=" operator. Note that when
141 calling this function explicitly you need to supply a third argument
142 that should generally be zero (see first example). This restriction is
143 expected to go away in future releases.
144
145 le processes bad values. The state of the bad-value flag of the output
146 ndarrays is unknown.
147
148 ge
149 Signature: (a(); b(); [o]c(); int swap)
150
151 the binary >= (greater equal) operation
152
153 $c = ge $x, $y, 0; # explicit call with trailing 0
154 $c = $x >= $y; # overloaded call
155 $x->inplace->ge($y,0); # modify $x inplace
156
157 It can be made to work inplace with the "$x->inplace" syntax. This
158 function is used to overload the binary ">=" operator. Note that when
159 calling this function explicitly you need to supply a third argument
160 that should generally be zero (see first example). This restriction is
161 expected to go away in future releases.
162
163 ge processes bad values. The state of the bad-value flag of the output
164 ndarrays is unknown.
165
166 eq
167 Signature: (a(); b(); [o]c(); int swap)
168
169 binary equal to operation ("==")
170
171 $c = eq $x, $y, 0; # explicit call with trailing 0
172 $c = $x == $y; # overloaded call
173 $x->inplace->eq($y,0); # modify $x inplace
174
175 It can be made to work inplace with the "$x->inplace" syntax. This
176 function is used to overload the binary "==" operator. Note that when
177 calling this function explicitly you need to supply a third argument
178 that should generally be zero (see first example). This restriction is
179 expected to go away in future releases.
180
181 eq processes bad values. The state of the bad-value flag of the output
182 ndarrays is unknown.
183
184 ne
185 Signature: (a(); b(); [o]c(); int swap)
186
187 binary not equal to operation ("!=")
188
189 $c = ne $x, $y, 0; # explicit call with trailing 0
190 $c = $x != $y; # overloaded call
191 $x->inplace->ne($y,0); # modify $x inplace
192
193 It can be made to work inplace with the "$x->inplace" syntax. This
194 function is used to overload the binary "!=" operator. Note that when
195 calling this function explicitly you need to supply a third argument
196 that should generally be zero (see first example). This restriction is
197 expected to go away in future releases.
198
199 ne processes bad values. The state of the bad-value flag of the output
200 ndarrays is unknown.
201
202 shiftleft
203 Signature: (a(); b(); [o]c(); int swap)
204
205 leftshift $a by $b
206
207 $c = shiftleft $x, $y, 0; # explicit call with trailing 0
208 $c = $x << $y; # overloaded call
209 $x->inplace->shiftleft($y,0); # modify $x inplace
210
211 It can be made to work inplace with the "$x->inplace" syntax. This
212 function is used to overload the binary "<<" operator. Note that when
213 calling this function explicitly you need to supply a third argument
214 that should generally be zero (see first example). This restriction is
215 expected to go away in future releases.
216
217 shiftleft processes bad values. The state of the bad-value flag of the
218 output ndarrays is unknown.
219
220 shiftright
221 Signature: (a(); b(); [o]c(); int swap)
222
223 rightshift $a by $b
224
225 $c = shiftright $x, $y, 0; # explicit call with trailing 0
226 $c = $x >> $y; # overloaded call
227 $x->inplace->shiftright($y,0); # modify $x inplace
228
229 It can be made to work inplace with the "$x->inplace" syntax. This
230 function is used to overload the binary ">>" operator. Note that when
231 calling this function explicitly you need to supply a third argument
232 that should generally be zero (see first example). This restriction is
233 expected to go away in future releases.
234
235 shiftright processes bad values. The state of the bad-value flag of
236 the output ndarrays is unknown.
237
238 or2
239 Signature: (a(); b(); [o]c(); int swap)
240
241 binary or of two ndarrays
242
243 $c = or2 $x, $y, 0; # explicit call with trailing 0
244 $c = $x | $y; # overloaded call
245 $x->inplace->or2($y,0); # modify $x inplace
246
247 It can be made to work inplace with the "$x->inplace" syntax. This
248 function is used to overload the binary "|" operator. Note that when
249 calling this function explicitly you need to supply a third argument
250 that should generally be zero (see first example). This restriction is
251 expected to go away in future releases.
252
253 or2 processes bad values. The state of the bad-value flag of the
254 output ndarrays is unknown.
255
256 and2
257 Signature: (a(); b(); [o]c(); int swap)
258
259 binary and of two ndarrays
260
261 $c = and2 $x, $y, 0; # explicit call with trailing 0
262 $c = $x & $y; # overloaded call
263 $x->inplace->and2($y,0); # modify $x inplace
264
265 It can be made to work inplace with the "$x->inplace" syntax. This
266 function is used to overload the binary "&" operator. Note that when
267 calling this function explicitly you need to supply a third argument
268 that should generally be zero (see first example). This restriction is
269 expected to go away in future releases.
270
271 and2 processes bad values. The state of the bad-value flag of the
272 output ndarrays is unknown.
273
274 xor
275 Signature: (a(); b(); [o]c(); int swap)
276
277 binary exclusive or of two ndarrays
278
279 $c = xor $x, $y, 0; # explicit call with trailing 0
280 $c = $x ^ $y; # overloaded call
281 $x->inplace->xor($y,0); # modify $x inplace
282
283 It can be made to work inplace with the "$x->inplace" syntax. This
284 function is used to overload the binary "^" operator. Note that when
285 calling this function explicitly you need to supply a third argument
286 that should generally be zero (see first example). This restriction is
287 expected to go away in future releases.
288
289 xor processes bad values. The state of the bad-value flag of the
290 output ndarrays is unknown.
291
292 bitnot
293 Signature: (a(); [o]b())
294
295 unary bit negation
296
297 $y = ~ $x;
298 $x->inplace->bitnot; # modify $x inplace
299
300 It can be made to work inplace with the "$x->inplace" syntax. This
301 function is used to overload the unary "~" operator/function.
302
303 bitnot processes bad values. It will set the bad-value flag of all
304 output ndarrays if the flag is set for any of the input ndarrays.
305
306 power
307 Signature: (a(); b(); [o]c(); int swap)
308
309 raise ndarray $a to the power $b
310
311 $c = $x->power($y,0); # explicit function call
312 $c = $a ** $b; # overloaded use
313 $x->inplace->power($y,0); # modify $x inplace
314
315 It can be made to work inplace with the "$x->inplace" syntax. This
316 function is used to overload the binary "**" function. Note that when
317 calling this function explicitly you need to supply a third argument
318 that should generally be zero (see first example). This restriction is
319 expected to go away in future releases.
320
321 power processes bad values. The state of the bad-value flag of the
322 output ndarrays is unknown.
323
324 atan2
325 Signature: (a(); b(); [o]c(); int swap)
326
327 elementwise "atan2" of two ndarrays
328
329 $c = $x->atan2($y,0); # explicit function call
330 $c = atan2 $a, $b; # overloaded use
331 $x->inplace->atan2($y,0); # modify $x inplace
332
333 It can be made to work inplace with the "$x->inplace" syntax. This
334 function is used to overload the binary "atan2" function. Note that
335 when calling this function explicitly you need to supply a third
336 argument that should generally be zero (see first example). This
337 restriction is expected to go away in future releases.
338
339 atan2 processes bad values. The state of the bad-value flag of the
340 output ndarrays is unknown.
341
342 modulo
343 Signature: (a(); b(); [o]c(); int swap)
344
345 elementwise "modulo" operation
346
347 $c = $x->modulo($y,0); # explicit function call
348 $c = $a % $b; # overloaded use
349 $x->inplace->modulo($y,0); # modify $x inplace
350
351 It can be made to work inplace with the "$x->inplace" syntax. This
352 function is used to overload the binary "%" function. Note that when
353 calling this function explicitly you need to supply a third argument
354 that should generally be zero (see first example). This restriction is
355 expected to go away in future releases.
356
357 modulo processes bad values. The state of the bad-value flag of the
358 output ndarrays is unknown.
359
360 spaceship
361 Signature: (a(); b(); [o]c(); int swap)
362
363 elementwise "<=>" operation
364
365 $c = $x->spaceship($y,0); # explicit function call
366 $c = $a <=> $b; # overloaded use
367 $x->inplace->spaceship($y,0); # modify $x inplace
368
369 It can be made to work inplace with the "$x->inplace" syntax. This
370 function is used to overload the binary "<=>" function. Note that when
371 calling this function explicitly you need to supply a third argument
372 that should generally be zero (see first example). This restriction is
373 expected to go away in future releases.
374
375 spaceship processes bad values. The state of the bad-value flag of the
376 output ndarrays is unknown.
377
378 sqrt
379 Signature: (a(); [o]b())
380
381 elementwise square root
382
383 $y = sqrt $x;
384 $x->inplace->sqrt; # modify $x inplace
385
386 It can be made to work inplace with the "$x->inplace" syntax. This
387 function is used to overload the unary "sqrt" operator/function.
388
389 sqrt processes bad values. It will set the bad-value flag of all
390 output ndarrays if the flag is set for any of the input ndarrays.
391
392 sin
393 Signature: (a(); [o]b())
394
395 the sin function
396
397 $y = sin $x;
398 $x->inplace->sin; # modify $x inplace
399
400 It can be made to work inplace with the "$x->inplace" syntax. This
401 function is used to overload the unary "sin" operator/function.
402
403 sin processes bad values. It will set the bad-value flag of all output
404 ndarrays if the flag is set for any of the input ndarrays.
405
406 cos
407 Signature: (a(); [o]b())
408
409 the cos function
410
411 $y = cos $x;
412 $x->inplace->cos; # modify $x inplace
413
414 It can be made to work inplace with the "$x->inplace" syntax. This
415 function is used to overload the unary "cos" operator/function.
416
417 cos processes bad values. It will set the bad-value flag of all output
418 ndarrays if the flag is set for any of the input ndarrays.
419
420 not
421 Signature: (a(); [o]b())
422
423 the elementwise not operation
424
425 $y = ! $x;
426 $x->inplace->not; # modify $x inplace
427
428 It can be made to work inplace with the "$x->inplace" syntax. This
429 function is used to overload the unary "!" operator/function.
430
431 not processes bad values. It will set the bad-value flag of all output
432 ndarrays if the flag is set for any of the input ndarrays.
433
434 exp
435 Signature: (a(); [o]b())
436
437 the exponential function
438
439 $y = exp $x;
440 $x->inplace->exp; # modify $x inplace
441
442 It can be made to work inplace with the "$x->inplace" syntax. This
443 function is used to overload the unary "exp" operator/function.
444
445 exp processes bad values. It will set the bad-value flag of all output
446 ndarrays if the flag is set for any of the input ndarrays.
447
448 log
449 Signature: (a(); [o]b())
450
451 the natural logarithm
452
453 $y = log $x;
454 $x->inplace->log; # modify $x inplace
455
456 It can be made to work inplace with the "$x->inplace" syntax. This
457 function is used to overload the unary "log" operator/function.
458
459 log processes bad values. It will set the bad-value flag of all output
460 ndarrays if the flag is set for any of the input ndarrays.
461
462 re
463 Signature: (complexv(); real [o]b())
464
465 Returns the real part of a complex number.
466
467 re processes bad values. It will set the bad-value flag of all output
468 ndarrays if the flag is set for any of the input ndarrays.
469
470 im
471 Signature: (complexv(); real [o]b())
472
473 Returns the imaginary part of a complex number.
474
475 im processes bad values. It will set the bad-value flag of all output
476 ndarrays if the flag is set for any of the input ndarrays.
477
478 _cabs
479 Signature: (complexv(); real [o]b())
480
481 Returns the absolute (length) of a complex number.
482
483 _cabs processes bad values. It will set the bad-value flag of all
484 output ndarrays if the flag is set for any of the input ndarrays.
485
486 log10
487 Signature: (a(); [o]b())
488
489 the base 10 logarithm
490
491 $y = log10 $x;
492 $x->inplace->log10; # modify $x inplace
493
494 It can be made to work inplace with the "$x->inplace" syntax. This
495 function is used to overload the unary "log10" operator/function.
496
497 log10 processes bad values. It will set the bad-value flag of all
498 output ndarrays if the flag is set for any of the input ndarrays.
499
500 assgn
501 Signature: (a(); [o]b())
502
503 Plain numerical assignment. This is used to implement the ".=" operator
504
505 If "a" is a child ndarray (e.g., the result of a slice) and bad values
506 are generated in "b", the bad value flag is set in "b", but it is NOT
507 automatically propagated back to the parent of "a". The following
508 idiom ensures that the badflag is propagated back to the parent of "a":
509
510 $pdl->slice(":,(1)") .= PDL::Bad_aware_func();
511 $pdl->badflag(1);
512 $pdl->check_badflag();
513
514 This is unnecessary if $pdl->badflag is known to be 1 before the slice
515 is performed.
516
517 See http://pdl.perl.org/PDLdocs/BadValues.html#dataflow_of_the_badflag
518 for details.
519
520 carg
521 Signature: (complexv(); real [o]b())
522
523 Returns the polar angle of a complex number.
524
525 carg processes bad values. It will set the bad-value flag of all
526 output ndarrays if the flag is set for any of the input ndarrays.
527
528 conj
529 Signature: (complexv(); [o]b())
530
531 complex conjugate.
532
533 conj processes bad values. It will set the bad-value flag of all
534 output ndarrays if the flag is set for any of the input ndarrays.
535
536 czip
537 Signature: (r(); i(); complex [o]c())
538
539 convert real, imaginary to native complex, (sort of) like LISP zip
540 function. Will add the "r" ndarray to "i" times the "i" ndarray. Only
541 takes real ndarrays as input.
542
543 czip does not process bad values. It will set the bad-value flag of
544 all output ndarrays if the flag is set for any of the input ndarrays.
545
546 ipow
547 Signature: (a(); indx b(); [o] ans())
548
549 raise ndarray $a to integer power $b
550
551 $c = $x->ipow($y,0); # explicit function call
552 $c = ipow $x, $y;
553 $x->inplace->ipow($y,0); # modify $x inplace
554
555 It can be made to work inplace with the "$x->inplace" syntax. Note
556 that when calling this function explicitly you need to supply a third
557 argument that should generally be zero (see first example). This
558 restriction is expected to go away in future releases.
559
560 Algorithm from Wikipedia
561 <http://en.wikipedia.org/wiki/Exponentiation_by_squaring>
562
563 ipow does not process bad values. It will set the bad-value flag of
564 all output ndarrays if the flag is set for any of the input ndarrays.
565
566 abs
567 Returns the absolute value of a number.
568
569 abs2
570 Returns the square of the absolute value of a number.
571
572 r2C
573 Signature: (r(); complex [o]c())
574
575 convert real to native complex, with an imaginary part of zero
576
577 r2C does not process bad values. It will set the bad-value flag of all
578 output ndarrays if the flag is set for any of the input ndarrays.
579
580 i2C
581 Signature: (i(); complex [o]c())
582
583 convert imaginary to native complex, with a real part of zero
584
585 i2C does not process bad values. It will set the bad-value flag of all
586 output ndarrays if the flag is set for any of the input ndarrays.
587
589 Tuomas J. Lukka (lukka@fas.harvard.edu), Karl Glazebrook
590 (kgb@aaoepp.aao.gov.au), Doug Hunt (dhunt@ucar.edu), Christian Soeller
591 (c.soeller@auckland.ac.nz), Doug Burke (burke@ifa.hawaii.edu), and
592 Craig DeForest (deforest@boulder.swri.edu).
593
594
595
596perl v5.34.0 2021-08-16 Ops(3)