use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.
the class ValuesCombineUtils method mergeSparseLongCompVector.
public static CompLongLongVector mergeSparseLongCompVector(LongIndexGetParam param, List<PartitionGetResult> partResults) {
Map<PartitionKey, PartitionGetResult> partKeyToResultMap = mapPartKeyToResult(partResults);
List<PartitionKey> partKeys = getSortedPartKeys(param.matrixId, param.getRowId());
MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(param.matrixId);
long dim = meta.getColNum();
long subDim = meta.getBlockColNum();
int size = partKeys.size();
LongLongVector[] splitVecs = new LongLongVector[size];
for (int i = 0; i < size; i++) {
if (param.getPartKeyToIndexesMap().containsKey(partKeys.get(i))) {
long[] values = ((IndexPartGetLongResult) partKeyToResultMap.get(partKeys.get(i))).getValues();
long[] indices = param.getPartKeyToIndexesMap().get(partKeys.get(i));
transformIndices(indices, partKeys.get(i));
splitVecs[i] = VFactory.sparseLongKeyLongVector(subDim, indices, values);
} else {
splitVecs[i] = VFactory.sparseLongKeyLongVector(subDim, 0);
}
}
CompLongLongVector vector = VFactory.compLongLongVector(dim, splitVecs, subDim);
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 ValuesCombineUtils method mergeSparseIntCompVector.
public static CompIntIntVector mergeSparseIntCompVector(IndexGetParam param, List<PartitionGetResult> partResults) {
Map<PartitionKey, PartitionGetResult> partKeyToResultMap = mapPartKeyToResult(partResults);
List<PartitionKey> partKeys = getSortedPartKeys(param.matrixId, param.getRowId());
MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(param.matrixId);
int dim = (int) meta.getColNum();
int subDim = (int) meta.getBlockColNum();
int size = partKeys.size();
IntIntVector[] splitVecs = new IntIntVector[size];
for (int i = 0; i < size; i++) {
if (param.getPartKeyToIndexesMap().containsKey(partKeys.get(i))) {
int[] values = ((IndexPartGetIntResult) partKeyToResultMap.get(partKeys.get(i))).getValues();
int[] indices = param.getPartKeyToIndexesMap().get(partKeys.get(i));
transformIndices(indices, partKeys.get(i));
splitVecs[i] = VFactory.sparseIntVector(subDim, indices, values);
} else {
splitVecs[i] = VFactory.sparseIntVector(subDim, 0);
}
}
CompIntIntVector vector = VFactory.compIntIntVector(dim, splitVecs, subDim);
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 ValuesCombineUtils method mergeSparseDoubleVector.
public static LongDoubleVector mergeSparseDoubleVector(LongIndexGetParam param, List<PartitionGetResult> partResults) {
long dim = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(param.getMatrixId()).getColNum();
LongDoubleVector vector = VFactory.sparseLongKeyDoubleVector(dim, param.size());
for (PartitionGetResult part : partResults) {
PartitionKey partKey = ((IndexPartGetResult) part).getPartKey();
long[] indexes = param.getPartKeyToIndexesMap().get(partKey);
double[] values = ((IndexPartGetDoubleResult) part).getValues();
for (int i = 0; i < indexes.length; 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 ValuesCombineUtils method mergeSparseDoubleCompVector.
public static CompLongDoubleVector mergeSparseDoubleCompVector(LongIndexGetParam param, List<PartitionGetResult> partResults) {
Map<PartitionKey, PartitionGetResult> partKeyToResultMap = mapPartKeyToResult(partResults);
List<PartitionKey> partKeys = getSortedPartKeys(param.matrixId, param.getRowId());
MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(param.matrixId);
long dim = meta.getColNum();
long subDim = meta.getBlockColNum();
int size = partKeys.size();
LongDoubleVector[] splitVecs = new LongDoubleVector[size];
for (int i = 0; i < size; i++) {
if (param.getPartKeyToIndexesMap().containsKey(partKeys.get(i))) {
double[] values = ((IndexPartGetDoubleResult) partKeyToResultMap.get(partKeys.get(i))).getValues();
long[] indices = param.getPartKeyToIndexesMap().get(partKeys.get(i));
transformIndices(indices, partKeys.get(i));
splitVecs[i] = VFactory.sparseLongKeyDoubleVector(subDim, indices, values);
} else {
splitVecs[i] = VFactory.sparseLongKeyDoubleVector(subDim, 1);
}
}
CompLongDoubleVector vector = VFactory.compLongDoubleVector(dim, splitVecs, subDim);
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 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;
}
Aggregations