I found that for 2D complex arrays $complex->sum does work, but it
doesn't work for 1D complex arrays (it gives an error) and it gives the wrong
result for 3D and higher dimensional complex arrays. I guess the error
lies in the file Basic/Complex/complex.pd, in the definition of sum
sub sum {
my($x) = @_;
my $tmp = $x->mv(0,1)->clump(0,2)->mv(1,0)->sumover;
return $tmp->squeeze;
}
In the third line
my $tmp = $x->mv(0,1)->clump(0,2)->mv(1,0)->sumover;
it is explicitly assumed that $x is a 2D complex array.
I guess the problem may be solved changing that line to
my $tmp = $x->real->mv(0,-1)->clump(-2)->sumover->complex;
where the real-imaginary index is protected by sending it to the last
position and clumping all previous indices. Is this solution reasonable?
I attach the corresponding patch.
Best regards,
Luis
a
On Thu, Feb 09, 2017 at 10:03:34AM -0600, Luis Mochan wrote:
> I believe that sum doesn't work on complex pdl's. Example:
>
> pdl> $a=sequence(5)+10*i*sequence(5)
> pdl> p $a->sum
> dimension index 2 larger than greatest dimension at
> /home/mochan/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux/PDL/Core.pm
> line 1642.
> PDL::clump(PDL::Complex=SCALAR(0x5605e2c93ab0), 0, 2) called at
> /home/mochan/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux/PDL/Complex.pm
> line 1347
> PDL::Complex::sum(PDL::Complex=SCALAR(0x5605e4724408)) called at (eval
> 947) line 4
> main::__ANON__() called at
> /home/mochan/perl5/perlbrew/perls/perl-5.24.0/bin/perldl line 719
> eval {...} called at
> /home/mochan/perl5/perlbrew/perls/perl-5.24.0/bin/perldl line 719
> main::eval_and_report("p \$a->sum\x{a}") called at
> /home/mochan/perl5/perlbrew/perls/perl-5.24.0/bin/perldl line 655
> main::process_input() called at
> /home/mochan/perl5/perlbrew/perls/perl-5.24.0/bin/perldl line 675
> eval {...} called at
> /home/mochan/perl5/perlbrew/perls/perl-5.24.0/bin/perldl line 675
> It seems sumover does work correctly.
>
> Best regards,
> Luis
>
> --
>
> o
> W. Luis Mochán, | tel:(52)(777)329-1734 /<(*)
> Instituto de Ciencias Físicas, UNAM | fax:(52)(777)317-5388 `>/ /\
> Apdo. Postal 48-3, 62251 | (*)/\/ \
> Cuernavaca, Morelos, México | [email protected] /\_/\__/
> GPG: 791EB9EB, C949 3F81 6D9B 1191 9A16 C2DF 5F0A C52B 791E B9EB
>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> pdl-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pdl-general
>
--
o
W. Luis Mochán, | tel:(52)(777)329-1734 /<(*)
Instituto de Ciencias Físicas, UNAM | fax:(52)(777)317-5388 `>/ /\
Apdo. Postal 48-3, 62251 | (*)/\/ \
Cuernavaca, Morelos, México | [email protected] /\_/\__/
GPG: 791EB9EB, C949 3F81 6D9B 1191 9A16 C2DF 5F0A C52B 791E B9EB
--- complex.pd 2015-08-11 20:44:19.000000000 -0500
+++ newcomplex.pd 2017-02-10 12:41:26.078924322 -0600
@@ -1047,7 +1047,7 @@
sub sum {
my($x) = @_;
- my $tmp = $x->mv(0,1)->clump(0,2)->mv(1,0)->sumover;
+ my $tmp = $x->real->mv(0,-1)->clump(-2)->sumover->complex;
return $tmp->squeeze;
}
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
pdl-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-general