1

I am trying to figure out use of arrayfire library and I have written following small code snippet to create a 2D plot like

enter image description here

af::info();
af::Window myWindow(800, 800, "2D Plot example: ArrayFire");    
myWindow.grid(3, 1);

std::vector <double> xyz = { -1, -1, -1, -1, 0, 0, -1,  -2, -2, -2, -1, -1, 1,  3,  4,  5,  4,  2,  -1, -2 };
array A = seq(0, 19);
af_print(A);
array B(xyz.size(), xyz.data());
af_print(B);

myWindow(0, 0).plot(A, B);
myWindow.show();

but I am getting type mismatch input error at run-time.

> ArrayFire Exception (Input types are not the same:205): In function
> af_err __cdecl plotWrapper(void *const ,void *const ,void *const
> ,const af_cell *const ,fg_plot_type,fg_marker_type) In file
> src\api\c\plot.cpp:268 Type mismatch inputs  0# af::allocHost<short>
> in afopencl  1# af::allocHost<short> in afopencl  2#
> af::allocHost<short> in afopencl  3# af_is_real in af  4# af_is_real
> in af  5# main at C:\Users\rad\source\repos\ArrayFire\plot2d.cpp:44 
> 6# invoke_main at
> d:\agent\_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:79
> 7# __scrt_common_main_seh at
> d:\agent\_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
> 8# __scrt_common_main at
> d:\agent\_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:331
> 9# mainCRTStartup at
> d:\agent\_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:17
> 10# BaseThreadInitThunk in KERNEL32 11# RtlUserThreadStart in ntdll
> 
> In function void __cdecl af::Window::plot(const class af::array
> &,const class af::array &,cons

Can someone please help me or point me towards correct tutorial. I am following arrayfire example from here http://arrayfire.org/docs/examples.htm.

Thank you for help in advance.

Random
  • 33
  • 8

1 Answers1

0

There are couple of things that can be improved.

  1. array B is of double precision data while array A is of single precision i.e. floats. The Window::plot() call expects both x and y coordinates to be of same data type. Hence, the error message "Mismatch in types".
  2. The way you have written graphics code right now is not how arrayfire graphics functionality works. The user has to have an event loop, you can quickly find how to write one from our graphics examples.

Please go through our graphics tutorial followed by examples like plot2 on how to write multi-view rendering program.

Since you are exploring arrayfire, I recommend going through the tutorials once before code-using-arrayfire or porting your existing code to arrayfire.

pradeep
  • 712
  • 4
  • 13