use of com.tencent.angel.ps.storage.vector.element.LongArrayElement in project angel by Tencent.
the class InitNeighbor method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
PartInitNeighborParam param = (PartInitNeighborParam) partParam;
ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
RowBasedPartition part = (RowBasedPartition) matrix.getPartition(partParam.getPartKey().getPartitionId());
ServerLongAnyRow row = (ServerLongAnyRow) part.getRow(0);
ObjectIterator<Long2ObjectMap.Entry<long[]>> iter = param.getNodeIdToNeighborIndices().long2ObjectEntrySet().iterator();
row.startWrite();
try {
while (iter.hasNext()) {
Long2ObjectMap.Entry<long[]> entry = iter.next();
row.set(entry.getLongKey(), new LongArrayElement(entry.getValue()));
}
} finally {
row.endWrite();
}
}
use of com.tencent.angel.ps.storage.vector.element.LongArrayElement 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.LongArrayElement 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.element.LongArrayElement 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.LongArrayElement in project angel by Tencent.
the class InitDynamicNbrs method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
GeneralPartUpdateParam initParam = (GeneralPartUpdateParam) partParam;
ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, initParam);
// Get nodes and features
ILongKeyAnyValuePartOp split = (ILongKeyAnyValuePartOp) initParam.getKeyValuePart();
long[] nodeIds = split.getKeys();
IElement[] neighbors = split.getValues();
row.startWrite();
try {
for (int i = 0; i < nodeIds.length; i++) {
LongArrayElement data = (LongArrayElement) neighbors[i];
DynamicNeighborElement ele = (DynamicNeighborElement) row.get(nodeIds[i]);
if (ele == null) {
ele = new DynamicNeighborElement();
ele.add(data.getData());
row.set(nodeIds[i], ele);
} else {
ele.add(data.getData());
}
}
} finally {
row.endWrite();
}
}
Aggregations