相关文章推荐
深沉的台灯  ·  验证 DataGridView ...·  9 月前    · 
深沉的台灯  ·  照亮\ 数据库\ ...·  9 月前    · 
深沉的台灯  ·  bash - Command that ...·  11 月前    · 
严肃的皮蛋  ·  Retrieve Original ...·  18 小时前    · 
严肃的围巾  ·  C++内部函数与外部函数 | ...·  18 小时前    · 
性感的绿豆  ·  SQL ...·  18 小时前    · 
完美的充值卡  ·  A Basic AWS Lambda ...·  18 小时前    · 
28 : 48 : warning: incompatible integer to pointer conversion passing ' __global int' to parameter of type ' __private int *' [-Wint-conversion] array_dist[i] = Euclidean_distance(X_train[i],data_point[j]); ^~~~~~~~~~
my code:
inline float Euclidean_distance( int * array_point_A, int * array_point_B) { float sum = 0 . 0 ; float w[20] = { 0 . 0847282 , 0 . 0408621 , 0 . 105036 , 0 . 0619821 , 0 . 0595455 , 0 . 0416739 , 0 . 0181147 , 0 . 00592921 , 0 . 040049 , 0 . 0766054 , 0 . 0441091 , 0 . 0376111 , 0 . 0124285 , 0 . 0733558 , 0 . 0587338 , 0 . 0303001 , 0 . 0579207 , 0 . 0449221 , 0 . 0530462 , 0 . 0530462 }; for ( int i = 0 ; i < 20 ; ++i) { float a = array_point_A[i] - array_point_B[i]; float wieghted_distance = w[i] * (a * a); sum += wieghted_distance; return sqrt(sum); __kernel void KNN_classifier(__global int * restrict X_train, __global int * restrict Y_train, __global int * restrict data_point, int k) float array_dist[4344] = {}; int index_arr[4344] = {}; for ( int i = 0 ; i < 4344 ; ++i) { for ( int j = 0 ; j < 20 ; ++j) { array_dist[i] = Euclidean_distance(X_train[i], data_point[j]); index_arr[i] = i; What I have tried:
I tried several solution but no improvement __kernel void KNN_classifier(__global int * restrict X_train, __global int * restrict Y_train, __global int * restrict data_point, int k)
The method you are calling expects an int * :
inline float Euclidean_distance( int * array_point_A, int * array_point_B)
array_dist[i] = Euclidean_distance(X_train[i], data_point[j]);When you select an element from an array with an index, you get the item, not a pointer to the item.
So if you pass in a pointer to an integer and then select an element from that, you get an integer, not a pointer to an integer (remember, the name of an array is a pointer to the first element of that array - so a pointer to a value is also an array of those values).
Either use the address of operator '&' or pass the whole array when you call the second method. inline float Euclidean_distance( int * array_point_A, int * array_point_B) { // both parameters are pointers to arrays
And now the call:
array_dist[i] = Euclidean_distance(X_train[i], data_point[j]); // but you are trying to pass single integers
Change the call to:
array_dist[i] = Euclidean_distance(X_train, data_point);
However, looking at the implementation of your code that is still going to cause problems, since the Euclidean_distance code iterates through 20 elements of each array, but you are calling it for each of the 20 elements of the data_point array.
I think you need to consider very carefully what you are trying to do with this code.
  • Read the question carefully.
  • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.
  •  
    推荐文章