Commit acbdd5db authored by rusty1s's avatar rusty1s
Browse files

greedy cpu without degree computation: results in O(E) runtime :(

parent 878fa61f
...@@ -4,36 +4,36 @@ ...@@ -4,36 +4,36 @@
#define THGreedy_ TH_CONCAT_3(TH,Real,Greedy) #define THGreedy_ TH_CONCAT_3(TH,Real,Greedy)
#define TH_GREEDY_CLUSTER(cluster, row, col, deg, SELECT) { \ #define TH_GREEDY_CLUSTER(cluster, row, col, SELECT) { \
THLongTensor_fill(cluster, -1); \ THLongTensor_fill(cluster, -1); \
int64_t *clusterData = THTensor_getData(cluster); \ int64_t *clusterData = THTensor_getData(cluster); \
int64_t *rowData = THTensor_getData(row); \ int64_t *rowData = THTensor_getData(row); \
int64_t *colData = THTensor_getData(col); \ int64_t *colData = THTensor_getData(col); \
int64_t *degData = THTensor_getData(deg); \ ptrdiff_t idx = 0, nEdges = THLongTensor_nElement(row); \
ptrdiff_t rowIdx = 0, neighborIdx; \ int64_t rowValue, pairValue, colValue, clusterValue; \
int64_t rowValue, colValue, clusterValue, tmp; \ while(idx < nEdges) { \
while(rowIdx < THLongTensor_nElement(row)) { \ rowValue = rowData[idx]; \
rowValue = rowData[rowIdx]; \ pairValue = rowValue; \
if (clusterData[rowValue] < 0) { \ if (clusterData[rowValue] < 0) { \
colValue = rowValue; \ while(idx < nEdges && rowData[idx] == rowValue) { \
SELECT \ colValue = colData[idx]; \
clusterValue = rowValue < colValue ? rowValue : colValue; \ if (clusterData[colValue] < 0) { \
clusterData[rowValue] = clusterValue; \ SELECT \
clusterData[colValue] = clusterValue; \ } \
idx++; \
} \
} \ } \
rowIdx += degData[rowValue]; \ clusterValue = rowValue < pairValue ? rowValue : pairValue; \
clusterData[rowValue] = clusterValue; \
clusterData[pairValue] = clusterValue; \
while(idx < nEdges && rowData[idx] == rowValue) idx++; \
} \ } \
} }
void THGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THLongTensor *deg) { void THGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col) {
TH_GREEDY_CLUSTER(cluster, row, col, deg, TH_GREEDY_CLUSTER(cluster, row, col,
for (neighborIdx = rowIdx; neighborIdx < rowIdx + degData[rowValue]; neighborIdx++) { pairValue = colValue;
tmp = colData[neighborIdx]; break;
if (clusterData[tmp] < 0) {
colValue = tmp;
break;
}
}
) )
} }
......
void THGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THLongTensor *deg); void THGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col);
void THByteGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THLongTensor *deg, THByteTensor *weight); void THByteGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THByteTensor *weight);
void THCharGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THLongTensor *deg, THCharTensor *weight); void THCharGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THCharTensor *weight);
void THShortGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THLongTensor *deg, THShortTensor *weight); void THShortGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THShortTensor *weight);
void THIntGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THLongTensor *deg, THIntTensor *weight); void THIntGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THIntTensor *weight);
void THLongGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THLongTensor *deg, THLongTensor *weight); void THLongGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THLongTensor *weight);
void THFloatGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THLongTensor *deg, THFloatTensor *weight); void THFloatGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THFloatTensor *weight);
void THDoubleGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THLongTensor *deg, THDoubleTensor *weight); void THDoubleGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THDoubleTensor *weight);
...@@ -2,18 +2,14 @@ ...@@ -2,18 +2,14 @@
#define TH_GENERIC_FILE "generic/THGreedy.c" #define TH_GENERIC_FILE "generic/THGreedy.c"
#else #else
void THGreedy_(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THLongTensor *deg, void THGreedy_(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THTensor *weight) {
THTensor *weight) {
real *weightData = THTensor_getData(weight); real *weightData = THTensor_getData(weight);
real maxWeight = 0, tmpWeight; real maxWeight = 0, tmpWeight;
TH_GREEDY_CLUSTER(cluster, row, col, deg, TH_GREEDY_CLUSTER(cluster, row, col,
for (neighborIdx = rowIdx; neighborIdx < rowIdx + degData[rowValue]; neighborIdx++) { tmpWeight = weightData[idx];
tmp = colData[neighborIdx]; if (tmpWeight > maxWeight) {
tmpWeight = weightData[neighborIdx]; pairValue = colValue;
if (clusterData[tmp] < 0 && tmpWeight > maxWeight) { maxWeight = tmpWeight;
colValue = tmp;
maxWeight = tmpWeight;
}
} }
) )
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment