use of com.tencent.angel.ps.storage.vector.ServerLongAnyRow 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.ServerLongAnyRow in project angel by Tencent.
the class PullNeighbor method partitionGet.
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
PartitionGetParamWithIds pparam = (PartitionGetParamWithIds) partParam;
long[] keyIds = pparam.getKeyIds();
ServerLongAnyRow row = (ServerLongAnyRow) psContext.getMatrixStorageManager().getRow(pparam.getPartKey(), 0);
Long2ObjectOpenHashMap<long[]> partResult = new Long2ObjectOpenHashMap<long[]>(keyIds.length);
boolean isTrunc = PathQueue.isIsTrunc();
if (PathQueue.getKeepProba() < 1.0 - 1e-6 && PathQueue.getKeepProba() > 1e-6) {
double selectThred = PathQueue.getThreshold() / (1 - PathQueue.getKeepProba());
for (long keyId : keyIds) {
LongArrayElement longArrayElement = (LongArrayElement) row.get(keyId);
long[] neighs = longArrayElement.getData();
if (isTrunc && neighs.length > selectThred) {
partResult.put(keyId, Arrays.copyOf(neighs, (int) selectThred));
} else {
partResult.put(keyId, neighs);
}
}
} else {
for (long keyId : keyIds) {
LongArrayElement longArrayElement = (LongArrayElement) row.get(keyId);
long[] neighs = longArrayElement.getData();
partResult.put(keyId, neighs);
}
}
return new PullNeighborPartitionResult(partResult);
}
use of com.tencent.angel.ps.storage.vector.ServerLongAnyRow 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.ServerLongAnyRow in project angel by Tencent.
the class GetNodes method partitionGet.
@Override
public PartitionGetResult partitionGet(PartitionGetParam param) {
ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
ObjectIterator<Entry<IElement>> it = row.iterator();
LongArrayList nodes = new LongArrayList();
Boolean isHash = ((PartGetNodesParam) param).getHash();
long start = isHash ? 0 : param.getPartKey().getStartCol();
while (it.hasNext()) {
Long2ObjectMap.Entry entry = it.next();
GraphNode node = (GraphNode) entry.getValue();
if (node.getFeats() != null && node.getNeighbors() == null) {
nodes.add(entry.getLongKey() + start);
}
}
return new IndexPartGetLongResult(param.getPartKey(), nodes.toLongArray());
}
use of com.tencent.angel.ps.storage.vector.ServerLongAnyRow 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);
}
Aggregations