Search in sources :

Example 16 with LongArrayList

use of it.unimi.dsi.fastutil.longs.LongArrayList in project angel by Tencent.

the class GetNodes method gatherNodes.

private long[] gatherNodes(LongFloatVector ranks, long offset) {
    if (ranks.getStorage().isSparse()) {
        ObjectIterator<Long2FloatMap.Entry> it = ranks.getStorage().entryIterator();
        LongArrayList ret = new LongArrayList();
        while (it.hasNext()) {
            Long2FloatMap.Entry entry = it.next();
            long key = entry.getLongKey();
            ret.add(key + offset);
        }
        return ret.toLongArray();
    } else {
        float[] vals = ranks.getStorage().getValues();
        LongArrayList ret = new LongArrayList();
        for (int i = 0; i < vals.length; i++) if (vals[i] != 0.0)
            ret.add(i + offset);
        return ret.toLongArray();
    }
}
Also used : Long2FloatMap(it.unimi.dsi.fastutil.longs.Long2FloatMap) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList)

Example 17 with LongArrayList

use of it.unimi.dsi.fastutil.longs.LongArrayList in project angel by Tencent.

the class GetNodes method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam param) {
    ServerLongAnyRow row = (ServerLongAnyRow) psContext.getMatrixStorageManager().getRow(param.getPartKey(), 0);
    ObjectIterator<Long2ObjectMap.Entry<IElement>> it = row.iterator();
    LongArrayList nodes = new LongArrayList();
    long start = param.getPartKey().getStartCol();
    while (it.hasNext()) {
        Long2ObjectMap.Entry entry = it.next();
        Node node = (Node) entry.getValue();
        if (node.getFeats() != null && node.getNeighbors() == null) {
            nodes.add(entry.getLongKey() + start);
        }
    }
    return new IndexPartGetLongResult(param.getPartKey(), nodes.toLongArray());
}
Also used : IndexPartGetLongResult(com.tencent.angel.ml.matrix.psf.get.indexed.IndexPartGetLongResult) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) Node(com.tencent.angel.graph.data.Node) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow)

Example 18 with LongArrayList

use of it.unimi.dsi.fastutil.longs.LongArrayList in project angel by Tencent.

the class GetLabels method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    GeneralPartGetParam param = (GeneralPartGetParam) partParam;
    KeyPart keyPart = param.getIndicesPart();
    switch(keyPart.getKeyType()) {
        case LONG:
            {
                // Long type node id
                long[] nodeIds = ((ILongKeyPartOp) keyPart).getKeys();
                ServerLongFloatRow row = (ServerLongFloatRow) psContext.getMatrixStorageManager().getRow(param.getPartKey(), 0);
                LongArrayList keys = new LongArrayList();
                FloatArrayList vals = new FloatArrayList();
                for (int i = 0; i < nodeIds.length; i++) {
                    if (row.exist(nodeIds[i])) {
                        keys.add(nodeIds[i]);
                        vals.add(row.get(nodeIds[i]));
                    }
                }
                return new GetLabelsPartResult(keys.toLongArray(), vals.toFloatArray());
            }
        default:
            {
                // TODO: support String, Int, and Any type node id
                throw new InvalidParameterException("Unsupport index type " + keyPart.getKeyType());
            }
    }
}
Also used : InvalidParameterException(com.tencent.angel.exception.InvalidParameterException) GeneralPartGetParam(com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) ServerLongFloatRow(com.tencent.angel.ps.storage.vector.ServerLongFloatRow) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) FloatArrayList(it.unimi.dsi.fastutil.floats.FloatArrayList)

Example 19 with LongArrayList

use of it.unimi.dsi.fastutil.longs.LongArrayList in project angel by Tencent.

the class CooLongDoubleMatrix method getRow.

@Override
public Vector getRow(int idx) {
    LongArrayList cols = new LongArrayList();
    DoubleArrayList data = new DoubleArrayList();
    for (int i = 0; i < rowIndices.length; i++) {
        if (rowIndices[i] == idx) {
            cols.add(colIndices[i]);
            data.add(values[i]);
        }
    }
    LongDoubleSparseVectorStorage storage = new LongDoubleSparseVectorStorage(shape[1], cols.toLongArray(), data.toDoubleArray());
    return new LongDoubleVector(getMatrixId(), idx, getClock(), shape[1], storage);
}
Also used : LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) LongDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage) DoubleArrayList(it.unimi.dsi.fastutil.doubles.DoubleArrayList)

Example 20 with LongArrayList

use of it.unimi.dsi.fastutil.longs.LongArrayList in project caffeine by ben-manes.

the class Simulator method broadcast.

/** Broadcast the trace events to all of the policy actors. */
private void broadcast() throws IOException {
    try (LongStream events = eventStream()) {
        LongArrayList batch = new LongArrayList(batchSize);
        for (PrimitiveIterator.OfLong i = events.iterator(); i.hasNext(); ) {
            batch.add(i.nextLong());
            if (batch.size() == batchSize) {
                router.route(batch, getSelf());
                batch = new LongArrayList(batchSize);
            }
        }
        router.route(batch, getSelf());
        router.route(Message.FINISH, getSelf());
    } catch (Exception e) {
        router.route(Message.ERROR, getSelf());
        context().system().log().error(e, "");
        getContext().stop(getSelf());
    }
}
Also used : PrimitiveIterator(java.util.PrimitiveIterator) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) LongStream(java.util.stream.LongStream) IOException(java.io.IOException)

Aggregations

LongArrayList (it.unimi.dsi.fastutil.longs.LongArrayList)37 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 IndexPartGetLongResult (com.tencent.angel.ml.matrix.psf.get.indexed.IndexPartGetLongResult)3 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)3 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)3 LongList (it.unimi.dsi.fastutil.longs.LongList)3 LongOpenHashSet (it.unimi.dsi.fastutil.longs.LongOpenHashSet)3 IOException (java.io.IOException)3 List (java.util.List)3 Block (com.facebook.presto.spi.block.Block)2 Type (com.facebook.presto.spi.type.Type)2 Supplier (com.google.common.base.Supplier)2 LongFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage)2 LongFloatVector (com.tencent.angel.ml.math2.vector.LongFloatVector)2 FloatArrayList (it.unimi.dsi.fastutil.floats.FloatArrayList)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 BinaryDecoder (co.cask.cdap.common.io.BinaryDecoder)1