I know that the overloaded operators in PDL::Complex have logic to ensure that 
the type is always PDL::Complex before internally calling Cadd.  I'm not sure 
how PDL::PP handles the case where one argument is subclassed, or if it does at 
all.

This is probably worth a formal bug report, though.

Derek

> On Dec 10, 2018, at 1:33 PM, Luis Mochan <[email protected]> wrote:
> 
> I'm curious about the pp_def routines such as Cadd in Basic/complex.pd:
> 
> 1  pdl> use PDL::Complex;
> 2  pdl> $x=1+2*i; # a complex number
> 3  pdl> $y=3+4*i; # another one
> 4  pdl> $z=pdl(5,6); # a 2-piddle
> 5  pdl> p Cadd($x, $y); # result is complex
> 6  4 +6i 
> 7  pdl> p Cadd($x, $z) # result is also complex
> 8  6 +8i
> 9  pdl> p Cadd($z, $x); # result is a 2-piddle
> 10 [6 8]
> 11 pdl> p $x+$y; # result is complex 
> 12 4 +6i
> 13 pdl> p $x+$z; # results are 2 complex numbers
> 14 [6 +2i  7 +2i]
> 15 pdl> p $z+$x; # results are 2 complex numbers
> 16 [6 +2i  7 +2i] 
> 
> I wonder where in the code does Cadd decide that the result is a
> PDL::Complex. Is it because the first argument is a PDL::Complex in
> lines 4 and 7. Would this work for other classes that might descend
> from PDL. 
> 
> Does the output of pp_def routines inherit their type from their first
> argument?
> 
> On the other hand, I understand the logic of lines 9-10,
> where the two arguments are interpreted as the real and imaginary
> parts of a complex number. I also understand the logic of lines 13-16,
> where the 2-pdl is treated as an array of two real numbers each of
> which is added to a complex number to yield an array of two complex
> numbers. However the differences between the behaviour of the
> subroutine call Cadd and that of the overloaded operator '+' might
> surprise some users. 
> 
> -- 
> 
>                                                                  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
> 
> 
> 
> 
> _______________________________________________
> pdl-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pdl-general
> 



_______________________________________________
pdl-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-general

Reply via email to