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 @@
#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); \
int64_t *clusterData = THTensor_getData(cluster); \
int64_t *rowData = THTensor_getData(row); \
int64_t *colData = THTensor_getData(col); \
int64_t *degData = THTensor_getData(deg); \
ptrdiff_t rowIdx = 0, neighborIdx; \
int64_t rowValue, colValue, clusterValue, tmp; \
while(rowIdx < THLongTensor_nElement(row)) { \
rowValue = rowData[rowIdx]; \
ptrdiff_t idx = 0, nEdges = THLongTensor_nElement(row); \
int64_t rowValue, pairValue, colValue, clusterValue; \
while(idx < nEdges) { \
rowValue = rowData[idx]; \
pairValue = rowValue; \
if (clusterData[rowValue] < 0) { \
colValue = rowValue; \
while(idx < nEdges && rowData[idx] == rowValue) { \
colValue = colData[idx]; \
if (clusterData[colValue] < 0) { \
SELECT \
clusterValue = rowValue < colValue ? rowValue : colValue; \
clusterData[rowValue] = clusterValue; \
clusterData[colValue] = clusterValue; \
} \
rowIdx += degData[rowValue]; \
idx++; \
} \
} \
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) {
TH_GREEDY_CLUSTER(cluster, row, col, deg,
for (neighborIdx = rowIdx; neighborIdx < rowIdx + degData[rowValue]; neighborIdx++) {
tmp = colData[neighborIdx];
if (clusterData[tmp] < 0) {
colValue = tmp;
void THGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col) {
TH_GREEDY_CLUSTER(cluster, row, col,
pairValue = colValue;
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 THCharGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THLongTensor *deg, THCharTensor *weight);
void THShortGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THLongTensor *deg, THShortTensor *weight);
void THIntGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THLongTensor *deg, THIntTensor *weight);
void THLongGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THLongTensor *deg, THLongTensor *weight);
void THFloatGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THLongTensor *deg, THFloatTensor *weight);
void THDoubleGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THLongTensor *deg, THDoubleTensor *weight);
void THByteGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THByteTensor *weight);
void THCharGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THCharTensor *weight);
void THShortGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THShortTensor *weight);
void THIntGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THIntTensor *weight);
void THLongGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THLongTensor *weight);
void THFloatGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THFloatTensor *weight);
void THDoubleGreedy(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THDoubleTensor *weight);
......@@ -2,19 +2,15 @@
#define TH_GENERIC_FILE "generic/THGreedy.c"
#else
void THGreedy_(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THLongTensor *deg,
THTensor *weight) {
void THGreedy_(THLongTensor *cluster, THLongTensor *row, THLongTensor *col, THTensor *weight) {
real *weightData = THTensor_getData(weight);
real maxWeight = 0, tmpWeight;
TH_GREEDY_CLUSTER(cluster, row, col, deg,
for (neighborIdx = rowIdx; neighborIdx < rowIdx + degData[rowValue]; neighborIdx++) {
tmp = colData[neighborIdx];
tmpWeight = weightData[neighborIdx];
if (clusterData[tmp] < 0 && tmpWeight > maxWeight) {
colValue = tmp;
TH_GREEDY_CLUSTER(cluster, row, col,
tmpWeight = weightData[idx];
if (tmpWeight > maxWeight) {
pairValue = colValue;
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