Search in sources :

Example 26 with Long2DoubleOpenHashMap

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

the class ModelLoader method loadSparseDoubleLongKeyPartition.

private static void loadSparseDoubleLongKeyPartition(SparseDoubleLongKeyModel model, FSDataInputStream input, ModelPartitionMeta partMeta) throws IOException {
    int rowNum = input.readInt();
    int rowId = 0;
    int nnz = 0;
    int totalNNZ = 0;
    Long2DoubleOpenHashMap row = null;
    for (int i = 0; i < rowNum; i++) {
        rowId = input.readInt();
        nnz = input.readInt();
        totalNNZ = (int) (nnz * (model.col) / (partMeta.getEndCol() - partMeta.getStartCol()));
        row = model.getRow(rowId, partMeta.getPartId(), totalNNZ);
        for (int j = 0; j < nnz; j++) {
            row.put(input.readLong(), input.readDouble());
        }
    }
}
Also used : Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap)

Example 27 with Long2DoubleOpenHashMap

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

the class ModelLoader method loadSparseDoubleLongKeyRowFromPartition.

public static Long2DoubleOpenHashMap loadSparseDoubleLongKeyRowFromPartition(FSDataInputStream input, ModelPartitionMeta partMeta, int rowId) throws IOException {
    RowOffset rowOffset = partMeta.getRowMetas().get(rowId);
    input.seek(rowOffset.getOffset());
    Preconditions.checkState(input.readInt() == rowId);
    int num = input.readInt();
    Long2DoubleOpenHashMap row = new Long2DoubleOpenHashMap();
    for (int j = 0; j < num; j++) {
        row.put(input.readLong(), input.readDouble());
    }
    return row;
}
Also used : RowOffset(com.tencent.angel.model.output.format.ModelPartitionMeta.RowOffset) Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap)

Example 28 with Long2DoubleOpenHashMap

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

the class SparseLongKeyDoubleVector method deserialize.

@Override
public void deserialize(ByteBuf buf) {
    int dim = buf.readInt();
    int length = buf.readInt();
    Long2DoubleOpenHashMap data = new Long2DoubleOpenHashMap(dim);
    IntStream.range(0, length).forEach(i -> data.put(buf.readLong(), buf.readDouble()));
    this.dim = dim;
    this.indexToValueMap = data;
}
Also used : Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap)

Example 29 with Long2DoubleOpenHashMap

use of it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap in project elki by elki-project.

the class FileBasedSparseDoubleDistanceFunction method loadCache.

/**
 * Fill cache from an input stream.
 *
 * @param size Expected size
 * @param in Input stream
 * @throws IOException
 */
protected void loadCache(int size, InputStream in) throws IOException {
    // Expect a sparse matrix here.
    cache = new Long2DoubleOpenHashMap(size * 20);
    cache.defaultReturnValue(Double.POSITIVE_INFINITY);
    min = Integer.MAX_VALUE;
    max = Integer.MIN_VALUE;
    parser.parse(in, new DistanceCacheWriter() {

        @Override
        public void put(int id1, int id2, double distance) {
            if (id1 < id2) {
                min = id1 < min ? id1 : min;
                max = id2 > max ? id2 : max;
            } else {
                min = id2 < min ? id2 : min;
                max = id1 > max ? id1 : max;
            }
            cache.put(makeKey(id1, id2), distance);
        }
    });
    if (min != 0 && LOG.isVerbose()) {
        LOG.verbose("Distance matrix is supposed to be 0-indexed. Choosing offset " + min + " to compensate.");
    }
    if (max + 1 - min != size) {
        LOG.warning("ID range is not consistent with relation size.");
    }
}
Also used : Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap)

Example 30 with Long2DoubleOpenHashMap

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

the class ModelMergeAndConvert method convertSparseDoubleLongKeyModel.

private static void convertSparseDoubleLongKeyModel(Configuration conf, FSDataOutputStream output, String modelInputDir, ModelLineConvert lineConvert) throws IOException {
    Long2DoubleOpenHashMap[] data = ModelLoader.loadToDoubleLongKeyMaps(modelInputDir, conf);
    for (int i = 0; i < data.length; i++) {
        Long2DoubleOpenHashMap row = data[i];
        data[i] = null;
        if (row == null) {
            continue;
        }
        lineConvert.convertRowIndex(output, i);
        long[] indexes = row.keySet().toLongArray();
        double[] values = row.values().toDoubleArray();
        row = null;
        Sort.quickSort(indexes, values, 0, indexes.length - 1);
        for (int j = 0; j < indexes.length; j++) {
            lineConvert.convertDoubleLongKey(output, indexes[j], values[j]);
        }
    }
}
Also used : Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap)

Aggregations

Long2DoubleOpenHashMap (it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap)59 Map (java.util.Map)29 LongSet (it.unimi.dsi.fastutil.longs.LongSet)7 ServerSparseDoubleLongKeyRow (com.tencent.angel.ps.impl.matrix.ServerSparseDoubleLongKeyRow)3 ArrayList (java.util.ArrayList)2 HyperLogLog (com.facebook.airlift.stats.cardinality.HyperLogLog)1 CommonParam (com.tencent.angel.ml.matrix.psf.common.CommonParam)1 PartitionGetResult (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)1 RowOffset (com.tencent.angel.model.output.format.ModelPartitionMeta.RowOffset)1 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)1 ILongKeyPartOp (com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp)1 Int2DoubleOpenHashMap (it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap)1 Int2FloatOpenHashMap (it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap)1 Int2IntOpenHashMap (it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)1 Long2DoubleMap (it.unimi.dsi.fastutil.longs.Long2DoubleMap)1 PrimitiveIterator (java.util.PrimitiveIterator)1 Configuration (org.apache.hadoop.conf.Configuration)1 Path (org.apache.hadoop.fs.Path)1