PDLA

 view release on metacpan or  search on metacpan

Basic/Complex/complex.pd  view on Meta::CPAN

     |                                         #             #             |
     |                                          ##         ##              |
     +      +      +      +      +      +      +  ### + ###  +      +      +
 -15 ++-----+------+------+------+------+------+-----###-----+------+-----++
     0      5      10     15     20     25     30     35     40     45     50

=cut

my $i;
BEGIN { $i = bless pdl 0,1 }
sub i () { $i->copy };
EOD

for (qw(Ctan Catan re im i cplx real)) {
   pp_add_exported '', $_;
}

pp_addhdr <<'EOH';

#include <math.h>

Basic/Complex/complex.pd  view on Meta::CPAN

pp_addpm <<'EOD';

=head2 re cplx, im cplx

Return the real or imaginary part of the complex number(s) given. These
are slicing operators, so data flow works. The real and imaginary parts
are returned as piddles (ref eq PDLA).

=cut

sub re($) { bless $_[0]->slice("(0)"), 'PDLA'; }
sub im($) { bless $_[0]->slice("(1)"), 'PDLA'; }

*PDLA::Complex::re = \&re;
*PDLA::Complex::im = \&im;

EOD

pp_def 'rCpolynomial',
       Pars => 'coeffs(n); x(c=2,m); [o]out(c=2,m)',
       Doc => 'evaluate the polynomial with (real) coefficients C<coeffs> at the (complex) position(s) C<x>. C<coeffs[0]> is the constant term.',
       GenericTypes => [F,D],

Basic/Complex/complex.pd  view on Meta::CPAN

        my $warningFlag;
        # This strange usage of BEGINs is to ensure the
        # warning messages get disabled and enabled in the
        # proper order. Without the BEGIN's the 'use overload'
        #  would be called first.
        BEGIN {$warningFlag = $^W; # Temporarily disable warnings caused by
               $^W = 0;            # redefining PDLA's subs
              }


sub cp(;@) {
	my $foo;
	if (ref $_[1]
		&& (ref $_[1] ne 'PDLA')
		&& defined ($foo = overload::Method($_[1],'+')))
		{ &$foo($_[1], $_[0], !$_[2])}
	else { PDLA::plus (@_)}
}

sub cm(;@) {
	my $foo;
	if (ref $_[1]
		&& (ref $_[1] ne 'PDLA')
		&& defined ($foo = overload::Method($_[1],'*')))
		{ &$foo($_[1], $_[0], !$_[2])}
	else { PDLA::mult (@_)}
}

sub cmi(;@) {
	my $foo;
	if (ref $_[1]
		&& (ref $_[1] ne 'PDLA')
		&& defined ($foo = overload::Method($_[1],'-')))
		{ &$foo($_[1], $_[0], !$_[2])}
	else { PDLA::minus (@_)}
}

sub cd(;@) {
	my $foo;
	if (ref $_[1]
		&& (ref $_[1] ne 'PDLA')
		&& defined ($foo = overload::Method($_[1],'/')))
		{ &$foo($_[1], $_[0], !$_[2])}
	else { PDLA::divide (@_)}
}


  # Used in overriding standard PDLA +, -, *, / ops in the complex subclass.



( run in 1.444 second using v1.01-cache-2.11-cpan-524268b4103 )