Search in sources :

Example 1 with ILongKeyPartOp

use of com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp in project angel by Tencent.

the class ServerRowUtils method getByKeys.

public static ValuePart getByKeys(ServerRow row, KeyPart keyPart) {
    ValuePart result;
    if (keyPart instanceof IIntKeyPartOp) {
        // Index is int
        IIntKeyPartOp intKeyPart = (IIntKeyPartOp) keyPart;
        if (row instanceof ServerIntFloatRow) {
            float[] values = ((ServerIntFloatRow) row).get(intKeyPart.getKeys());
            result = new FloatValuesPart(values);
        } else if (row instanceof ServerIntDoubleRow) {
            double[] values = ((ServerIntDoubleRow) row).get(intKeyPart.getKeys());
            result = new DoubleValuesPart(values);
        } else if (row instanceof ServerIntIntRow) {
            int[] values = ((ServerIntIntRow) row).get(intKeyPart.getKeys());
            result = new IntValuesPart(values);
        } else if (row instanceof ServerIntLongRow) {
            long[] values = ((ServerIntLongRow) row).get(intKeyPart.getKeys());
            result = new LongValuesPart(values);
        } else {
            throw new UnsupportedOperationException("Unsupport row type " + row.getClass().getName());
        }
    } else if (keyPart instanceof ILongKeyPartOp) {
        // Index is long
        ILongKeyPartOp longKeyPart = (ILongKeyPartOp) keyPart;
        if (row instanceof ServerLongFloatRow) {
            float[] values = ((ServerLongFloatRow) row).get(longKeyPart.getKeys());
            result = new FloatValuesPart(values);
        } else if (row instanceof ServerLongDoubleRow) {
            double[] values = ((ServerLongDoubleRow) row).get(longKeyPart.getKeys());
            result = new DoubleValuesPart(values);
        } else if (row instanceof ServerLongIntRow) {
            int[] values = ((ServerLongIntRow) row).get(longKeyPart.getKeys());
            result = new IntValuesPart(values);
        } else if (row instanceof ServerLongLongRow) {
            long[] values = ((ServerLongLongRow) row).get(longKeyPart.getKeys());
            result = new LongValuesPart(values);
        } else {
            throw new UnsupportedOperationException("Unsupport row type " + row.getClass().getName());
        }
    } else {
        throw new UnsupportedOperationException("Unsupport index type " + keyPart.getClass().getName());
    }
    return result;
}
Also used : FloatValuesPart(com.tencent.angel.psagent.matrix.transport.router.value.FloatValuesPart) ValuePart(com.tencent.angel.psagent.matrix.transport.router.ValuePart) ILongKeyPartOp(com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp) LongValuesPart(com.tencent.angel.psagent.matrix.transport.router.value.LongValuesPart) IIntKeyPartOp(com.tencent.angel.psagent.matrix.transport.router.operator.IIntKeyPartOp) IntValuesPart(com.tencent.angel.psagent.matrix.transport.router.value.IntValuesPart) DoubleValuesPart(com.tencent.angel.psagent.matrix.transport.router.value.DoubleValuesPart)

Example 2 with ILongKeyPartOp

use of com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp in project angel by Tencent.

the class SampleNeighborWithType method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    PartSampleNeighborWithTypeParam sampleParam = (PartSampleNeighborWithTypeParam) partParam;
    ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, partParam);
    ILongKeyPartOp split = (ILongKeyPartOp) sampleParam.getIndicesPart();
    long[] nodeIds = split.getKeys();
    SampleType sampleType = sampleParam.getSampleType();
    switch(sampleType) {
        case NODE:
        case EDGE:
            {
                Tuple2<Long2ObjectOpenHashMap<long[]>, Long2ObjectOpenHashMap<int[]>> nodeId2SampleNeighbors = SampleUtils.sampleWithType(row, sampleParam.getCount(), nodeIds, sampleType, System.currentTimeMillis());
                return new PartSampleNeighborResultWithType(sampleParam.getPartKey().getPartitionId(), nodeId2SampleNeighbors._1, nodeId2SampleNeighbors._2, sampleType);
            }
        case NODE_AND_EDGE:
            {
                Tuple3<Long2ObjectOpenHashMap<long[]>, Long2ObjectOpenHashMap<int[]>, Long2ObjectOpenHashMap<int[]>> nodeId2SampleNeighbors = SampleUtils.sampleWithBothType(row, sampleParam.getCount(), nodeIds, System.currentTimeMillis());
                return new PartSampleNeighborResultWithType(sampleParam.getPartKey().getPartitionId(), nodeId2SampleNeighbors._1(), nodeId2SampleNeighbors._2(), nodeId2SampleNeighbors._3());
            }
        default:
            {
                throw new UnsupportedOperationException("Not support sample type " + sampleType + " now");
            }
    }
}
Also used : Tuple2(scala.Tuple2) Tuple3(scala.Tuple3) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) ILongKeyPartOp(com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp)

Example 3 with ILongKeyPartOp

use of com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp in project angel by Tencent.

