ArrayFire uses cuComplex(cfloat in ArrayFire 2.0RC) to store complex numbers. cuComplex is defined as a float2 internally which is a struct with two elements.
std::complex should have the same structure. You might be able to perform a reinterpret_cast to change the type of the variable without moving the data to a different data structure. On my machine(Linux Mint with g++ 4.7.1) I was able to create an ArrayFire array from a std::complex using the following code:
int count = 10;
std::complex<float> host_complex[count];
for(int i = 0; i < count; i++) {
std::real(host_complex[i]) = i;
std::imag(host_complex[i]) = i*2;
}
array af_complex(count, reinterpret_cast<cuComplex*>(host_complex));
print(af_complex);
Output:
af_complex =
0.0000 + 0.0000i
1.0000 + 2.0000i
2.0000 + 4.0000i
3.0000 + 6.0000i
4.0000 + 8.0000i
5.0000 + 10.0000i
6.0000 + 12.0000i
7.0000 + 14.0000i
8.0000 + 16.0000i
9.0000 + 18.0000i
Caveat
As far as I can tell the C++ standard does not specify the size or data layout of the std::complex type therefore this approach might not be portable. If you want a portable solution, I would suggest storing your complex data in a struct like a float2/cfloat to avoid compiler related issues.
Umar