NAME
PDL::Ops - Fundamental mathematical operators
DESCRIPTION
This module provides the functions used by PDL to overload the basic mathematical operators (+ - / *
etc.) and functions (sin sqrt
etc.)
It also includes the function log10
, which should be a perl function so that we can overload it!
Matrix multiplication (the operator x
) is handled by the module PDL::Primitive.
SYNOPSIS
none
FUNCTIONS
plus
Signature: (a(); b(); [o]c(); int $swap)
add two ndarrays
$c = $x + $y; # overloaded call
$c = PDL::plus($x, $y); # explicit call with default swap of 0
$c = PDL::plus($x, $y, 0); # explicit call with explicit swap of 0
$c = PDL::plus($x, $y, 1); # explicit call with trailing 1 to swap args
PDL::plus($x, $y, $c, 1); # all params given
$x->plus($y, $c, 0); # method call, all params given
$c = $x->plus($y); # method call
$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).
plus 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.
mult
Signature: (a(); b(); [o]c(); int $swap)
multiply two ndarrays
$c = $x * $y; # overloaded call
$c = PDL::mult($x, $y); # explicit call with default swap of 0
$c = PDL::mult($x, $y, 0); # explicit call with explicit swap of 0
$c = PDL::mult($x, $y, 1); # explicit call with trailing 1 to swap args
PDL::mult($x, $y, $c, 1); # all params given
$x->mult($y, $c, 0); # method call, all params given
$c = $x->mult($y); # method call
$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. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
minus
Signature: (a(); b(); [o]c(); int $swap)
subtract two ndarrays
$c = $x - $y; # overloaded call
$c = PDL::minus($x, $y); # explicit call with default swap of 0
$c = PDL::minus($x, $y, 0); # explicit call with explicit swap of 0
$c = PDL::minus($x, $y, 1); # explicit call with trailing 1 to swap args
PDL::minus($x, $y, $c, 1); # all params given
$x->minus($y, $c, 0); # method call, all params given
$c = $x->minus($y); # method call
$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. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
divide
Signature: (a(); b(); [o]c(); int $swap)
divide two ndarrays
$c = $x / $y; # overloaded call
$c = PDL::divide($x, $y); # explicit call with default swap of 0
$c = PDL::divide($x, $y, 0); # explicit call with explicit swap of 0
$c = PDL::divide($x, $y, 1); # explicit call with trailing 1 to swap args
PDL::divide($x, $y, $c, 1); # all params given
$x->divide($y, $c, 0); # method call, all params given
$c = $x->divide($y); # method call
$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. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
gt
Signature: (a(); b(); [o]c(); int $swap)
the binary > (greater than) operation
$c = $x > $y; # overloaded call
$c = PDL::gt($x, $y); # explicit call with default swap of 0
$c = PDL::gt($x, $y, 0); # explicit call with explicit swap of 0
$c = PDL::gt($x, $y, 1); # explicit call with trailing 1 to swap args
PDL::gt($x, $y, $c, 1); # all params given
$x->gt($y, $c, 0); # method call, all params given
$c = $x->gt($y); # method call
$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. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
lt
Signature: (a(); b(); [o]c(); int $swap)
the binary < (less than) operation
$c = $x < $y; # overloaded call
$c = PDL::lt($x, $y); # explicit call with default swap of 0
$c = PDL::lt($x, $y, 0); # explicit call with explicit swap of 0
$c = PDL::lt($x, $y, 1); # explicit call with trailing 1 to swap args
PDL::lt($x, $y, $c, 1); # all params given
$x->lt($y, $c, 0); # method call, all params given
$c = $x->lt($y); # method call
$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. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
le
Signature: (a(); b(); [o]c(); int $swap)
the binary <= (less equal) operation
$c = $x <= $y; # overloaded call
$c = PDL::le($x, $y); # explicit call with default swap of 0
$c = PDL::le($x, $y, 0); # explicit call with explicit swap of 0
$c = PDL::le($x, $y, 1); # explicit call with trailing 1 to swap args
PDL::le($x, $y, $c, 1); # all params given
$x->le($y, $c, 0); # method call, all params given
$c = $x->le($y); # method call
$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. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
ge
Signature: (a(); b(); [o]c(); int $swap)
the binary >= (greater equal) operation
$c = $x >= $y; # overloaded call
$c = PDL::ge($x, $y); # explicit call with default swap of 0
$c = PDL::ge($x, $y, 0); # explicit call with explicit swap of 0
$c = PDL::ge($x, $y, 1); # explicit call with trailing 1 to swap args
PDL::ge($x, $y, $c, 1); # all params given
$x->ge($y, $c, 0); # method call, all params given
$c = $x->ge($y); # method call
$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. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
eq
Signature: (a(); b(); [o]c(); int $swap)
binary equal to operation (==
)
$c = $x == $y; # overloaded call
$c = PDL::eq($x, $y); # explicit call with default swap of 0
$c = PDL::eq($x, $y, 0); # explicit call with explicit swap of 0
$c = PDL::eq($x, $y, 1); # explicit call with trailing 1 to swap args
PDL::eq($x, $y, $c, 1); # all params given
$x->eq($y, $c, 0); # method call, all params given
$c = $x->eq($y); # method call
$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. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
ne
Signature: (a(); b(); [o]c(); int $swap)
binary not equal to operation (!=
)
$c = $x != $y; # overloaded call
$c = PDL::ne($x, $y); # explicit call with default swap of 0
$c = PDL::ne($x, $y, 0); # explicit call with explicit swap of 0
$c = PDL::ne($x, $y, 1); # explicit call with trailing 1 to swap args
PDL::ne($x, $y, $c, 1); # all params given
$x->ne($y, $c, 0); # method call, all params given
$c = $x->ne($y); # method call
$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. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
shiftleft
Signature: (a(); b(); [o]c(); int $swap)
leftshift $a
by $b
$c = $x << $y; # overloaded call
$c = PDL::shiftleft($x, $y); # explicit call with default swap of 0
$c = PDL::shiftleft($x, $y, 0); # explicit call with explicit swap of 0
$c = PDL::shiftleft($x, $y, 1); # explicit call with trailing 1 to swap args
PDL::shiftleft($x, $y, $c, 1); # all params given
$x->shiftleft($y, $c, 0); # method call, all params given
$c = $x->shiftleft($y); # method call
$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. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
shiftright
Signature: (a(); b(); [o]c(); int $swap)
rightshift $a
by $b
$c = $x >> $y; # overloaded call
$c = PDL::shiftright($x, $y); # explicit call with default swap of 0
$c = PDL::shiftright($x, $y, 0); # explicit call with explicit swap of 0
$c = PDL::shiftright($x, $y, 1); # explicit call with trailing 1 to swap args
PDL::shiftright($x, $y, $c, 1); # all params given
$x->shiftright($y, $c, 0); # method call, all params given
$c = $x->shiftright($y); # method call
$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. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
or2
Signature: (a(); b(); [o]c(); int $swap)
binary or of two ndarrays
$c = $x | $y; # overloaded call
$c = PDL::or2($x, $y); # explicit call with default swap of 0
$c = PDL::or2($x, $y, 0); # explicit call with explicit swap of 0
$c = PDL::or2($x, $y, 1); # explicit call with trailing 1 to swap args
PDL::or2($x, $y, $c, 1); # all params given
$x->or2($y, $c, 0); # method call, all params given
$c = $x->or2($y); # method call
$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. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
and2
Signature: (a(); b(); [o]c(); int $swap)
binary and of two ndarrays
$c = $x & $y; # overloaded call
$c = PDL::and2($x, $y); # explicit call with default swap of 0
$c = PDL::and2($x, $y, 0); # explicit call with explicit swap of 0
$c = PDL::and2($x, $y, 1); # explicit call with trailing 1 to swap args
PDL::and2($x, $y, $c, 1); # all params given
$x->and2($y, $c, 0); # method call, all params given
$c = $x->and2($y); # method call
$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. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
xor
Signature: (a(); b(); [o]c(); int $swap)
binary exclusive or of two ndarrays
$c = $x ^ $y; # overloaded call
$c = PDL::xor($x, $y); # explicit call with default swap of 0
$c = PDL::xor($x, $y, 0); # explicit call with explicit swap of 0
$c = PDL::xor($x, $y, 1); # explicit call with trailing 1 to swap args
PDL::xor($x, $y, $c, 1); # all params given
$x->xor($y, $c, 0); # method call, all params given
$c = $x->xor($y); # method call
$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. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
bitnot
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.
power
Signature: (a(); b(); [o]c(); int $swap)
raise ndarray $a
to the power $b
$c = $x->power($y); # explicit call with default swap of 0
$c = $x->power($y, 1); # explicit call with trailing 1 to swap args
$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. As of 2.065, when calling this function explicitly you can omit the third argument (see first example), or supply it (see second one).
power 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.
atan2
Signature: (a(); b(); [o]c(); int $swap)
elementwise atan2
of two ndarrays
$c = $x->atan2($y); # explicit call with default swap of 0
$c = $x->atan2($y, 1); # explicit call with trailing 1 to swap args
$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. As of 2.065, when calling this function explicitly you can omit the third argument (see first example), or supply it (see second one).
atan2 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.
modulo
Signature: (a(); b(); [o]c(); int $swap)
elementwise modulo
operation
$c = $x->modulo($y); # explicit call with default swap of 0
$c = $x->modulo($y, 1); # explicit call with trailing 1 to swap args
$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. As of 2.065, when calling this function explicitly you can omit the third argument (see first example), or supply it (see second one).
modulo 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.
spaceship
Signature: (a(); b(); [o]c(); int $swap)
elementwise "<=>" operation
$c = $x->spaceship($y); # explicit call with default swap of 0
$c = $x->spaceship($y, 1); # explicit call with trailing 1 to swap args
$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. As of 2.065, when calling this function explicitly you can omit the third argument (see first example), or supply it (see second one).
spaceship 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.
sqrt
Signature: (a(); [o]b())
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 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.
sin
Signature: (a(); [o]b())
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 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.
cos
Signature: (a(); [o]b())
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 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.
not
Signature: (a(); [o]b())
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.
exp
Signature: (a(); [o]b())
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 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.
log
Signature: (a(); [o]b())
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 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.
re
Signature: (complexv(); real [o]b())
Returns the real part of a complex number. Flows data back & forth.
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.
im
Signature: (complexv(); real [o]b())
Returns the imaginary part of a complex number. Flows data back & forth.
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.
_cabs
Signature: (complexv(); real [o]b())
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.
log10
Signature: (a(); [o]b())
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.
assgn
Signature: (a(); [o]b())
Plain numerical assignment. This is used to implement the ".=" operator
assgn 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.
carg
Signature: (complexv(); real [o]b())
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.
conj
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.
czip
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.
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.
ipow
Signature: (a(); longlong b(); [o] ans())
raise ndarray $a
to integer power $b
$c = $x->ipow($y); # as method
$c = ipow $x, $y;
$x->inplace->ipow($y); # modify $x inplace
It can be made to work inplace with the $x->inplace
syntax.
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.
abs
Returns the absolute value of a number.
abs2
Signature: (a(); real [o]b())
Returns the square of the absolute value of a number.
abs2 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.
r2C
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.
i2C
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.
AUTHOR
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).