## #339 PDL::Complex support is inconsistent and incomplete

normal
open-remind
nobody
None
3
2015-08-16
2013-08-31
No

This is from a posting by Luis Mochon on the perldl mailing list
at http://mailman.jach.hawaii.edu/pipermail/perldl/2013-August/008103.html
on some issues with the current PDL::Complex implementation and excerpted
here:

I found an strange behavior in PDL::Complex.
(I'm running PDL v2.006 under perl5 (revision 5 version 16 subversion 1))

To illustrate this behavior, I declare a 1D complex array from a 2D real pdl:

``` pdl> \$a=sequence(2,3)->cplx
pdl> p \$a
[0 +1i  2 +3i  4 +5i]

# Pdl allows me to transpose the array, as if it were an ordinary 2x3 pdl:
pdl> p \$a->transpose
[
[0 2 4]
[1 3 5]
]
# but it doesn't realize that after transposition it is no longer a 1D
# complex array

pdl> p \$a->transpose->info
PDL::Complex: Double D [3,2]
```

## Discussion

• W_Luis - 2014-09-01

Another inconsistent and sometimes wrong behavior:

```pdl> \$a=sequence(3)+i*2*sequence(3)
pdl> p \$a #three complex numbers
[0 +0i  1 +2i  2 +4i]
pdl> p \$a->sumover #complex sums over index 1, not 0
3 +6i
pdl> p \$a->prodover #real product over index 0, not 1
[0 2 8]
pdl> p \$a->prodover->info
PDL::Complex: Double D [3] #Complex number with three components!
```

sumover yields an expected result, i.e., the complex sum of three complex
numbers, but prodover sums over index 0, i.e., multiplies real times
imaginary parts, yielding three real numbers, which are nevertheless
interpreted as a complex number!

• W_Luis - 2014-09-01

I just noticed there is a Cprodover function in PDL::Complex that does
what I expected prodover would do. Maybe they should be synonyms when
acting on a complex type. I also noticed that the code for sum works
only on 2D complex arrays (i.e., 3D piddles), not for the general n-D
case.

• Chris Marshall - 2015-02-22

Not planned to address for PDL-2.008

• Chris Marshall - 2015-02-22
• Priority: 5 --> 3

• Chris Marshall - 2015-08-16
• Group: critical --> normal