THCGraclus.cu 1.19 KB
Newer Older
rusty1s's avatar
rusty1s committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "THCGraclus.h"

#include "common.cuh"
#include "THCDegree.cuh"
#include "THCColor.cuh"
#include "THCPropose.cuh"
#include "THCResponse.cuh"

void THCTensor_graclus(THCState *state, THCudaLongTensor *self, THCudaLongTensor *row,
                       THCudaLongTensor *col) {
  THCAssertSameGPU(THCudaLongTensor_checkGPU(state, 3, self, row, col));

  int nNodes = THCudaLongTensor_nElement(state, self);
  THCudaLongTensor_fill(state, self, -1);

  THCudaLongTensor *prop = THCudaLongTensor_newWithSize1d(state, nNodes);
  THCudaLongTensor_fill(state, prop, -1);

  THCudaLongTensor *degree = THCudaLongTensor_newWithSize1d(state, nNodes);
  THCudaLongTensor_degree(state, degree, row);

  THCudaLongTensor *cumDegree = THCudaLongTensor_newWithSize1d(state, nNodes);
  THCudaLongTensor_cumsum(state, cumDegree, degree, 0);

rusty1s's avatar
rusty1s committed
25
26
27
28
  while(!THCTensor_color(state, self)) {
    THCTensor_propose(state, self, prop, row, col, degree, cumDegree);
    THCTensor_response(state, self, prop, row, col, degree, cumDegree);
  };
rusty1s's avatar
rusty1s committed
29
30
31
32
33
34
35
36

  THCudaLongTensor_free(state, prop);
  THCudaLongTensor_free(state, degree);
  THCudaLongTensor_free(state, cumDegree);
}

#include "generic/THCGraclus.cu"
#include "THC/THCGenerateAllTypes.h"