host pointer to complex array?

63 views
Skip to first unread message

Joe Georger

unread,
Jul 26, 2017, 10:21:05 AM7/26/17
to ArrayFire Users
For debugging purposes I'm trying to bring a complex array back to the host:

        std::complex<float> *h_E = E.host<std::complex<float> >();
        std::cout << h_E[0] << std::endl;
        delete [] h_E;

and I'm getting the following error:

Undefined symbols for architecture x86_64:
  "std::__1::complex<float>* af::array::host<std::__1::complex<float> >() const", referenced from:
      _main in test_kron.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm using 
ArrayFire v3.5.0 (CPU, 64-bit Mac OSX, build 05999f3)
[0] Intel: Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz, 16384 MB, Max threads(8).

Anyone encounter this?  I've tried with just float and it works fine....

Umar Arshad

unread,
Jul 26, 2017, 10:55:11 AM7/26/17
to ArrayFire Users
Hey Joe,

ArrayFire does not have a host function that converts directly to std::complex. You probably can do something like this:

vector<std::complex<float>> Edata(E.elements);
E.host(Edata.data());
...

Pavan Yalamanchili

unread,
Jul 26, 2017, 12:55:01 PM7/26/17
to Umar Arshad, ArrayFire Users
ArrayFire also implements a custom complex data type. This was done so arrayfire will not depend on the STL implementation which will cause incompatibilities between compiler versions.

If you wanted, you can use af::cfloat instead of std::complex<float>.

--
You received this message because you are subscribed to the Google Groups "ArrayFire Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to arrayfire-use...@googlegroups.com.
To post to this group, send email to arrayfi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/arrayfire-users/5afabe80-10a2-44fe-b177-d1c67f619616%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

Pradeep Garigipati

unread,
Jul 7, 2021, 12:41:36 AMJul 7
to John Doe, ArrayFire Users
That is unexpected, here is a full blown standalone example code (followed by the sample output) that works fine.

#include <arrayfire.h>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <iostream>
#include <vector>

using namespace af;

int main(int argc, char* argv[]) {
    try {
        int device = argc > 1 ? atoi(argv[1]) : 0;
        af::setDevice(device);
        af::info();

        array A = randu(5, 3, c32);
        af_print(A);

        std::vector< std::complex<float> > hostca(A.elements());
        A.host(hostca.data());

        std::ostream_iterator< std::complex<float> > out_it(std::cout,", ");
        std::copy(hostca.begin(), hostca.end(), out_it);
    } catch (af::exception& e) {
        fprintf(stderr, "%s\n", e.what());
        throw;
    }

    return 0;
}


./build/ninja-cpu-mkl-debug/examples/helloworld/helloworld_cpu
ArrayFire v3.9.0 (CPU, 64-bit Linux, build 293601beb)
[0] AMD: AMD A10-7850K Radeon R7, 12 Compute Cores 4C+8GA
[5 3 1 1]
   Offset: 0
   Strides: [1 5 15 15]
(0.6010,0.0278) (0.1583,0.3712) (0.6755,0.6105)
(0.9806,0.2126) (0.3543,0.6450) (0.5232,0.5567)
(0.0655,0.5497) (0.9675,0.3636) (0.7896,0.8966)
(0.2864,0.3410) (0.4165,0.5814) (0.0536,0.5775)
(0.7509,0.4105) (0.8962,0.3712) (0.2908,0.9941)

(0.601,0.02776), (0.9806,0.2126), (0.06546,0.5497), (0.2864,0.341), (0.7509,0.4105), (0.1583,0.3712), (0.3543,0.645), (0.9675,0.3636), (0.4165,0.5814), (0.8962,0.3712), (0.6755,0.6105), (0.5232,0.5567), (0.7896,0.8966), (0.05364,0.5775), (0.2908,0.9941)





On Fri, Jun 25, 2021 at 1:01 PM John Doe <asut...@gmail.com> wrote:
The example from Umar doesn't work.

Could you provide a working compilable example please?

Thanks!


--
Reply all
Reply to author
Forward
0 new messages