the class Sample method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    PartSampleParam param = (PartSampleParam) partParam;
    KeyPart keyPart = param.getIndicesPart();
    int sampleType = param.getSampleType();
    long[] nodeIds = ((ILongKeyPartOp) keyPart).getKeys();
    Long2IntOpenHashMap nodeIdToSizes = new Long2IntOpenHashMap(nodeIds.length);
    for (int i = 0; i < nodeIds.length; i++) {
        nodeIdToSizes.addTo(nodeIds[i], 1);
    }
    ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
    Random r = new Random();
    long[] distinctNodeIds = new long[nodeIdToSizes.size()];
    long[][] samples = new long[nodeIdToSizes.size()][];
    ObjectIterator<Entry> iter = nodeIdToSizes.long2IntEntrySet().fastIterator();
    int index = 0;
    while (iter.hasNext()) {
        Entry entry = iter.next();
        distinctNodeIds[index] = entry.getLongKey();
        TypeNeighborElement element = (TypeNeighborElement) row.get(distinctNodeIds[index]);
        samples[index] = element.Sample(sampleType, r, distinctNodeIds[index], entry.getIntValue());
        index++;
    }
    return new PartGetLongsResult(distinctNodeIds, samples);
}
Also used : Long2IntOpenHashMap(it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap) 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) TypeNeighborElement(com.tencent.angel.graph.model.neighbor.simplewithtype.TypeNeighborElement) Entry(it.unimi.dsi.fastutil.longs.Long2IntMap.Entry) Random(java.util.Random) PartGetLongsResult(com.tencent.angel.graph.common.psf.result.PartGetLongsResult)

Example 4 with ILongKeyPartOp

use of com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp in project angel by Tencent.

the class InitHyperLogLog method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    InitHyperLogLogPartParam param = (InitHyperLogLogPartParam) partParam;
    ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
    // Get nodes and features
    ILongKeyPartOp split = (ILongKeyPartOp) param.getNodes();
    long[] nodes = split.getKeys();
    int p = param.getP();
    int sp = param.getSp();
    long seed = param.getSeed();
    row.startWrite();
    try {
        for (int i = 0; i < nodes.length; i++) {
            row.set(nodes[i], new HyperLogLogPlusElement(nodes[i], p, sp, seed));
        }
    } finally {
        row.endWrite();
    }
}
Also used : ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) ILongKeyPartOp(com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp)

Example 5 with ILongKeyPartOp

use of com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp in project angel by Tencent.

the class GetClosenessAndCardinality method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    GetHyperLogLogPartParam param = (GetHyperLogLogPartParam) partParam;
    ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
    ILongKeyPartOp keyPart = (ILongKeyPartOp) param.getNodes();
    long[] nodes = keyPart.getKeys();
    long n = param.getN();
    boolean isDirected = param.isDirected();
    Long2ObjectOpenHashMap<Tuple3<Double, Long, Long>> closenesses = new Long2ObjectOpenHashMap<>();
    for (int i = 0; i < nodes.length; i++) {
        HyperLogLogPlusElement hllElem = (HyperLogLogPlusElement) row.get(nodes[i]);
        if (isDirected) {
            if (hllElem.getCloseness() < n) {
                closenesses.put(nodes[i], new Tuple3<>(0d, hllElem.getCardinality(), hllElem.getCloseness()));
            } else {
                closenesses.put(nodes[i], new Tuple3<>(((double) n / (double) hllElem.getCloseness()), hllElem.getCardinality(), hllElem.getCloseness()));
            }
        } else {
            closenesses.put(nodes[i], new Tuple3<>(((double) hllElem.getCardinality() / (double) hllElem.getCloseness()), hllElem.getCardinality(), hllElem.getCloseness()));
        }
    }
    return new GetClosenessAndCardinalityPartResult(closenesses);
}
Also used : Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) ILongKeyPartOp(com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp) Tuple3(scala.Tuple3)

Aggregations

ILongKeyPartOp (com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp)11 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)9 KeyPart (com.tencent.angel.psagent.matrix.transport.router.KeyPart)3 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)3 Tuple3 (scala.Tuple3)2 HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)1 DynamicLongArray (com.tencent.angel.common.collections.DynamicLongArray)1 AngelException (com.tencent.angel.exception.AngelException)1 PartGetLongsResult (com.tencent.angel.graph.common.psf.result.PartGetLongsResult)1 PartGeneralGetResult (com.tencent.angel.graph.model.general.get.PartGeneralGetResult)1 TypeNeighborElement (com.tencent.angel.graph.model.neighbor.simplewithtype.TypeNeighborElement)1 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)1 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)1 GeneralPartGetParam (com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam)1 ServerLongIntRow (com.tencent.angel.ps.storage.vector.ServerLongIntRow)1 IElement (com.tencent.angel.ps.storage.vector.element.IElement)1 ValuePart (com.tencent.angel.psagent.matrix.transport.router.ValuePart)1 IIntKeyPartOp (com.tencent.angel.psagent.matrix.transport.router.operator.IIntKeyPartOp)1 DoubleValuesPart (com.tencent.angel.psagent.matrix.transport.router.value.DoubleValuesPart)1 FloatValuesPart (com.tencent.angel.psagent.matrix.transport.router.value.FloatValuesPart)1