THCDegree.cuh 534 Bytes
Newer Older
rusty1s's avatar
rusty1s committed
1
#ifndef THC_GENERIC_FILE
rusty1s's avatar
rusty1s committed
2
#define THC_GENERIC_FILE "generic/THCDegree.cuh"
rusty1s's avatar
rusty1s committed
3
#else
rusty1s's avatar
rusty1s committed
4

rusty1s's avatar
rusty1s committed
5
6
void THCTensor_(degree)(THCState *state, THCTensor *self, THCudaLongTensor *index) {
  int nEdges = THCudaLongTensor_nElement(state, index);
rusty1s's avatar
rusty1s committed
7

rusty1s's avatar
rusty1s committed
8
  THCTensor *one = THCTensor_(newWithSize1d)(state, nEdges);
rusty1s's avatar
rusty1s committed
9
  THCTensor_(fill)(state, one, ScalarConvert<int, real>::to(1));
rusty1s's avatar
rusty1s committed
10

rusty1s's avatar
rusty1s committed
11
  THCTensor_(fill)(state, self, ScalarConvert<int, real>::to(0));
rusty1s's avatar
rusty1s committed
12
13
14
15
16
17
  THCTensor_(scatterAdd)(state, self, 0, index, one);

  THCTensor_(free)(state, one);
}

#endif  // THC_GENERIC_FILE