0

Basically I have a numpy ufunc that operates on npy_cdouble and npy_cfloat arrays. For instance:

static void
ufunc_H( char ** args
       , npy_intp * dimensions
       , npy_intp * steps
       , void * data)
{

    npy_cdouble * qm_in = (npy_cdouble *) (args[0]);
    npy_cdouble * qm_out = (npy_cdouble *) (args[1]);
    npy_intp i;

    for(i = 0; i < ndim; i++)
    {
        qm_out[i] = (qm_in[i] - qm_in[i ^ ipow(2, argument.act)]) * M_SQRT1_2;
    }


}

This however does not work and the compiler says that qm_in has the type ‘npy_cdouble’ {aka ‘struct <anonymous>’}. How do I treat npy_cdouble correctly?

LittleByBlue
  • 436
  • 9
  • 18

1 Answers1

0

The structures npy_cdouble and npy_cfloat have the members .real and .imag. Those can be used to do operations:

static void
ufunc_H( char ** args
       , npy_intp * dimensions
       , npy_intp * steps
       , void * data)
{

    npy_cdouble * qm_in = (npy_cdouble *) (args[0]);
    npy_cdouble * qm_out = (npy_cdouble *) (args[1]);
    npy_intp i;

    for(i = 0; i < ndim; i++)
    {
        qm_out[i].real = (qm_in[i].real - qm_in[i ^ ipow(2, argument.act)].real) * M_SQRT1_2;
        qm_out[i].imag = (qm_in[i].imag - qm_in[i ^ ipow(2, argument.act)].imag) * M_SQRT1_2;
    }


}
LittleByBlue
  • 436
  • 9
  • 18