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();
}
}
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());
}
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());
}
}
}
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);
}
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());
}
}
Aggregations