Search in sources :

Example 1 with PartGeneralGetResult

use of com.tencent.angel.graph.model.general.get.PartGeneralGetResult in project angel by Tencent.

the class GetAliasTableWithTrunc method merge.

@Override
public GetResult merge(List<PartitionGetResult> partResults) {
    int resultSize = 0;
    for (PartitionGetResult result : partResults) {
        resultSize += ((PartGeneralGetResult) result).getNodeIds().length;
    }
    Long2ObjectOpenHashMap<Tuple3<long[], float[], int[]>> nodeIdToNeighbors = new Long2ObjectOpenHashMap<>(resultSize);
    for (PartitionGetResult result : partResults) {
        PartGeneralGetResult partResult = (PartGeneralGetResult) result;
        long[] nodeIds = partResult.getNodeIds();
        IElement[] data = partResult.getData();
        for (int i = 0; i < nodeIds.length; i++) {
            if (data[i] != null) {
                long[] neighbors = ((AliasElement) data[i]).getNeighborIds();
                float[] accept = ((AliasElement) data[i]).getAccept();
                int[] alias = ((AliasElement) data[i]).getAlias();
                if (neighbors.length > 0 && accept.length > 0 && alias.length > 0) {
                    nodeIdToNeighbors.put(nodeIds[i], new Tuple3<>(neighbors, accept, alias));
                } else {
                    nodeIdToNeighbors.put(nodeIds[i], emp);
                }
            } else {
                nodeIdToNeighbors.put(nodeIds[i], emp);
            }
        }
    }
    return new PullAliasResult(nodeIdToNeighbors);
}
Also used : IElement(com.tencent.angel.ps.storage.vector.element.IElement) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) PartGeneralGetResult(com.tencent.angel.graph.model.general.get.PartGeneralGetResult) Tuple3(scala.Tuple3) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)

Example 2 with PartGeneralGetResult

use of com.tencent.angel.graph.model.general.get.PartGeneralGetResult 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 3 with PartGeneralGetResult

use of com.tencent.angel.graph.model.general.get.PartGeneralGetResult in project angel by Tencent.

the class GeneralGetUtils method partitionGet.

public static PartitionGetResult partitionGet(PSContext psContext, PartitionGetParam partParam) {
    GeneralPartGetParam param = (GeneralPartGetParam) partParam;
    KeyPart keyPart = param.getIndicesPart();
    // Long type node id
    long[] nodeIds = ((ILongKeyPartOp) keyPart).getKeys();
    ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
    // Get data
    IElement[] data = new IElement[nodeIds.length];
    for (int i = 0; i < nodeIds.length; i++) {
        data[i] = row.get(nodeIds[i]);
    }
    MatrixMeta meta = psContext.getMatrixMetaManager().getMatrixMeta(param.getMatrixId());
    try {
        return new PartGeneralGetResult(meta.getValueClass(), nodeIds, data);
    } catch (ClassNotFoundException e) {
        throw new AngelException("Can not get value class ");
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) GeneralPartGetParam(com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam) IElement(com.tencent.angel.ps.storage.vector.element.IElement) PartGeneralGetResult(com.tencent.angel.graph.model.general.get.PartGeneralGetResult) MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) ILongKeyPartOp(com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp)

Example 4 with PartGeneralGetResult

use of com.tencent.angel.graph.model.general.get.PartGeneralGetResult in project angel by Tencent.

the class GetNeighbor method merge.

@Override
public GetResult merge(List<PartitionGetResult> partResults) {
    int resultSize = 0;
    for (PartitionGetResult result : partResults) {
        resultSize += ((PartGeneralGetResult) result).getNodeIds().length;
    }
    Long2ObjectOpenHashMap<long[]> nodeIdToNeighbors = new Long2ObjectOpenHashMap<>(resultSize);
    for (PartitionGetResult result : partResults) {
        PartGeneralGetResult partResult = (PartGeneralGetResult) result;
        long[] nodeIds = partResult.getNodeIds();
        IElement[] neighbors = partResult.getData();
        for (int i = 0; i < nodeIds.length; i++) {
            if (neighbors[i] != null) {
                byte[] nbrs = ((DynamicNeighborElement) neighbors[i]).getData();
                nodeIdToNeighbors.put(nodeIds[i], ScalaKryoInstantiator.defaultPool().fromBytes(nbrs, long[].class));
            } else {
                nodeIdToNeighbors.put(nodeIds[i], Constents.emptyLongs);
            }
        }
    }
    return new GetLongsResult(nodeIdToNeighbors);
}
Also used : IElement(com.tencent.angel.ps.storage.vector.element.IElement) PartGeneralGetResult(com.tencent.angel.graph.model.general.get.PartGeneralGetResult) DynamicNeighborElement(com.tencent.angel.graph.model.neighbor.dynamic.DynamicNeighborElement) 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 5 with PartGeneralGetResult

use of com.tencent.angel.graph.model.general.get.PartGeneralGetResult in project angel by Tencent.

the class GetLongNeighbor method merge.

@Override
public GetResult merge(List<PartitionGetResult> partResults) {
    int resultSize = 0;
    for (PartitionGetResult result : partResults) {
        resultSize += ((PartGeneralGetResult) result).getNodeIds().length;
    }
    Long2ObjectOpenHashMap<long[]> nodeIdToNeighbors = new Long2ObjectOpenHashMap<>(resultSize);
    for (PartitionGetResult result : partResults) {
        PartGeneralGetResult partResult = (PartGeneralGetResult) result;
        long[] nodeIds = partResult.getNodeIds();
        IElement[] neighbors = partResult.getData();
        for (int i = 0; i < nodeIds.length; i++) {
            if (neighbors[i] != null) {
                nodeIdToNeighbors.put(nodeIds[i], ((LongArrayElement) neighbors[i]).getData());
            } else {
                nodeIdToNeighbors.put(nodeIds[i], Constents.emptyLongs);
            }
        }
    }
    return new GetLongsResult(nodeIdToNeighbors);
}
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) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult) GetLongsResult(com.tencent.angel.graph.common.psf.result.GetLongsResult)

Aggregations

PartGeneralGetResult (com.tencent.angel.graph.model.general.get.PartGeneralGetResult)6 IElement (com.tencent.angel.ps.storage.vector.element.IElement)6 PartitionGetResult (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)5 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)5 GetLongsResult (com.tencent.angel.graph.common.psf.result.GetLongsResult)3 AngelException (com.tencent.angel.exception.AngelException)1 GetFloatsResult (com.tencent.angel.graph.common.psf.result.GetFloatsResult)1 DynamicNeighborElement (com.tencent.angel.graph.model.neighbor.dynamic.DynamicNeighborElement)1 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)1 GeneralPartGetParam (com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam)1 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)1 ByteArrayElement (com.tencent.angel.ps.storage.vector.element.ByteArrayElement)1 KeyPart (com.tencent.angel.psagent.matrix.transport.router.KeyPart)1 ILongKeyPartOp (com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp)1 Tuple3 (scala.Tuple3)1