Search in sources :

Example 31 with PartitionGetResult

use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.

the class Dot method merge.

@Override
public GetResult merge(List<PartitionGetResult> partResults) {
    if (partResults.size() > 0 && partResults.get(0) instanceof DotPartitionResult) {
        int size = ((DotPartitionResult) partResults.get(0)).length;
        // check the length of dot values
        for (PartitionGetResult result : partResults) {
            if (result instanceof DotPartitionResult && size != ((DotPartitionResult) result).length)
                throw new AngelException(String.format("length of dot values not same one is %d other is %d", size, ((DotPartitionResult) result).length));
        }
        // merge dot values from all partitions
        float[] results = new float[size];
        for (PartitionGetResult result : partResults) if (result instanceof DotPartitionResult)
            try {
                ((DotPartitionResult) result).merge(results);
            } finally {
                ((DotPartitionResult) result).clear();
            }
        return new NEDot.NEDotResult(results);
    }
    return null;
}
Also used : AngelException(com.tencent.angel.exception.AngelException) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)

Example 32 with PartitionGetResult

use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.

the class GetNeighborsWithCount method merge.

@Override
public GetResult merge(List<PartitionGetResult> partResults) {
    int resultSize = 0;
    for (PartitionGetResult result : partResults) {
        resultSize += ((PartGetNeighborWithCountResult) result).getNodeIds().length;
    }
    Long2ObjectOpenHashMap<long[]> nodeIdToNeighbors = new Long2ObjectOpenHashMap<>(resultSize);
    for (PartitionGetResult result : partResults) {
        PartGetNeighborWithCountResult getResult = (PartGetNeighborWithCountResult) result;
        long[] nodeIds = getResult.getNodeIds();
        long[][] objs = getResult.getData();
        for (int i = 0; i < nodeIds.length; i++) {
            nodeIdToNeighbors.put(nodeIds[i], objs[i]);
        }
    }
    return new GetLongsResult(nodeIdToNeighbors);
}
Also used : Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult) GetLongsResult(com.tencent.angel.graph.common.psf.result.GetLongsResult)

Example 33 with PartitionGetResult

use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.

the class GetHyperLogLog method merge.

@Override
public GetResult merge(List<PartitionGetResult> partResults) {
    int size = 0;
    for (PartitionGetResult result : partResults) {
        size += ((GetHyperLogLogPartResult) result).getLogs().size();
    }
    Long2ObjectOpenHashMap<HyperLogLogPlus> logs = new Long2ObjectOpenHashMap<>(size);
    for (PartitionGetResult r : partResults) {
        GetHyperLogLogPartResult rr = (GetHyperLogLogPartResult) r;
        logs.putAll(rr.getLogs());
    }
    return new GetHyperLogLogResult(logs);
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)

Example 34 with PartitionGetResult

use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.

the class GetUDFHandler method handle.

@Override
public void handle(FutureResult finalResult, UserRequest userRequest, ResponseCache responseCache) {
    GetPSFRequest getPSFRequest = (GetPSFRequest) userRequest;
    MapResponseCache cache = (MapResponseCache) responseCache;
    // Adaptor to Get PSF merge
    ConcurrentHashMap<Request, Response> responses = cache.getResponses();
    int responseNum = responses.size();
    List<PartitionGetResult> partGetResults = new ArrayList<>(responseNum);
    for (Response response : responses.values()) {
        partGetResults.add(((GetUDFResponse) response.getData()).getPartResult());
    }
    // Merge the sub-results
    try {
        finalResult.set(getPSFRequest.getGetFunc().merge(partGetResults));
    } catch (Exception x) {
        LOG.error("merge row failed ", x);
        finalResult.setExecuteException(new ExecutionException(x));
    }
}
Also used : Response(com.tencent.angel.ps.server.data.response.Response) GetUDFResponse(com.tencent.angel.ps.server.data.response.GetUDFResponse) Request(com.tencent.angel.ps.server.data.request.Request) GetPSFRequest(com.tencent.angel.psagent.matrix.transport.adapter.GetPSFRequest) UserRequest(com.tencent.angel.psagent.matrix.transport.adapter.UserRequest) ArrayList(java.util.ArrayList) GetPSFRequest(com.tencent.angel.psagent.matrix.transport.adapter.GetPSFRequest) ExecutionException(java.util.concurrent.ExecutionException) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult) ExecutionException(java.util.concurrent.ExecutionException)

Example 35 with PartitionGetResult

use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.

the class GetNodes method merge.

@Override
public GetResult merge(List<PartitionGetResult> partResults) {
    int size = 0;
    for (PartitionGetResult result : partResults) {
        if (result instanceof IndexPartGetLongResult) {
            size += ((IndexPartGetLongResult) result).getValues().length;
        }
    }
    long[] values = new long[size];
    int start = 0;
    for (PartitionGetResult result : partResults) {
        if (result instanceof IndexPartGetLongResult) {
            long[] vals = ((IndexPartGetLongResult) result).getValues();
            System.arraycopy(vals, 0, values, start, vals.length);
            start += vals.length;
        }
    }
    return new GetRowResult(ResponseType.SUCCESS, VFactory.denseLongVector(values));
}
Also used : IndexPartGetLongResult(com.tencent.angel.ml.matrix.psf.get.indexed.IndexPartGetLongResult) GetRowResult(com.tencent.angel.ml.matrix.psf.get.getrow.GetRowResult) 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