"test/vscode:/vscode.git/clone" did not exist on "c5402b18b0cc3ba3e893095b6a5dbc73358d869c"
THGrid.c 684 Bytes
Newer Older
rusty1s's avatar
rusty1s committed
1
2
3
4
5
#ifndef TH_GENERIC_FILE
#define TH_GENERIC_FILE "generic/THGrid.c"
#else

void THGrid_(cluster)(THLongTensor *cluster, THTensor *pos, THTensor *size, THLongTensor *count) {
rusty1s's avatar
rusty1s committed
6
7
8
9
10
11
12
  int64_t *clusterData = DATA(cluster);
  real *posData = DATA(pos);
  real *sizeData = DATA(size);
  int64_t *countData = DATA(count);

  ptrdiff_t n, d; int64_t coef, value;
  for (n = 0; n < THTensor_(size)(pos, 0); n++) {
rusty1s's avatar
rusty1s committed
13
    coef = 1; value = 0;
rusty1s's avatar
rusty1s committed
14
15
    for (d = 0; d < THTensor_(size)(pos, 1); d++) {
      value += coef * (int64_t) (*(posData + d * pos->stride[1]) / sizeData[d]);
rusty1s's avatar
rusty1s committed
16
17
      coef *= countData[d];
    }
rusty1s's avatar
rusty1s committed
18
19
20
    posData += pos->stride[0];
    clusterData[n] = value;
  }
rusty1s's avatar
rusty1s committed
21
22
23
}

#endif  // TH_GENERIC_FILE