use of com.tencent.angel.ps.storage.vector.element.IElement in project angel by Tencent.
the class InitWalkPath method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
InitWalkPathPartitionParam pparam = (InitWalkPathPartitionParam) partParam;
PartitionKey partKey = pparam.getPartKey();
ServerLongAnyRow walkPath = (ServerLongAnyRow) psContext.getMatrixStorageManager().getRow(partKey, 0);
ServerLongAnyRow rowNeighbor = (ServerLongAnyRow) psContext.getMatrixStorageManager().getRow(pparam.getNeighborMatrixId(), 0, partKey.getPartitionId());
Random rand = new Random();
ObjectIterator<Long2ObjectMap.Entry<IElement>> iter = rowNeighbor.iterator();
walkPath.startWrite();
walkPath.clear();
PathQueue.init(partKey.getPartitionId());
PathQueue.setThreshold(pparam.getThreshold());
PathQueue.setKeepProba(pparam.getKeepProba());
PathQueue.setNumParts(pparam.getNumParts());
PathQueue.setIsTrunc(pparam.isTrunc());
try {
int count = 0;
int batchSize = 1024;
ArrayList<WalkPath> batchPath = new ArrayList<>();
while (iter.hasNext()) {
Long2ObjectMap.Entry<IElement> entry = iter.next();
long key = entry.getLongKey() + partKey.getStartCol();
LongArrayElement value = (LongArrayElement) entry.getValue();
long[] neighbor = value.getData();
long neigh = neighbor[rand.nextInt(neighbor.length)];
WalkPath wPath = new WalkPath(pparam.getWalkLength(), key, neigh);
walkPath.set(key, wPath);
batchPath.add(wPath);
count++;
if (count % batchSize == 0) {
PathQueue.initPushBatch(partKey.getPartitionId(), batchPath);
batchPath.clear();
}
}
if (!batchPath.isEmpty()) {
PathQueue.initPushBatch(partKey.getPartitionId(), batchPath);
batchPath.clear();
}
} finally {
walkPath.endWrite();
}
}
use of com.tencent.angel.ps.storage.vector.element.IElement in project angel by Tencent.
the class InitNodeFeats method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
GeneralPartUpdateParam initParam = (GeneralPartUpdateParam) partParam;
ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, initParam);
// Get node ids and features
ILongKeyAnyValuePartOp split = (ILongKeyAnyValuePartOp) initParam.getKeyValuePart();
long[] nodeIds = split.getKeys();
IElement[] features = split.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.setFeats(((Feature) features[i]).getFeatures());
}
} finally {
row.endWrite();
}
}
use of com.tencent.angel.ps.storage.vector.element.IElement in project angel by Tencent.
the class PullMinDegree method partitionGet.
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
ServerLongAnyRow row = (ServerLongAnyRow) psContext.getMatrixStorageManager().getRow(partParam.getPartKey(), 0);
int partResult = Integer.MAX_VALUE;
ObjectIterator<Long2ObjectMap.Entry<IElement>> iter = row.iterator();
while (iter.hasNext()) {
Long2ObjectMap.Entry<IElement> entry = iter.next();
LongArrayElement value = (LongArrayElement) entry.getValue();
int length = value.getData().length;
if (length < partResult) {
partResult = length;
}
}
return new PullMinDegreePartitionResult(partResult);
}
use of com.tencent.angel.ps.storage.vector.element.IElement in project angel by Tencent.
the class GetNodeAttrs method merge.
@Override
public GetResult merge(List<PartitionGetResult> partResults) {
int resultSize = 0;
for (PartitionGetResult result : partResults) {
resultSize += ((PartGeneralGetResult) result).getNodeIds().length;
}
Long2ObjectOpenHashMap<float[]> nodeIdToAttrs = new Long2ObjectOpenHashMap<>(resultSize);
for (PartitionGetResult result : partResults) {
PartGeneralGetResult partResult = (PartGeneralGetResult) result;
long[] nodeIds = partResult.getNodeIds();
IElement[] attrs = partResult.getData();
for (int i = 0; i < nodeIds.length; i++) {
if (attrs[i] != null) {
nodeIdToAttrs.put(nodeIds[i], ((FloatArrayElement) attrs[i]).getData());
} else {
nodeIdToAttrs.put(nodeIds[i], emptyFloats);
}
}
}
return new GetFloatsResult(nodeIdToAttrs);
}
use of com.tencent.angel.ps.storage.vector.element.IElement in project angel by Tencent.
the class GeneralGet method merge.
@Override
public GetResult merge(List<PartitionGetResult> partResults) {
int resultSize = 0;
for (PartitionGetResult result : partResults) {
resultSize += ((PartGeneralGetResult) result).getNodeIds().length;
}
Long2ObjectOpenHashMap nodeIdToNeighbors = new Long2ObjectOpenHashMap<>(resultSize);
for (PartitionGetResult result : partResults) {
PartGeneralGetResult getResult = (PartGeneralGetResult) result;
long[] nodeIds = getResult.getNodeIds();
IElement[] objs = getResult.getData();
for (int i = 0; i < nodeIds.length; i++) {
nodeIdToNeighbors.put(nodeIds[i], objs[i]);
}
}
return new GetElementResult(nodeIdToNeighbors);
}
Aggregations