Search in sources :

Example 26 with PartitionGetResult

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);
}
Also used : IElement(com.tencent.angel.ps.storage.vector.element.IElement) PartGeneralGetResult(com.tencent.angel.graph.model.general.get.PartGeneralGetResult) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) GetFloatsResult(com.tencent.angel.graph.common.psf.result.GetFloatsResult) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)

Example 27 with PartitionGetResult

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);
}
Also used : IElement(com.tencent.angel.ps.storage.vector.element.IElement) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult) GetElementResult(com.tencent.angel.graph.common.psf.result.GetElementResult)

Example 28 with PartitionGetResult

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);
}
Also used : Int2ObjectArrayMap(it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap) ScalarAggrResult(com.tencent.angel.ml.matrix.psf.aggr.enhance.ScalarAggrResult) PartitionGetParam(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)

Example 29 with PartitionGetResult

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!");
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)

Example 30 with PartitionGetResult

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);
}
Also used : Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)

Aggregations

PartitionGetResult (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)60 PartitionKey (com.tencent.angel.PartitionKey)24 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)18 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)12 PartitionGetParam (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)6 IElement (com.tencent.angel.ps.storage.vector.element.IElement)6 Int2ObjectArrayMap (it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap)6 GetLongsResult (com.tencent.angel.graph.common.psf.result.GetLongsResult)5 PartGeneralGetResult (com.tencent.angel.graph.model.general.get.PartGeneralGetResult)5 AngelException (com.tencent.angel.exception.AngelException)2 GetFunc (com.tencent.angel.ml.matrix.psf.get.base.GetFunc)2 GetRowResult (com.tencent.angel.ml.matrix.psf.get.getrow.GetRowResult)2 IndexPartGetLongResult (com.tencent.angel.ml.matrix.psf.get.indexed.IndexPartGetLongResult)2 GetUDFRequest (com.tencent.angel.ps.server.data.request.GetUDFRequest)2 Request (com.tencent.angel.ps.server.data.request.Request)2 GetUDFResponse (com.tencent.angel.ps.server.data.response.GetUDFResponse)2 RowBasedPartition (com.tencent.angel.ps.storage.partition.RowBasedPartition)2 UserRequest (com.tencent.angel.psagent.matrix.transport.adapter.UserRequest)2 Tuple3 (scala.Tuple3)2 HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)1