PDL-Complex

 view release on metacpan or  search on metacpan

GENERATED/PDL/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 ndarrays (ref eq PDL).

=cut

sub re($) { $_[0]->slice("(0)") }
sub im($) { $_[0]->slice("(1)") }

{
no warnings 'redefine';
# if the argument does anything other than pass through 0-th dim, re-bless
sub slice :lvalue {
  my $first = ref $_[1] ? $_[1][0] : (split ',', $_[1])[0];
  my $class = ($first//'') =~ /^[:x]?$/i ? ref($_[0]) : 'PDL';
  my $ret = bless $_[0]->SUPER::slice(@_[1..$#_]), $class;
  $ret;
}

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 ndarrays (ref eq PDL).

=cut

sub re($) { $_[0]->slice("(0)") }
sub im($) { $_[0]->slice("(1)") }

{
no warnings 'redefine';
# if the argument does anything other than pass through 0-th dim, re-bless
sub slice :lvalue {
  my $first = ref $_[1] ? $_[1][0] : (split ',', $_[1])[0];
  my $class = ($first//'') =~ /^[:x]?$/i ? ref($_[0]) : 'PDL';
  my $ret = bless $_[0]->SUPER::slice(@_[1..$#_]), $class;
  $ret;
}



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