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) {
int resultSize = 0;
for (PartitionGetResult result : partResults) {
resultSize += ((PartGeneralGetResult) result).getNodeIds().length;
}
Long2ObjectOpenHashMap<float[]> nodeIdToAttrs = new Long2ObjectOpenHashMap<>(resultSize);
for (PartitionGetResult result : partResults) {
PartGeneralGetResult partResult = (PartGeneralGetResult) result;
long[] nodeIds = partResult.getNodeIds();
IElement[] attrs = partResult.getData();
for (int i = 0; i < nodeIds.length; i++) {
if (attrs[i] != null) {
nodeIdToAttrs.put(nodeIds[i], ((FloatArrayElement) attrs[i]).getData());
} else {
nodeIdToAttrs.put(nodeIds[i], emptyFloats);
}
}
}
return new GetFloatsResult(nodeIdToAttrs);
}
use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.
the class GeneralGet method merge.
@Override
public GetResult merge(List<PartitionGetResult> partResults) {
int resultSize = 0;
for (PartitionGetResult result : partResults) {
resultSize += ((PartGeneralGetResult) result).getNodeIds().length;
}
Long2ObjectOpenHashMap nodeIdToNeighbors = new Long2ObjectOpenHashMap<>(resultSize);
for (PartitionGetResult result : partResults) {
PartGeneralGetResult getResult = (PartGeneralGetResult) result;
long[] nodeIds = getResult.getNodeIds();
IElement[] objs = getResult.getData();
for (int i = 0; i < nodeIds.length; i++) {
nodeIdToNeighbors.put(nodeIds[i], objs[i]);
}
}
return new GetElementResult(nodeIdToNeighbors);
}
use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.
the class SampleNeighbor method merge.
@Override
public GetResult merge(List<PartitionGetResult> partResults) {
SampleNeighborParam param = (SampleNeighborParam) getParam();
long[] keys = param.getKeys();
Int2ObjectArrayMap<PartitionGetResult> partIdToResult = new Int2ObjectArrayMap<>();
for (PartitionGetResult result : partResults) {
partIdToResult.put(((SampleNeighborPartResult) result).getPartId(), result);
}
for (PartitionGetParam partParam : param.getParams()) {
SampleNeighborPartParam param0 = (SampleNeighborPartParam) partParam;
int start = param0.getStartIndex();
int end = param0.getEndIndex();
SampleNeighborPartResult result = (SampleNeighborPartResult) partIdToResult.get(param0.getPartKey().getPartitionId());
int[] indptr = result.getIndptr();
long[] neighbors = result.getNeighbors();
int[] sampleTypes = result.getTypes();
assert indptr.length == (end - start) + 1;
for (int i = start; i < end; i++) {
int keyIndex = index.get(keys[i]);
for (int j = indptr[i - start]; j < indptr[i - start + 1]; j++) {
long n = neighbors[j];
if (!index.containsKey(n)) {
index.put(n, index.size());
}
srcs.add(keyIndex);
dsts.add(index.get(n));
}
if (param.getSampleTypes()) {
for (int j = indptr[i - start]; j < indptr[i - start + 1]; j++) {
types.add(sampleTypes[j]);
}
}
}
}
return new ScalarAggrResult(0);
}
use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.
the class GetColsFunc method merge.
@Override
public GetResult merge(List<PartitionGetResult> partResults) {
PartitionGetColsResult rr = (PartitionGetColsResult) partResults.get(0);
if (rr.vector instanceof CompIntDoubleVector) {
Map<Long, Vector> maps = new HashMap<>();
for (PartitionGetResult r : partResults) {
PartitionGetColsResult rrr = (PartitionGetColsResult) r;
long[] cols = rrr.cols;
CompIntDoubleVector vector = (CompIntDoubleVector) rrr.vector;
for (int i = 0; i < cols.length; i++) {
maps.put(cols[i], vector.getPartitions()[i]);
}
}
return new GetColsResult(maps);
} else if (rr.vector instanceof CompIntFloatVector) {
Map<Long, Vector> maps = new HashMap<>();
for (PartitionGetResult r : partResults) {
PartitionGetColsResult rrr = (PartitionGetColsResult) r;
long[] cols = rrr.cols;
CompIntFloatVector vector = (CompIntFloatVector) rrr.vector;
for (int i = 0; i < cols.length; i++) {
maps.put(cols[i], vector.getPartitions()[i]);
}
}
return new GetColsResult(maps);
} else {
throw new AngelException("Data type should be double or float!");
}
}
use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.
the class SampleNeighbor method merge.
@Override
public GetResult merge(List<PartitionGetResult> partResults) {
int len = 0;
for (PartitionGetResult result : partResults) {
len += ((PartSampleNeighborResult) result).getNodeIdToNeighbors().size();
}
Int2ObjectOpenHashMap<int[]> nodeIdToNeighbors = new Int2ObjectOpenHashMap<>(len);
for (PartitionGetResult result : partResults) {
nodeIdToNeighbors.putAll(((PartSampleNeighborResult) result).getNodeIdToNeighbors());
}
return new SampleNeighborResult(nodeIdToNeighbors);
}
Aggregations