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 _______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
