Thanks Chris,
Now it makes sense. I expected I would be beyond that mistake,
arrogant me!
Best regards,
Luis


On Tue, Sep 17, 2013 at 09:25:13AM -0400, Chris Marshall wrote:
> On Mon, Sep 16, 2013 at 11:24 PM, Luis Mochan <[email protected]> wrote:
> > I had found problems with PDL::Complex that had to do with
> > confusing between size 2 real arrays and complex
> > numbers. Nevertheless, I don't understand the origin of the problems
> > exemplified by the following lines (via Guillermo Ortiz) and thus, I don't
> > know how to deal with them in more complex codes; I don't know when to
> > expect the correct and when the incorrect result. I ran the lines
> > below through pdl2 (Perldl2 Shell v0.008) with PDL  v2.006, PERL v5.16.1:
> >
> > pdl> use PDL::Complex
> > pdl> $x=i
> > pdl> $y=2*i
> > pdl> $z=$x/$y
> > pdl> p $x**2/$y**2
> >   0.25+0i  (correct)
> > pdl> p ($x/$y)**2
> >   0.5+0i   (incorrect)
> 
> This is correct, since perl reads this as 'print($x/$y)**2' and the
> return value of print is squared but not output.  The rule is if
> it looks like a function, it is a function....  Add a + in front of
> the () to disambiguate.
> 
> > pdl> p $z**2
> >   0.25+0i  (correct)
> > pdl> p ($q=$x/$y)**2
> >   0.5+0i   (incorrect)
> 
> See above.
> 
> > pdl> p ($x/$y)**(2+0*i)
> >   0.5+0i   (incorrect)
> 
> See above.
> 
> > pdl> p Cpow(i,2)
> >   -0.0432139 +5.29218e-18i (incorrect)
> 
> This is correct.  If you look at the signature, Cpow() needs its
> args to have a first dim size 2.  Since 2 is not correct, it get
> threaded over and the result is you are calculating Cpow(i,2+2*i).
> 
> Removing this dim size 2 for the complex element is one
> of the goals of improved type support for PDL.
> 
> > pdl> p Cpow(i,2+0*i)
> >   -1 +1.22465e-16i  (~ correct)
> >
> > Have these problems been already addressed? Is the PDL I'm using too
> > old?
> 
> Just gotchas of the current implementation.  Hope this helps.
> 
> --Chris

-- 

                                                                  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: DD344B85,  2ADC B65A 5499 C2D3 4A3B  93F3 AE20 0F5E DD34 4B85



_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to