use of com.tencent.angel.ps.storage.vector.ServerLongAnyRow in project angel by Tencent.
the class InitNeighbor method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
InitNeighborPartParam param = (InitNeighborPartParam) partParam;
ServerLongAnyRow row = (ServerLongAnyRow) (psContext.getMatrixStorageManager().getRow(param.getPartKey(), 0));
long[] keys = param.getKeys();
long[][] neighborArrays = param.getNeighborArrays();
int[][] edgeTypes = param.getEdgeTypeArrays();
int[][] neighborTypes = param.getDstTypeArrays();
row.startWrite();
try {
for (int i = 0; i < keys.length; i++) {
Node node = (Node) row.get(keys[i]);
if (node == null) {
node = new Node();
row.set(keys[i], node);
}
node.setNeighbors(neighborArrays[i]);
if (edgeTypes != null)
node.setEdgeTypes(edgeTypes[i]);
if (neighborTypes != null)
node.setTypes(neighborTypes[i]);
}
} finally {
row.endWrite();
}
}
use of com.tencent.angel.ps.storage.vector.ServerLongAnyRow in project angel by Tencent.
the class GetProgress method partitionGet.
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
int partitionId = partParam.getPartKey().getPartitionId();
int finished = PathQueue.getProgress(partitionId);
ServerLongAnyRow row = (ServerLongAnyRow) psContext.getMatrixStorageManager().getRow(partParam.getPartKey(), 0);
if (row.size() == finished) {
return new GetProgressPartitionResult(true, 1.0);
} else {
return new GetProgressPartitionResult(false, 1.0 * finished / row.size());
}
}
use of com.tencent.angel.ps.storage.vector.ServerLongAnyRow in project angel by Tencent.
the class InitEdgeTypes method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
GeneralPartUpdateParam param = (GeneralPartUpdateParam) partParam;
ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
ILongKeyAnyValuePartOp keyValuePart = (ILongKeyAnyValuePartOp) param.getKeyValuePart();
long[] nodeIds = keyValuePart.getKeys();
IElement[] neighbors = keyValuePart.getValues();
row.startWrite();
try {
for (int i = 0; i < nodeIds.length; i++) {
GraphNode graphNode = (GraphNode) row.get(nodeIds[i]);
if (graphNode == null) {
graphNode = new GraphNode();
row.set(nodeIds[i], graphNode);
}
graphNode.setEdgeTypes(((EdgeType) neighbors[i]).getTypes());
}
} finally {
row.endWrite();
}
}
use of com.tencent.angel.ps.storage.vector.ServerLongAnyRow in project angel by Tencent.
the class GetLabels method partitionGet.
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
GeneralPartGetParam param = (GeneralPartGetParam) partParam;
KeyPart keyPart = param.getIndicesPart();
switch(keyPart.getKeyType()) {
case LONG:
{
// Long type node id
long[] nodeIds = ((ILongKeyPartOp) keyPart).getKeys();
ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
Long2ObjectOpenHashMap<float[]> nodeIdToLabels = new Long2ObjectOpenHashMap<>(nodeIds.length);
for (long nodeId : nodeIds) {
if (row.get(nodeId) == null) {
// If node not exist, just skip
continue;
}
float[] labels = ((GraphNode) (row.get(nodeId))).getLabels();
if (labels != null) {
nodeIdToLabels.put(nodeId, labels);
}
}
return new PartGetFloatArrayAttrsResult(param.getPartKey().getPartitionId(), nodeIdToLabels);
}
default:
{
// TODO: support String, Int, and Any type node id
throw new InvalidParameterException("Unsupport index type " + keyPart.getKeyType());
}
}
}
use of com.tencent.angel.ps.storage.vector.ServerLongAnyRow in project angel by Tencent.
the class GetNodeFeats method partitionGet.
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
GeneralPartGetParam param = (GeneralPartGetParam) partParam;
KeyPart keyPart = param.getIndicesPart();
switch(keyPart.getKeyType()) {
case LONG:
{
// Long type node id
long[] nodeIds = ((ILongKeyPartOp) keyPart).getKeys();
ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
Long2ObjectOpenHashMap<IntFloatVector> nodeIdToFeats = new Long2ObjectOpenHashMap<>(nodeIds.length);
for (long nodeId : nodeIds) {
if (row.get(nodeId) == null) {
// If node not exist, just skip
continue;
}
IntFloatVector feat = ((GraphNode) (row.get(nodeId))).getFeats();
if (feat != null) {
nodeIdToFeats.put(nodeId, feat);
}
}
return new PartGetNodeFeatsResult(param.getPartKey().getPartitionId(), nodeIdToFeats);
}
default:
{
// TODO: support String, Int, and Any type node id
throw new InvalidParameterException("Unsupport index type " + keyPart.getKeyType());
}
}
}
Aggregations