0

I would like to create a 2D matrix of complex numbers. The matrix is available as two distinct pointers containing the real and imaginary parts (comes from MATLAB - MEX). I'm using the C++ interface.

The closest thing I see in the API is a C interface, af_cplx2().

// C Interface for creating complex array from two input arrays.
AFAPI af_err af_cplx2   (   af_array *  out,
const af_array  lhs,
const af_array  rhs,
const bool  batch 
)   

The C++ interface gets only one array and creates complex from real array:

// C++ Interface for creating complex array from real array.
AFAPI array af::complex (   const array &   in  )   

How can a complex array be created from two arrays, the real and imaginary part?

miluz
  • 1,353
  • 3
  • 14
  • 22
  • Can you provide more code ? What have you tried ? I don't see the difficulty of creating a complex numbers array from one real and one imaginary part array. – coincoin Jul 07 '15 at 08:37
  • I don't have code since I'm looking for the right interface call to do just that. I'm new to ArrayFire, and I can't find this kind of operation in the docs. If you know how to do it please share your knowledge.. – miluz Jul 07 '15 at 09:38
  • Ok then can you at least precise your context, what kind of codes your are working on ? What are your input and such ? what is AFAPI ? Using [std::complex](http://www.cplusplus.com/reference/complex/complex) would be ok for you ? – coincoin Jul 07 '15 at 10:09
  • I have a 2D matrix of complex numbers as input for MATLAB/MEX. I'd like to perform some calculations on it using arrayfire's FFT, and linear algebra. MATLAB provides complex arrays as two different arrays: real, imag. The way I see that complex array are created, is by providing a pointer to a host array of which the data is interleaved. I'd like to avoid the costly operation of interleaving and see if arrayfire can use two pointers for real and imag parts to create a complex array. – miluz Jul 07 '15 at 10:17
  • std::complex means interleaving the data, this is the costly operation I would like to avoid. – miluz Jul 07 '15 at 10:35

1 Answers1

0

af::complex can be used to create a complex array using two arrays, such that:

af::array c = af::complex(r, i);    // r,i are of af::array

For example, to create a complex array from pointers to real and imaginary parts in a MEX file:

double *p_real = mxGetPr(mex_array);
double *p_imag = mxGetPi(mex_array);

af::array c = af::complex(af::array(rows,cols,p_real),
                          af::array(rows,cols,p_imag));
miluz
  • 1,353
  • 3
  • 14
  • 22