3

I would like to create the imaginary unit in ArrayFire, but I can't. I can construct a complex matrix from a real matrix, but that will not be pure imaginary. Perhaps I can use function af_cplx2 from this page. I thought of the following:

af_array *R;
const af_array re = 0.0;
const af_array im = 1.0;
af_cplx2(R,re,im,0);

However I get a runtime error (unhandled exception) in Visual Studio 2013. How can I do it? Thank you in advance.

Zoltán Csáti
  • 679
  • 5
  • 17

3 Answers3

5

Here's how you would do it using the C and C++ APIs. You can find the APIs here: http://www.arrayfire.com/docs/group__data__func__constant.htm

// Using C++ API
cfloat h_unit = {0, 1}  // Host side
af::array unit = af::constant(h_unit, 1, c32); // Creates an array of size 1 containing all {0, 1} on device side.

// Using C API
af_array af_unit = 0;
dim_type dims{} = {1};
dim_type ndims = 1;
af_constant_complex(&af_unit, 0, 1, ndims, dims, c32};

This an answer expands on the answer by Christopher Columbus.

shehzan
  • 331
  • 1
  • 5
2

cdouble, creates an object of class std::complex, its use does not create an actual ArrayFire object. To create an ArrayFire object with datatype "c64", use this,

cdouble i_cdouble = { 0, 1 }; 
array i = constant(i_cdouble,1,1, c64);/* imaginary unit */
printf("\n Creating an imaginary unit, since there is no ArrayFire inbuilt constant.");
af_print(i); 
Syed Alam Abbas
  • 521
  • 6
  • 21
  • Thanks. Has the variable`i` the same type as `unit` given by shehzan in the first answer? – Zoltán Csáti Jun 01 '15 at 06:24
  • The only difference is in precision, array unit is declared c32 (complex 32 bit), and variable i is declared c64 (complex 64). When using array object especially for further processing it is best to remain uniform. – Syed Alam Abbas Jun 03 '15 at 05:39
1

After a few hours of hard work, here is the solution:

cdouble i = { 0, 1 }; /* imaginary unit */
Zoltán Csáti
  • 679
  • 5
  • 17