use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.
the class IndexGet 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());
PartitionGetResult result = null;
if (part != null) {
int rowId = ((IndexPartGetParam) partParam).getRowId();
int[] indexes = ((IndexPartGetParam) partParam).getIndexes();
ServerRow row = part.getRow(rowId);
RowType rowType = row.getRowType();
switch(rowType) {
case T_DOUBLE_DENSE:
case T_DOUBLE_SPARSE:
case T_DOUBLE_DENSE_COMPONENT:
case T_DOUBLE_SPARSE_COMPONENT:
{
result = new IndexPartGetDoubleResult(partParam.getPartKey(), ((ServerIntDoubleRow) row).get(indexes));
break;
}
case T_FLOAT_DENSE:
case T_FLOAT_SPARSE:
case T_FLOAT_DENSE_COMPONENT:
case T_FLOAT_SPARSE_COMPONENT:
{
result = new IndexPartGetFloatResult(partParam.getPartKey(), ((ServerIntFloatRow) row).get(indexes));
break;
}
case T_INT_DENSE:
case T_INT_SPARSE:
case T_INT_DENSE_COMPONENT:
case T_INT_SPARSE_COMPONENT:
{
result = new IndexPartGetIntResult(partParam.getPartKey(), ((ServerIntIntRow) row).get(indexes));
break;
}
case T_LONG_DENSE:
case T_LONG_SPARSE:
case T_LONG_DENSE_COMPONENT:
case T_LONG_SPARSE_COMPONENT:
{
result = new IndexPartGetLongResult(partParam.getPartKey(), ((ServerIntLongRow) row).get(indexes));
break;
}
default:
throw new UnsupportedOperationException("Unsupport operation: update " + rowType + " to " + this.getClass().getName());
}
}
LOG.debug("Partition get use time=" + (System.currentTimeMillis() - startTs) + " ms");
return result;
}
use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.
the class ValuesCombineUtils method mergeSparseFloatVector.
public static IntFloatVector mergeSparseFloatVector(IndexGetParam param, List<PartitionGetResult> partResults) {
int dim = (int) PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(param.getMatrixId()).getColNum();
IntFloatVector vector = VFactory.sparseFloatVector(dim, param.size());
for (PartitionGetResult part : partResults) {
PartitionKey partKey = ((IndexPartGetFloatResult) part).getPartKey();
int[] indexes = param.getPartKeyToIndexesMap().get(partKey);
float[] values = ((IndexPartGetFloatResult) part).getValues();
for (int i = 0; i < indexes.length; i++) {
if (i < 10) {
LOG.debug("index " + indexes[i] + ", value " + values[i]);
}
vector.set(indexes[i], values[i]);
}
}
vector.setMatrixId(param.getMatrixId());
vector.setRowId(param.getRowId());
return vector;
}
use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.
the class GetNeighbor method merge.
@Override
public GetResult merge(List<PartitionGetResult> partResults) {
int resultSize = 0;
for (PartitionGetResult result : partResults) {
resultSize += ((PartGeneralGetResult) result).getNodeIds().length;
}
Long2ObjectOpenHashMap<long[]> nodeIdToNeighbors = new Long2ObjectOpenHashMap<>(resultSize);
for (PartitionGetResult result : partResults) {
PartGeneralGetResult partResult = (PartGeneralGetResult) result;
long[] nodeIds = partResult.getNodeIds();
IElement[] neighbors = partResult.getData();
for (int i = 0; i < nodeIds.length; i++) {
if (neighbors[i] != null) {
byte[] nbrs = ((DynamicNeighborElement) neighbors[i]).getData();
nodeIdToNeighbors.put(nodeIds[i], ScalaKryoInstantiator.defaultPool().fromBytes(nbrs, long[].class));
} else {
nodeIdToNeighbors.put(nodeIds[i], Constents.emptyLongs);
}
}
}
return new GetLongsResult(nodeIdToNeighbors);
}
use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.
the class GetLongNeighbor method merge.
@Override
public GetResult merge(List<PartitionGetResult> partResults) {
int resultSize = 0;
for (PartitionGetResult result : partResults) {
resultSize += ((PartGeneralGetResult) result).getNodeIds().length;
}
Long2ObjectOpenHashMap<long[]> nodeIdToNeighbors = new Long2ObjectOpenHashMap<>(resultSize);
for (PartitionGetResult result : partResults) {
PartGeneralGetResult partResult = (PartGeneralGetResult) result;
long[] nodeIds = partResult.getNodeIds();
IElement[] neighbors = partResult.getData();
for (int i = 0; i < nodeIds.length; i++) {
if (neighbors[i] != null) {
nodeIdToNeighbors.put(nodeIds[i], ((LongArrayElement) neighbors[i]).getData());
} else {
nodeIdToNeighbors.put(nodeIds[i], Constents.emptyLongs);
}
}
}
return new GetLongsResult(nodeIdToNeighbors);
}
use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.
the class Sample method merge.
@Override
public GetResult merge(List<PartitionGetResult> partResults) {
int resultSize = 0;
for (PartitionGetResult result : partResults) {
resultSize += ((PartGetLongsResult) result).getData().length;
}
Long2ObjectOpenHashMap<long[]> nodeIdToNeighbors = new Long2ObjectOpenHashMap<>(resultSize);
for (PartitionGetResult result : partResults) {
PartGetLongsResult partResult = (PartGetLongsResult) result;
long[] nodeIds = partResult.getNodeIds();
long[][] samples = partResult.getData();
for (int i = 0; i < nodeIds.length; i++) {
nodeIdToNeighbors.put(nodeIds[i], samples[i]);
}
}
return new GetLongsResult(nodeIdToNeighbors);
}
Aggregations