Hi Ed,

very nice! See comments inline.

On 26.03.21 06:40, Ed . wrote:

I’m currently working on making creal and cimag return real data
rather than complex, which I’m doing by implementing a “real” type
qualifier (in PP terminology), so:

              Pars => “a(); real [o] b()”

How do you do that? I tried to implement this and failed because I
didn't know where to start. ;)

This is also necessary to implement irfftn() in PDL::FFTW3 with native
complex data, because the library itself takes complex data and
returns real, and currently PDL makes all data parameters be the same
unless a type-qualifier is given, and I didn’t want to have to make
separate cfloat and cdouble versions.

I think that comparisons (including sorting) of complex data other
than an equality test (and approx) should simply throw an exception,
as they aren’t mathematically valid at all. I also think that the
equivalent should be done in PDL::Complex, despite it not currently
being an error. What do others think?

Iagree for the new native support, but I think PDL::Complex behaviour
should be preserved since it is around for a long time. But then it
might even improve old code by highlighting dubious behaviour. ;)

In a similar vein: is it really useful to call creal/cimag on real
data? It seems to me that too should throw an exception.

I think it should just return the input and 0, respectively. Thus it can
be used to write generic code that accepts real and complex input. carg
should do the same. Even conj kind of works that way.

Best regards,

Ed

*From: *Luis Mochan <mailto:moc...@icf.unam.mx>
*Sent: *26 March 2021 05:30
*To: *pdl-devel@lists.sourceforge.net
<mailto:pdl-devel@lists.sourceforge.net>
*Subject: *Re: [Pdl-devel] [Pdl-general] PDL 2.029 released

I started playing with the new complex numbers. I find it nice
and useful that creal and cimag can be applied to real pdl's, but the
results are promoted to complex:

pdl> $x=pdl(1)
pdl> p $x
1
pdl> p $x->creal
1+0i
pdl> p $x->cimag
0+0i

Equality and inequality comparisons do work but they also return
complex values:

pdl> p $x==1
1
pdl> p $x->creal==1
1+0i
pdl> p $x->creal==2
0+0i
pdl> p $x->creal!=2
1+0i

This is troublesome, as their boolean interpretation is not correct:

pdl> print +($x->creal==1)?'yes':'no'
yes
pdl> print +($x->creal==2)?'yes':'no'
yes
pdl> print +($x==2)?'yes':'no'
no

On the other hand, greater than, lower than, etc. do compare the real
parts only and return a real value.

pdl> $y=ci
pdl> p $y<1
1
pdl> p $y<ci
0
pdl> p $y<=0.01*ci
1



_______________________________________________
pdl-devel mailing list
pdl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pdl-devel
_______________________________________________
pdl-devel mailing list
pdl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pdl-devel

Reply via email to