[Numpy-discussion] How can CDOUBLE_to_CDOUBLE work correctly?

Pearu Peterson pearu at cens.ioc.ee
Sun Mar 3 07:10:08 CST 2002


Hi again,

On Sun, 3 Mar 2002, Pearu Peterson wrote:

> So, I would have expected CDOUBLE_to_CDOUBLE to be
> 
> static void CDOUBLE_to_CDOUBLE(double *ip, int ipstep,
>                              double *op, int opstep, int n)
> {  int i; 
>    for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {
>      *op = (double)*ip;           /* copy real part */
>      *(op+1) = (double)*(ip+1);   /* copy imaginary part that always
>                                      follows the real part in memory */
>    }
> }

After some testing I found that CDOUBLE_to_CDOUBLE should be

static void CDOUBLE_to_CDOUBLE(double *ip, int ipstep,
                               double *op, int opstep, int n)
{  int i;
   for(i=0;i<n;i++,ip+=2*ipstep,op+=2*opstep) {
     *op = (double)*ip;           /* copy real part */
     *(op+1) = (double)*(ip+1);   /* copy imaginary part that always
                                     follows the real part in memory */
   }
}

In fact, by redefining CDOUBLE_to_CDOUBLE, CDOUBLE_to_CFLOAT,
CFLOAT_to_CDOUBLE, and CFLOAT_to_CFLOAT functions as above, I get
everything work correctly for copy_ND_array.

So, what it indicates? Is copy_ND_array a hack or is copying Numeric
complex arrays broken? I don't know.
I could not produce any incorrect results when using default Numeric
functions, though. But I did not tried really hard either because I am not
sure if the above makes sense for you.

Regards,
	Pearu





More information about the Numpy-discussion mailing list