use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.
the class GetNodeAttrs method merge.
@Override
public GetResult merge(List<PartitionGetResult> partResults) {
Int2ObjectArrayMap<PartitionGetResult> partIdToResultMap = new Int2ObjectArrayMap<>(partResults.size());
for (PartitionGetResult result : partResults) {
partIdToResultMap.put(((PartGetNodeAttrsResult) result).getPartId(), result);
}
GetNodeAttrsParam param = (GetNodeAttrsParam) getParam();
long[] nodeIds = param.getNodeIds();
List<PartitionGetParam> partParams = param.getPartParams();
Long2ObjectOpenHashMap<float[]> nodeIdToAttrs = new Long2ObjectOpenHashMap<>(nodeIds.length);
for (PartitionGetParam partParam : partParams) {
int start = ((PartGetNodeAttrsParam) partParam).getStartIndex();
int end = ((PartGetNodeAttrsParam) partParam).getEndIndex();
PartGetNodeAttrsResult partResult = (PartGetNodeAttrsResult) (partIdToResultMap.get(partParam.getPartKey().getPartitionId()));
float[][] results = partResult.getNodeIdToAttrs();
for (int i = start; i < end; i++) {
nodeIdToAttrs.put(nodeIds[i], results[i - start]);
}
}
return new GetNodeAttrsResult(nodeIdToAttrs);
}
use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.
the class ValuesCombineUtils method mergeSparseFloatCompVector.
public static CompLongFloatVector mergeSparseFloatCompVector(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();
LongFloatVector[] splitVecs = new LongFloatVector[size];
for (int i = 0; i < size; i++) {
if (param.getPartKeyToIndexesMap().containsKey(partKeys.get(i))) {
float[] values = ((IndexPartGetFloatResult) partKeyToResultMap.get(partKeys.get(i))).getValues();
long[] indices = param.getPartKeyToIndexesMap().get(partKeys.get(i));
transformIndices(indices, partKeys.get(i));
splitVecs[i] = VFactory.sparseLongKeyFloatVector(subDim, indices, values);
} else {
splitVecs[i] = VFactory.sparseLongKeyFloatVector(subDim, 1);
}
}
CompLongFloatVector vector = VFactory.compLongFloatVector(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 mergeSparseDoubleCompVector.
// TODO : subDim set
public static CompIntDoubleVector mergeSparseDoubleCompVector(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();
IntDoubleVector[] splitVecs = new IntDoubleVector[size];
for (int i = 0; i < size; i++) {
if (param.getPartKeyToIndexesMap().containsKey(partKeys.get(i))) {
double[] values = ((IndexPartGetDoubleResult) partKeyToResultMap.get(partKeys.get(i))).getValues();
int[] indices = param.getPartKeyToIndexesMap().get(partKeys.get(i));
transformIndices(indices, partKeys.get(i));
splitVecs[i] = VFactory.sparseDoubleVector(subDim, indices, values);
} else {
splitVecs[i] = VFactory.sparseDoubleVector(subDim, 0);
}
}
CompIntDoubleVector vector = VFactory.compIntDoubleVector(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 mergeSparseFloatCompVector.
public static CompIntFloatVector mergeSparseFloatCompVector(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();
IntFloatVector[] splitVecs = new IntFloatVector[size];
for (int i = 0; i < size; i++) {
if (param.getPartKeyToIndexesMap().containsKey(partKeys.get(i))) {
float[] values = ((IndexPartGetFloatResult) partKeyToResultMap.get(partKeys.get(i))).getValues();
int[] indices = param.getPartKeyToIndexesMap().get(partKeys.get(i));
transformIndices(indices, partKeys.get(i));
splitVecs[i] = VFactory.sparseFloatVector(subDim, indices, values);
} else {
splitVecs[i] = VFactory.sparseFloatVector(subDim, 0);
}
}
CompIntFloatVector vector = VFactory.compIntFloatVector(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 IntDoubleVector mergeSparseDoubleVector(IndexGetParam param, List<PartitionGetResult> partResults) {
int dim = (int) PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(param.getMatrixId()).getColNum();
IntDoubleVector vector = VFactory.sparseDoubleVector(dim, param.size());
for (PartitionGetResult part : partResults) {
PartitionKey partKey = ((IndexPartGetDoubleResult) part).getPartKey();
int[] 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;
}
Aggregations