I made a few changes to PDL::Basic::Complex.pd so that sum, prod,
Csumover and prodover work with PDL::Complex types, and I made the
corresponding changes to my earlier proposed tests at
t/complex.t. They seem to work. I attach the corresponding patch from
git diff.
Best regards,
Luis
On Tue, Dec 11, 2018 at 10:32:24AM -0700, Derek Lamb wrote:
> Excellent, thank you! No test failures on my machine. I've committed and
> pushed that patch to the complex_atan2 branch. I will look at it more
> carefully later today.
>
> Derek
>
> > On Dec 10, 2018, at 6:30 PM, Luis Mochan <[email protected]> wrote:
> >
> > I added some more tests for PDL::Complex.
> > I attach a patch from git diff.
> > I tested them running
> >
> > prove -v -b t/complex.t
> >
> > on the complex_atan2 git branch. I protected the tests that failed
> > with TODO and SKIP blocks.
> >
> > Best regards,
> > Luis
> >
> >
> > On Sun, Dec 09, 2018 at 10:16:42PM -0600, Luis Mochan wrote:
> >> I assembled a few tests to exercise some aspects of PDL::Complex...
> >
> >
> > --
> >
> > 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
> >
> >
> > <rem.patch>_______________________________________________
> > 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
diff --git a/Basic/Complex/complex.pd b/Basic/Complex/complex.pd
index 59124a76..19ec5104 100644
--- a/Basic/Complex/complex.pd
+++ b/Basic/Complex/complex.pd
@@ -37,7 +37,7 @@ PDL::Complex - handle complex numbers
This module features a growing number of functions manipulating complex
numbers. These are usually represented as a pair C<[ real imag ]> or
-C<[ angle phase ]>. If not explicitly mentioned, the functions can work
+C<[ magnitude phase ]>. If not explicitly mentioned, the functions can work
inplace (not yet implemented!!!) and require rectangular form.
While there is a procedural interface available (C<< $x/$y*$c <=> Cmul
@@ -1153,17 +1153,30 @@ sub cd(;@) {
}
- sub sum {
- my($x) = @_;
- my $tmp = $x->mv(0,1)->clump(0,2)->mv(1,0)->sumover;
- return $tmp->squeeze;
- }
+ sub sum {
+ my($x) = @_;
+ return $x if $x->dims==1;
+ my $tmp = $x->mv(0,-1)->clump(-2)->mv(1,0)->sumover;
+ return $tmp;
+ }
sub sumover{
my $m = shift;
PDL::Ufunc::sumover($m->xchg(0,1));
}
+ *PDL::Complex::Csumover=\&sumover; # define through alias
+
+ *PDL::Complex::prodover=\&Cprodover; # define through alias
+
+ sub prod {
+ my($x) = @_;
+ return $x if $x->dims==1;
+ my $tmp = $x->mv(0,-1)->clump(-2)->mv(1,0)->prodover;
+ return $tmp;
+ }
+
+
sub strND {
my($self,$format1,$format2,$level)=@_;
diff --git a/t/complex.t b/t/complex.t
index cbe58073..21a7f458 100644
--- a/t/complex.t
+++ b/t/complex.t
@@ -207,11 +207,7 @@ ok(tapprox(rCpolynomial(pdl(1,2,3), $x),
$y = $x->copy + 1;
my $bigArray = $x->cat($y);
ok(abs($bigArray->sumover->sumover + 8 - 4*i) < .0001, 'check cat for PDL::Complex');
- SKIP: {
- # This test passed, but by chance
- skip "sum only works on 2D complex arrays, i.e. 3D piddles", 1;
- ok(abs($bigArray->sum() + 8 - 4*i) < .0001, 'check cat for PDL::Complex');
-}
+ok(abs($bigArray->sum() + 8 - 4*i) < .0001, 'check cat for PDL::Complex');
my $z = pdl(0) + i*pdl(0);
$z **= 2;
@@ -237,19 +233,16 @@ ok($r->at(0) < 100.000000001 && $r->at(0) > 99.999999999 && $r->at(1) == 0,
#Check Csumover sumover, Cprodover and prodover
$x=sequence(2,3)+1;
$y=$x->copy->complex;
- SKIP: {
- skip "Csumover is not defined", 3;
- ok(ref $y->Csumover eq 'PDL::Complex', 'Type of Csumover');
- is($y->Csumover->dim(0), 2, 'Dimension 0 of Csumover');
- ok(tapprox($y->Csumover->real, $x->mv(1,0)->sumover),
- 'Csumover value');
-}
+ok(ref $y->Csumover eq 'PDL::Complex', 'Type of Csumover');
+is($y->Csumover->dim(0), 2, 'Dimension 0 of Csumover');
+ok(tapprox($y->Csumover->real, $x->mv(1,0)->sumover),
+ 'Csumover value');
ok(ref $y->sumover eq 'PDL::Complex', 'Type of sumover');
is($y->sumover->dim(0), 2, 'Dimension 0 of sumover');
ok(tapprox($y->sumover->real, $x->mv(1,0)->sumover), 'sumover value');
+ok(ref sumover($y) eq 'PDL::Complex', 'Type of sumover');
TODO: {
local $TODO="sumover as method and as function differ";
- ok(ref sumover($y) eq 'PDL::Complex', 'Type of sumover');
is(sumover($y)->dim(0), 2, 'Dimension 0 of sumover');
SKIP: {
todo_skip "sumover as function is real sumover", 1;
@@ -264,46 +257,28 @@ ok(tapprox($y->Cprodover->real,
($y->slice(':,(0)')*$y->slice(':,(1)')*$y->slice(':,(2)'))->real),
'Value of Cprodover');
ok(ref $y->prodover eq 'PDL::Complex', 'Type of prodover');
- TODO: {
- local $TODO="prodover of complex multiplies over dimension 0, not 1";
is($y->prodover->dim(0), 2, 'Dimension 0 of prodover');
- SKIP: {
- todo_skip "prodover of complex multiplies over dimension 0, not 1",
- 1 if $y->prodover->dim(0) != 2;
- ok(tapprox($y->prodover->real, $x->mv(1,0)->prodover),
- 'Value of prodover');
- }
-}
+ok(tapprox($y->prodover->real,
+ ($y->slice(':,(0)')*$y->slice(':,(1)')*$y->slice(':,(2)'))->real),
+ 'Value of prodover');
#Check sum
- TODO: {
- local $TODO="Complex sum works miraculously only for 2,n,m PDL's";
- SKIP: {
- todo_skip "Complex sum for 2,n Complex PDL's doesn't work", 4;
- $x=sequence(2,3)+1;
- $y=$x->copy->complex;
- ok(ref $y->sum eq 'PDL::Complex', 'Type of sum');
- is($y->sum->dims, 1, 'Dimensions of sum');
- is($y->sum->dim(0), 2, 'Dimension 0 of sum');
- ok(tapprox($y->sum->real, $x->mv(1,0)->sumover), 'Value of sum');
- }
-}
+$x=sequence(2,3)+1;
+$y=$x->copy->complex;
+ok(ref $y->sum eq 'PDL::Complex', 'Type of sum');
+is($y->sum->dims, 1, 'Dimensions of sum');
+is($y->sum->dim(0), 2, 'Dimension 0 of sum');
+ok(tapprox($y->sum->real, $x->mv(1,0)->sumover), 'Value of sum');
#Check prod
- TODO: {
- local $TODO="Complex prod doesn't work at all";
- SKIP: {
- todo_skip "Complex prod doesn't work", 4;
- $x=sequence(2,3)+1;
- $y=$x->copy->complex;
- ok(ref $y->prod eq 'PDL::Complex', 'Type of prod');
- is($y->prod->dims, 1, 'Dimensions of prod');
- is($y->prod->dim(0), 2, 'Dimension 0 of prod');
- ok(tapprox($y->prod->real, $y->prodover->real),
- 'Value of prod');
- }
-}
+$x=sequence(2,3)+1;
+$y=$x->copy->complex;
+ok(ref $y->prod eq 'PDL::Complex', 'Type of prod');
+is($y->prod->dims, 1, 'Dimensions of prod');
+is($y->prod->dim(0), 2, 'Dimension 0 of prod');
+ok(tapprox($y->prod->real, $y->prodover->real),
+ 'Value of prod');
TODO: {
_______________________________________________
pdl-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-general