PDL::Complex was never fully implemented, in the sense of overloading
all the basic operators. Hence many operations will "fall through" to
the PDL implementation that is under the hood. PDL::Complex places
the (real,imaginary) component in the 0 dimension, which is why your
3x3 PDL::Complex object turns out to be a 2x3x3 PDL under the hood.
To be fair, there is no non-surprising way to implement the "at"
method for PDL::Complex objects, because PDL::at returns a Perl scalar
and Perl doesn't implement a complex scalar type.
You will find that the more familiar slicing operators don't work
quite right either:
perldl> print $cz->((0),(0))
[0 0 0]
I don't think there is strong enough interest in PDL::Complex among
the current developers that it is likely to get fixed soon. Your best
options are:
(1) become a developer (not that hard) and add more overlain
operators to PDL::Complex;
(2) use the existing PDL::Complex, which mainly handles basic
operations like multiplication and printing, and expect that you'll
see the underlying structure a fair amount;
(3) Just use regular PDLs and treat the complex operations explicitly.
I think PDL::Complex is likely to be pulled out of the main
distribution at the next major release (which will be the main
development goal once we get the long-delayed 2.4.4 minor point
release out the door). It will then become a separate CPAN module.
Cheers,
Craig
On Sep 19, 2008, at 5:17 AM, Hugh Sasse wrote:
> I'm using Perldl 2.4.3 under cygwin.
>
> perldl> $z = zeroes(3,3)
>
> perldl> $cz = &PDL::Complex::r2C($z);
>
> perldl> print $cz
>
> [
> [0+0i 0+0i 0+0i]
> [0+0i 0+0i 0+0i]
> [0+0i 0+0i 0+0i]
> ]
>
> Fair enough, a 3 by 3 array of complex. Well, maybe.
> perldl> print ref($cz)
> PDL::Complex
>
> So it knows it holds complex numbers.
>
> perldl> print $cz->at(1,1)
> Invalid position at /usr/lib/perl5/site_perl/5.10/i686-cygwin/PDL
> /Core.pm line 2377.
>
> So what does it think the dimensions are?
>
> perldl> print $cz->dims()
> 2 3 3
> perldl>
>
> Now, complex numbers are supposed to interact correctly with "normal"
> reals, but I can't access elements of arrays of Complex and arrays
> of reals in the same way in the code, so I need two paths through my
> code.
>
> Is there something like this (rough sketch) already?:
>
> package PDL::Complex;
>
> sub at {
> my $self = shift;
> my $x = shift;
> my $y = shift;
>
> return &PDL::at($self,0,$x,$y) + &PDL::at($self,1,$x,$y) * i;
> }
>
> Is there a reason I would not want to add that to my code, if not?
> Alternatively, why is my expectation on this wrong? What should I
> be looking for, to pluck a complex value from a 2D array of numbers,
> in a complx/real agnostic way?
>
> Thank you,
> Hugh
>
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl