__kernel void weighted_euclidean(
  __global numeric* output,
  const unsigned int count,
  __global const numeric* input,
  __global const numeric* weights,
  const int N,
  const int DIM) {

  size_t i = get_global_id(0);
  size_t j = get_global_id(1);
  size_t output_index = i + ((size_t) N) * j;

  if (i < (size_t) N && j < (size_t) N &&
      output_index < (size_t) count) {
    numeric sum = (numeric) 0;
    for (int k = 0; k < DIM; ++k) {
      size_t offset = ((size_t) k) * ((size_t) N);
      numeric diff = input[i + offset] - input[j + offset];
      sum += weights[k] * diff * diff;
    }
    output[output_index] = sqrt(sum);
  }
}
