The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

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 = plus $x, $y, 0;     # explicit call with trailing 0
   $c = $x + $y;           # overloaded call
   $x->inplace->plus($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 + operator. 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.

plus processes bad values. The state of the bad-value flag of the output ndarrays is unknown.

mult

  Signature: (a(); b(); [o]c(); int swap)

multiply two ndarrays

   $c = mult $x, $y, 0;     # explicit call with trailing 0
   $c = $x * $y;           # overloaded call
   $x->inplace->mult($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 * operator. 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.

mult processes bad values. The state of the bad-value flag of the output ndarrays is unknown.

minus

  Signature: (a(); b(); [o]c(); int swap)

subtract two ndarrays

   $c = minus $x, $y, 0;     # explicit call with trailing 0
   $c = $x - $y;           # overloaded call
   $x->inplace->minus($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 - operator. 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.

minus processes bad values. The state of the bad-value flag of the output ndarrays is unknown.

divide

  Signature: (a(); b(); [o]c(); int swap)

divide two ndarrays

   $c = divide $x, $y, 0;     # explicit call with trailing 0
   $c = $x / $y;           # overloaded call
   $x->inplace->divide($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 / operator. 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.

divide processes bad values. The state of the bad-value flag of the output ndarrays is unknown.

gt

  Signature: (a(); b(); [o]c(); int swap)

the binary > (greater than) operation

   $c = gt $x, $y, 0;     # explicit call with trailing 0
   $c = $x > $y;           # overloaded call
   $x->inplace->gt($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 > operator. 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.

gt processes bad values. The state of the bad-value flag of the output ndarrays is unknown.

lt

  Signature: (a(); b(); [o]c(); int swap)

the binary < (less than) operation

   $c = lt $x, $y, 0;     # explicit call with trailing 0
   $c = $x < $y;           # overloaded call
   $x->inplace->lt($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 < operator. 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.

lt processes bad values. The state of the bad-value flag of the output ndarrays is unknown.

le

  Signature: (a(); b(); [o]c(); int swap)

the binary <= (less equal) operation

   $c = le $x, $y, 0;     # explicit call with trailing 0
   $c = $x <= $y;           # overloaded call
   $x->inplace->le($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 <= operator. 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.

le processes bad values. The state of the bad-value flag of the output ndarrays is unknown.

ge

  Signature: (a(); b(); [o]c(); int swap)

the binary >= (greater equal) operation

   $c = ge $x, $y, 0;     # explicit call with trailing 0
   $c = $x >= $y;           # overloaded call
   $x->inplace->ge($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 >= operator. 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.

ge processes bad values. The state of the bad-value flag of the output ndarrays is unknown.

eq

  Signature: (a(); b(); [o]c(); int swap)

binary equal to operation (==)

   $c = eq $x, $y, 0;     # explicit call with trailing 0
   $c = $x == $y;           # overloaded call
   $x->inplace->eq($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 == operator. 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.

eq processes bad values. The state of the bad-value flag of the output ndarrays is unknown.

ne

  Signature: (a(); b(); [o]c(); int swap)

binary not equal to operation (!=)

   $c = ne $x, $y, 0;     # explicit call with trailing 0
   $c = $x != $y;           # overloaded call
   $x->inplace->ne($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 != operator. 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.

ne processes bad values. The state of the bad-value flag of the output ndarrays is unknown.

shiftleft

  Signature: (a(); b(); [o]c(); int swap)

leftshift $a by $b

   $c = shiftleft $x, $y, 0;     # explicit call with trailing 0
   $c = $x << $y;           # overloaded call
   $x->inplace->shiftleft($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 << operator. 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.

shiftleft processes bad values. The state of the bad-value flag of the output ndarrays is unknown.

shiftright

  Signature: (a(); b(); [o]c(); int swap)

rightshift $a by $b

   $c = shiftright $x, $y, 0;     # explicit call with trailing 0
   $c = $x >> $y;           # overloaded call
   $x->inplace->shiftright($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 >> operator. 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.

shiftright processes bad values. The state of the bad-value flag of the output ndarrays is unknown.

or2

  Signature: (a(); b(); [o]c(); int swap)

binary or of two ndarrays

   $c = or2 $x, $y, 0;     # explicit call with trailing 0
   $c = $x | $y;           # overloaded call
   $x->inplace->or2($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 | operator. 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.

or2 processes bad values. The state of the bad-value flag of the output ndarrays is unknown.

and2

  Signature: (a(); b(); [o]c(); int swap)

binary and of two ndarrays

   $c = and2 $x, $y, 0;     # explicit call with trailing 0
   $c = $x & $y;           # overloaded call
   $x->inplace->and2($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 & operator. 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.

and2 processes bad values. The state of the bad-value flag of the output ndarrays is unknown.

xor

  Signature: (a(); b(); [o]c(); int swap)

binary exclusive or of two ndarrays

   $c = xor $x, $y, 0;     # explicit call with trailing 0
   $c = $x ^ $y;           # overloaded call
   $x->inplace->xor($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 ^ operator. 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.

xor processes bad values. The state of the bad-value flag of the output ndarrays is unknown.

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,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.

atan2

  Signature: (a(); b(); [o]c(); int swap)

elementwise atan2 of two ndarrays

   $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.

modulo

  Signature: (a(); b(); [o]c(); int swap)

elementwise modulo operation

   $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.

spaceship

  Signature: (a(); b(); [o]c(); int swap)

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.

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.

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.

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

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:

 $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.

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(); 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.

abs

Returns the absolute value of a number.

abs2

Returns the square of the absolute value of a number.

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).