use of com.tencent.angel.ps.storage.partition.RowBasedPartition in project angel by Tencent.
the class LongIndexGet method partitionGet.
/**
* Each server partition execute this function and return values of specified index.
*
* @param partParam the partition parameter
* @return values of specified index
*/
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
long startTs = System.currentTimeMillis();
RowBasedPartition part = (RowBasedPartition) psContext.getMatrixStorageManager().getPart(partParam.getMatrixId(), partParam.getPartKey().getPartitionId());
if (part == null) {
throw new RuntimeException("Can not find partition " + partParam.getPartKey().getPartitionId());
}
int rowId = ((LongIndexPartGetParam) partParam).getRowId();
long[] indexes = ((LongIndexPartGetParam) partParam).getIndex();
ServerRow row = part.getRow(rowId);
if (row == null) {
throw new RuntimeException("Can not find row " + rowId + " in partition " + partParam.getPartKey().getPartitionId());
}
PartitionGetResult result;
if (row instanceof ServerLongDoubleRow) {
result = new IndexPartGetDoubleResult(partParam.getPartKey(), ((ServerLongDoubleRow) row).get(indexes));
} else if (row instanceof ServerLongFloatRow) {
result = new IndexPartGetFloatResult(partParam.getPartKey(), ((ServerLongFloatRow) row).get(indexes));
} else if (row instanceof ServerLongLongRow) {
result = new IndexPartGetLongResult(partParam.getPartKey(), ((ServerLongLongRow) row).get(indexes));
} else if (row instanceof ServerLongIntRow) {
result = new IndexPartGetIntResult(partParam.getPartKey(), ((ServerLongIntRow) row).get(indexes));
} else {
throw new UnsupportedOperationException("Index get use long type key not support " + row.getClass().getName() + "now");
}
LOG.debug("Partition get use time=" + (System.currentTimeMillis() - startTs) + " ms");
return result;
}
use of com.tencent.angel.ps.storage.partition.RowBasedPartition in project angel by Tencent.
the class Zero method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
RowBasedPartition part = (RowBasedPartition) psContext.getMatrixStorageManager().getPart(partParam.getMatrixId(), partParam.getPartKey().getPartitionId());
if (part != null) {
int startRow = part.getPartitionKey().getStartRow();
int endRow = part.getPartitionKey().getEndRow();
for (int i = startRow; i < endRow; i++) {
ServerRow row = part.getRow(i);
if (row == null) {
continue;
}
zero(row);
}
}
}
use of com.tencent.angel.ps.storage.partition.RowBasedPartition in project angel by Tencent.
the class GetNodeAttrs method partitionGet.
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
PartGetNodeAttrsParam param = (PartGetNodeAttrsParam) partParam;
ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
ServerPartition part = matrix.getPartition(partParam.getPartKey().getPartitionId());
ServerLongAnyRow row = (ServerLongAnyRow) (((RowBasedPartition) part).getRow(0));
long[] nodeIds = param.getNodeIds();
float[][] attrs = new float[nodeIds.length][];
int count = param.getCount();
Random r = new Random();
for (int i = 0; i < nodeIds.length; i++) {
long nodeId = nodeIds[i];
// Get node neighbor number
FloatArrayElement element = (FloatArrayElement) (row.get(nodeId));
if (element == null) {
attrs[i] = null;
} else {
float[] nodeAttrs = element.getData();
if (nodeAttrs == null || nodeAttrs.length == 0) {
attrs[i] = null;
} else if (count <= 0 || nodeAttrs.length <= count) {
attrs[i] = nodeAttrs;
} else {
attrs[i] = new float[count];
// If the neighbor number > count, just copy a range of neighbors to the result array, the copy position is random
int startPos = Math.abs(r.nextInt()) % nodeAttrs.length;
if (startPos + count <= nodeAttrs.length) {
System.arraycopy(nodeAttrs, startPos, attrs[i], 0, count);
} else {
System.arraycopy(nodeAttrs, startPos, attrs[i], 0, nodeAttrs.length - startPos);
System.arraycopy(nodeAttrs, 0, attrs[i], nodeAttrs.length - startPos, count - (nodeAttrs.length - startPos));
}
}
}
}
return new PartGetNodeAttrsResult(part.getPartitionKey().getPartitionId(), attrs);
}
use of com.tencent.angel.ps.storage.partition.RowBasedPartition in project angel by Tencent.
the class GetNodeFeats method partitionGet.
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
PartGetNodeFeatsParam param = (PartGetNodeFeatsParam) partParam;
ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
ServerPartition part = matrix.getPartition(partParam.getPartKey().getPartitionId());
ServerLongAnyRow row = (ServerLongAnyRow) (((RowBasedPartition) part).getRow(0));
long[] nodeIds = param.getNodeIds();
IntFloatVector[] feats = new IntFloatVector[nodeIds.length];
for (int i = 0; i < nodeIds.length; i++) {
if (row.get(nodeIds[i]) == null) {
continue;
}
feats[i] = ((Node) (row.get(nodeIds[i]))).getFeats();
}
return new PartGetNodeFeatsResult(part.getPartitionKey().getPartitionId(), feats);
}
use of com.tencent.angel.ps.storage.partition.RowBasedPartition in project angel by Tencent.
the class GetNeighborWithByteAttr method partitionGet.
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
PartSampleNeighborWithAttrParam param = (PartSampleNeighborWithAttrParam) partParam;
ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
ServerPartition part = matrix.getPartition(partParam.getPartKey().getPartitionId());
ServerLongAnyRow row = (ServerLongAnyRow) (((RowBasedPartition) part).getRow(0));
long[] nodeIds = param.getNodeIds();
NeighborsAttrsCompressedElement[] elementsCompressed = new NeighborsAttrsCompressedElement[nodeIds.length];
for (int i = 0; i < nodeIds.length; i++) {
long nodeId = nodeIds[i];
// Get node neighbors
NeighborsAttrsCompressedElement elem = (NeighborsAttrsCompressedElement) (row.get(nodeId));
if (elem == null) {
elementsCompressed[i] = null;
} else {
elementsCompressed[i] = elem;
}
}
return new PartGetNeighborWithAttrResult(part.getPartitionKey().getPartitionId(), elementsCompressed);
}
Aggregations