PDL::Ops - Fundamental mathematical operators
This module provides the functions used by PDL to overload the basic mathematical operators (+ - / * etc.) and functions (sin sqrt etc.)
+ - / *
sin sqrt
It also includes the function log10, which should be a perl function so that we can overload it!
log10
Matrix multiplication (the operator x) is handled by the module PDL::Primitive.
x
none
Signature: (a(); b(); [o]c(); int swap)
add two ndarrays
$c = $x + $y; # overloaded call $c = plus $x, $y; # explicit call with default swap of 0 $c = plus $x, $y, 1; # explicit call with trailing 1 to swap args $x->inplace->plus($y); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the binary + operator. As of 2.065, when calling this function explicitly you can omit the third argument (see second example), or supply it (see third one).
$x->inplace
+
plus processes bad values. The state of the bad-value flag of the output ndarrays is unknown.
multiply two ndarrays
$c = $x * $y; # overloaded call $c = mult $x, $y; # explicit call with default swap of 0 $c = mult $x, $y, 1; # explicit call with trailing 1 to swap args $x->inplace->mult($y); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the binary * operator. As of 2.065, when calling this function explicitly you can omit the third argument (see second example), or supply it (see third one).
*
mult processes bad values. The state of the bad-value flag of the output ndarrays is unknown.
subtract two ndarrays
$c = $x - $y; # overloaded call $c = minus $x, $y; # explicit call with default swap of 0 $c = minus $x, $y, 1; # explicit call with trailing 1 to swap args $x->inplace->minus($y); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the binary - operator. As of 2.065, when calling this function explicitly you can omit the third argument (see second example), or supply it (see third one).
-
minus processes bad values. The state of the bad-value flag of the output ndarrays is unknown.
divide two ndarrays
$c = $x / $y; # overloaded call $c = divide $x, $y; # explicit call with default swap of 0 $c = divide $x, $y, 1; # explicit call with trailing 1 to swap args $x->inplace->divide($y); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the binary / operator. As of 2.065, when calling this function explicitly you can omit the third argument (see second example), or supply it (see third one).
/
divide processes bad values. The state of the bad-value flag of the output ndarrays is unknown.
the binary > (greater than) operation
$c = $x > $y; # overloaded call $c = gt $x, $y; # explicit call with default swap of 0 $c = gt $x, $y, 1; # explicit call with trailing 1 to swap args $x->inplace->gt($y); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the binary > operator. As of 2.065, when calling this function explicitly you can omit the third argument (see second example), or supply it (see third one).
>
gt processes bad values. The state of the bad-value flag of the output ndarrays is unknown.
the binary < (less than) operation
$c = $x < $y; # overloaded call $c = lt $x, $y; # explicit call with default swap of 0 $c = lt $x, $y, 1; # explicit call with trailing 1 to swap args $x->inplace->lt($y); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the binary < operator. As of 2.065, when calling this function explicitly you can omit the third argument (see second example), or supply it (see third one).
<
lt processes bad values. The state of the bad-value flag of the output ndarrays is unknown.
the binary <= (less equal) operation
$c = $x <= $y; # overloaded call $c = le $x, $y; # explicit call with default swap of 0 $c = le $x, $y, 1; # explicit call with trailing 1 to swap args $x->inplace->le($y); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the binary <= operator. As of 2.065, when calling this function explicitly you can omit the third argument (see second example), or supply it (see third one).
<=
le processes bad values. The state of the bad-value flag of the output ndarrays is unknown.
the binary >= (greater equal) operation
$c = $x >= $y; # overloaded call $c = ge $x, $y; # explicit call with default swap of 0 $c = ge $x, $y, 1; # explicit call with trailing 1 to swap args $x->inplace->ge($y); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the binary >= operator. As of 2.065, when calling this function explicitly you can omit the third argument (see second example), or supply it (see third one).
>=
ge processes bad values. The state of the bad-value flag of the output ndarrays is unknown.
binary equal to operation (==)
==
$c = $x == $y; # overloaded call $c = eq $x, $y; # explicit call with default swap of 0 $c = eq $x, $y, 1; # explicit call with trailing 1 to swap args $x->inplace->eq($y); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the binary == operator. As of 2.065, when calling this function explicitly you can omit the third argument (see second example), or supply it (see third one).
eq processes bad values. The state of the bad-value flag of the output ndarrays is unknown.
binary not equal to operation (!=)
!=
$c = $x != $y; # overloaded call $c = ne $x, $y; # explicit call with default swap of 0 $c = ne $x, $y, 1; # explicit call with trailing 1 to swap args $x->inplace->ne($y); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the binary != operator. As of 2.065, when calling this function explicitly you can omit the third argument (see second example), or supply it (see third one).
ne processes bad values. The state of the bad-value flag of the output ndarrays is unknown.
leftshift $a by $b
$a
$b
$c = $x << $y; # overloaded call $c = shiftleft $x, $y; # explicit call with default swap of 0 $c = shiftleft $x, $y, 1; # explicit call with trailing 1 to swap args $x->inplace->shiftleft($y); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the binary << operator. As of 2.065, when calling this function explicitly you can omit the third argument (see second example), or supply it (see third one).
<<
shiftleft processes bad values. The state of the bad-value flag of the output ndarrays is unknown.
rightshift $a by $b
$c = $x >> $y; # overloaded call $c = shiftright $x, $y; # explicit call with default swap of 0 $c = shiftright $x, $y, 1; # explicit call with trailing 1 to swap args $x->inplace->shiftright($y); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the binary >> operator. As of 2.065, when calling this function explicitly you can omit the third argument (see second example), or supply it (see third one).
>>
shiftright processes bad values. The state of the bad-value flag of the output ndarrays is unknown.
binary or of two ndarrays
$c = $x | $y; # overloaded call $c = or2 $x, $y; # explicit call with default swap of 0 $c = or2 $x, $y, 1; # explicit call with trailing 1 to swap args $x->inplace->or2($y); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the binary | operator. As of 2.065, when calling this function explicitly you can omit the third argument (see second example), or supply it (see third one).
|
or2 processes bad values. The state of the bad-value flag of the output ndarrays is unknown.
binary and of two ndarrays
$c = $x & $y; # overloaded call $c = and2 $x, $y; # explicit call with default swap of 0 $c = and2 $x, $y, 1; # explicit call with trailing 1 to swap args $x->inplace->and2($y); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the binary & operator. As of 2.065, when calling this function explicitly you can omit the third argument (see second example), or supply it (see third one).
&
and2 processes bad values. The state of the bad-value flag of the output ndarrays is unknown.
binary exclusive or of two ndarrays
$c = $x ^ $y; # overloaded call $c = xor $x, $y; # explicit call with default swap of 0 $c = xor $x, $y, 1; # explicit call with trailing 1 to swap args $x->inplace->xor($y); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the binary ^ operator. As of 2.065, when calling this function explicitly you can omit the third argument (see second example), or supply it (see third one).
^
xor processes bad values. The state of the bad-value flag of the output ndarrays is unknown.
Signature: (a(); [o]b())
unary bit negation
$y = ~ $x; $x->inplace->bitnot; # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the unary ~ operator/function.
~
bitnot processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
raise ndarray $a to the power $b
$c = $x->power($y,0); # explicit function call $c = $a ** $b; # overloaded use $x->inplace->power($y,0); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the binary ** function. Note that when calling this function explicitly you need to supply a third argument that should generally be zero (see first example). This restriction is expected to go away in future releases.
**
power processes bad values. The state of the bad-value flag of the output ndarrays is unknown.
elementwise atan2 of two ndarrays
atan2
$c = $x->atan2($y,0); # explicit function call $c = atan2 $a, $b; # overloaded use $x->inplace->atan2($y,0); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the binary atan2 function. Note that when calling this function explicitly you need to supply a third argument that should generally be zero (see first example). This restriction is expected to go away in future releases.
atan2 processes bad values. The state of the bad-value flag of the output ndarrays is unknown.
elementwise modulo operation
modulo
$c = $x->modulo($y,0); # explicit function call $c = $a % $b; # overloaded use $x->inplace->modulo($y,0); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the binary % function. Note that when calling this function explicitly you need to supply a third argument that should generally be zero (see first example). This restriction is expected to go away in future releases.
%
modulo processes bad values. The state of the bad-value flag of the output ndarrays is unknown.
elementwise "<=>" operation
$c = $x->spaceship($y,0); # explicit function call $c = $a <=> $b; # overloaded use $x->inplace->spaceship($y,0); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the binary <=> function. Note that when calling this function explicitly you need to supply a third argument that should generally be zero (see first example). This restriction is expected to go away in future releases.
<=>
spaceship processes bad values. The state of the bad-value flag of the output ndarrays is unknown.
elementwise square root
$y = sqrt $x; $x->inplace->sqrt; # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the unary sqrt operator/function.
sqrt
sqrt processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
the sin function
$y = sin $x; $x->inplace->sin; # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the unary sin operator/function.
sin
sin processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
the cos function
$y = cos $x; $x->inplace->cos; # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the unary cos operator/function.
cos
cos processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
the elementwise not operation
$y = ! $x; $x->inplace->not; # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the unary ! operator/function.
!
not processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
the exponential function
$y = exp $x; $x->inplace->exp; # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the unary exp operator/function.
exp
exp processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
the natural logarithm
$y = log $x; $x->inplace->log; # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the unary log operator/function.
log
log processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Signature: (complexv(); real [o]b())
Returns the real part of a complex number.
re processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Returns the imaginary part of a complex number.
im processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Returns the absolute (length) of a complex number.
_cabs processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
the base 10 logarithm
$y = log10 $x; $x->inplace->log10; # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. This function is used to overload the unary log10 operator/function.
log10 processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Plain numerical assignment. This is used to implement the ".=" operator
If a is a child ndarray (e.g., the result of a slice) and bad values are generated in b, the bad value flag is set in b, but it is NOT automatically propagated back to the parent of a. The following idiom ensures that the badflag is propagated back to the parent of a:
a
b
$pdl->slice(":,(1)") .= PDL::Bad_aware_func(); $pdl->badflag(1); $pdl->check_badflag();
This is unnecessary if $pdl->badflag is known to be 1 before the slice is performed.
See http://pdl.perl.org/PDLdocs/BadValues.html#dataflow_of_the_badflag for details.
Returns the polar angle of a complex number.
carg processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Signature: (complexv(); [o]b())
complex conjugate.
conj processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Signature: (r(); i(); complex [o]c())
convert real, imaginary to native complex, (sort of) like LISP zip function. Will add the r ndarray to "i" times the i ndarray. Only takes real ndarrays as input.
r
i
czip does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Signature: (a(); indx b(); [o] ans())
raise ndarray $a to integer power $b
$c = $x->ipow($y,0); # explicit function call $c = ipow $x, $y; $x->inplace->ipow($y,0); # modify $x inplace
It can be made to work inplace with the $x->inplace syntax. Note that when calling this function explicitly you need to supply a third argument that should generally be zero (see first example). This restriction is expected to go away in future releases.
Algorithm from Wikipedia
ipow does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Returns the absolute value of a number.
Returns the square of the absolute value of a number.
Signature: (r(); complex [o]c())
convert real to native complex, with an imaginary part of zero
r2C does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Signature: (i(); complex [o]c())
convert imaginary to native complex, with a real part of zero
i2C does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Tuomas J. Lukka (lukka@fas.harvard.edu), Karl Glazebrook (kgb@aaoepp.aao.gov.au), Doug Hunt (dhunt@ucar.edu), Christian Soeller (c.soeller@auckland.ac.nz), Doug Burke (burke@ifa.hawaii.edu), and Craig DeForest (deforest@boulder.swri.edu).
To install PDL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PDL
CPAN shell
perl -MCPAN -e shell install PDL
For more information on module installation, please visit the detailed CPAN module installation guide.