__kernel void weighted_euclidean_block(
  __global numeric* output,
  const unsigned int count,
  __global const numeric* A,
  __global const numeric* B,
  __global const numeric* weights,
  const int N_a,
  const int N_b,
  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_b) + j;

  if (i < (size_t) N_a && j < (size_t) N_b &&
      output_index < (size_t) count) {
    numeric sum = (numeric) 0;
    for (int k = 0; k < DIM; ++k) {
      size_t offset_a = ((size_t) k) * ((size_t) N_a);
      size_t offset_b = ((size_t) k) * ((size_t) N_b);
      numeric diff = A[i + offset_a] - B[j + offset_b];
      sum += weights[k] * diff * diff;
    }
    output[output_index] = sqrt(sum);
  }
}
