use of com.tencent.angel.psagent.matrix.transport.router.KeyValuePart in project angel by Tencent.
the class RangeRouterUtils method splitStream.
/**
* Split keys by matrix partition
*
* @param matrixMeta matrix meta data
* @param vectors Matrix vectors
* @return partition key to key partition map
*/
public static CompStreamKeyValuePart[] splitStream(MatrixMeta matrixMeta, Vector[] vectors) {
CompStreamKeyValuePart[] dataParts = new CompStreamKeyValuePart[matrixMeta.getPartitionNum()];
KeyValuePart[][] subDataParts = new KeyValuePart[vectors.length][];
for (int i = 0; i < vectors.length; i++) {
subDataParts[i] = split(matrixMeta, vectors[i]);
}
for (int i = 0; i < dataParts.length; i++) {
dataParts[i] = new CompStreamKeyValuePart(vectors.length);
for (int j = 0; j < vectors.length; j++) {
dataParts[i].add(subDataParts[j][i]);
}
}
return dataParts;
}
use of com.tencent.angel.psagent.matrix.transport.router.KeyValuePart in project angel by Tencent.
the class AnyKeysUpdateParam method split.
@Override
public List<PartitionUpdateParam> split() {
MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
PartitionKey[] parts = meta.getPartitionKeys();
KeyValuePart[] splits = RouterUtils.split(meta, 0, nodeIds, neighbors);
assert parts.length == splits.length;
List<PartitionUpdateParam> partParams = new ArrayList<>(parts.length);
for (int i = 0; i < parts.length; i++) {
if (splits[i] != null && splits[i].size() > 0) {
partParams.add(new GeneralPartUpdateParam(matrixId, parts[i], splits[i]));
}
}
return partParams;
}
use of com.tencent.angel.psagent.matrix.transport.router.KeyValuePart in project angel by Tencent.
the class IntKeysUpdateParam method split.
@Override
public List<PartitionUpdateParam> split() {
MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
PartitionKey[] parts = meta.getPartitionKeys();
KeyValuePart[] splits = RouterUtils.split(meta, 0, nodeIds, neighbors);
assert parts.length == splits.length;
List<PartitionUpdateParam> partParams = new ArrayList<>(parts.length);
for (int i = 0; i < parts.length; i++) {
if (splits[i] != null && splits[i].size() > 0) {
partParams.add(new GeneralPartUpdateParam(matrixId, parts[i], splits[i]));
}
}
return partParams;
}
use of com.tencent.angel.psagent.matrix.transport.router.KeyValuePart in project angel by Tencent.
the class LongKeysUpdateParam method split.
@Override
public List<PartitionUpdateParam> split() {
MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
PartitionKey[] parts = meta.getPartitionKeys();
KeyValuePart[] splits = RouterUtils.split(meta, 0, nodeIds, neighbors);
assert parts.length == splits.length;
List<PartitionUpdateParam> partParams = new ArrayList<>(parts.length);
for (int i = 0; i < parts.length; i++) {
if (splits[i] != null && splits[i].size() > 0) {
partParams.add(new GeneralPartUpdateParam(matrixId, parts[i], splits[i]));
}
}
return partParams;
}
use of com.tencent.angel.psagent.matrix.transport.router.KeyValuePart in project angel by Tencent.
the class GetNeighborsWithCount method partitionGetWithCount.
public static PartitionGetResult partitionGetWithCount(PSContext psContext, PartitionGetParam partParam) {
PartGetNeighborWithCountParam param = (PartGetNeighborWithCountParam) partParam;
KeyValuePart keyValuePart = param.getIndicesPart();
// Long type node id
long[] nodeIds = ((ILongKeyIntValuePartOp) keyValuePart).getKeys();
int[] count = ((ILongKeyIntValuePartOp) keyValuePart).getValues();
long[][] neighbors = new long[nodeIds.length][];
Random r = new Random();
ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
for (int i = 0; i < nodeIds.length; i++) {
long nodeId = nodeIds[i];
// Get node neighbor number
NeighborsAliasTableElement element = (NeighborsAliasTableElement) (row.get(nodeId));
if (element == null) {
neighbors[i] = null;
} else {
long[] nodeNeighbors = element.getNeighborIds();
if (nodeNeighbors == null || nodeNeighbors.length == 0 || count[i] <= 0) {
neighbors[i] = null;
} else {
neighbors[i] = new long[count[i]];
// start sampling by alias table for count times
float[] accept = element.getAccept();
int[] alias = element.getAlias();
for (int j = 0; j < count[i]; j++) {
// int index = Math.abs(r.nextInt()) % nodeNeighbors.length;
int index = r.nextInt(nodeNeighbors.length);
// float ac = Math.abs(r.nextFloat());
float ac = r.nextFloat();
if (ac < accept[index]) {
neighbors[i][j] = nodeNeighbors[index];
} else {
neighbors[i][j] = nodeNeighbors[alias[index]];
}
}
}
}
}
return new PartGetNeighborWithCountResult(nodeIds, neighbors);
}
Aggregations