PDLA-Core
view release on metacpan or search on metacpan
Basic/Complex/complex.pd view on Meta::CPAN
=item ++, -- (increment, decrement; they affect the real part of the complex number only)
=item "" (stringification)
=back
=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
=head2 re, im
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.
GENERATED/PDLA/Complex.pm view on Meta::CPAN
=item ++, -- (increment, decrement; they affect the real part of the complex number only)
=item "" (stringification)
=back
=cut
my $i;
BEGIN { $i = bless pdl 0,1 }
sub i () { $i->copy };
=head1 FUNCTIONS
GENERATED/PDLA/Complex.pm view on Meta::CPAN
=head2 re, im
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;
=head2 rCpolynomial
GENERATED/PDLA/Complex.pm 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.653 second using v1.01-cache-2.11-cpan-524268b4103 )