Search in sources :

Example 36 with ObjectIterator

use of it.unimi.dsi.fastutil.objects.ObjectIterator in project angel by Tencent.

the class IntIntVector method argmin.

public int argmin() {
    IntIntVectorStorage idstorage = (IntIntVectorStorage) storage;
    if (idstorage.size() == 0)
        return -1;
    int minval = Integer.MAX_VALUE;
    int minidx = -1;
    if (idstorage.isDense()) {
        int[] val = idstorage.getValues();
        int length = val.length;
        for (int idx = 0; idx < length; idx++) {
            if (val[idx] < minval) {
                minval = val[idx];
                minidx = idx;
            }
        }
    } else if (idstorage.isSparse()) {
        ObjectIterator<Int2IntMap.Entry> iter = idstorage.entryIterator();
        while (iter.hasNext()) {
            Int2IntMap.Entry entry = iter.next();
            int idx = entry.getIntKey();
            int val = entry.getIntValue();
            if (val < minval) {
                minval = val;
                minidx = idx;
            }
        }
    } else {
        int[] indices = idstorage.getIndices();
        int[] val = idstorage.getValues();
        int size = idstorage.size();
        for (int i = 0; i < size; i++) {
            int idx = indices[i];
            if (val[i] < minval) {
                minval = val[i];
                minidx = idx;
            }
        }
    }
    return minidx;
}
Also used : IntIntVectorStorage(com.tencent.angel.ml.math2.storage.IntIntVectorStorage) Int2IntMap(it.unimi.dsi.fastutil.ints.Int2IntMap) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator)

Example 37 with ObjectIterator

use of it.unimi.dsi.fastutil.objects.ObjectIterator in project angel by Tencent.

the class IntLongVector method argmax.

public int argmax() {
    IntLongVectorStorage idstorage = (IntLongVectorStorage) storage;
    if (idstorage.size() == 0)
        return -1;
    long maxval = Long.MIN_VALUE;
    int maxidx = -1;
    if (idstorage.isDense()) {
        long[] val = idstorage.getValues();
        int length = val.length;
        for (int idx = 0; idx < length; idx++) {
            if (val[idx] > maxval) {
                maxval = val[idx];
                maxidx = idx;
            }
        }
    } else if (idstorage.isSparse()) {
        ObjectIterator<Int2LongMap.Entry> iter = idstorage.entryIterator();
        while (iter.hasNext()) {
            Int2LongMap.Entry entry = iter.next();
            int idx = entry.getIntKey();
            long val = entry.getLongValue();
            if (val > maxval) {
                maxval = val;
                maxidx = idx;
            }
        }
    } else {
        int[] indices = idstorage.getIndices();
        long[] val = idstorage.getValues();
        int size = idstorage.size();
        for (int i = 0; i < size; i++) {
            int idx = indices[i];
            if (val[i] > maxval) {
                maxval = val[i];
                maxidx = idx;
            }
        }
    }
    return maxidx;
}
Also used : IntLongVectorStorage(com.tencent.angel.ml.math2.storage.IntLongVectorStorage) Int2LongMap(it.unimi.dsi.fastutil.ints.Int2LongMap) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator)

Example 38 with ObjectIterator

use of it.unimi.dsi.fastutil.objects.ObjectIterator in project angel by Tencent.

the class SnapshotFormat method save.

private void save(ServerLongLongRow row, PSMatrixSaveContext saveContext, MatrixPartitionMeta meta, DataOutputStream out) throws IOException {
    long startCol = meta.getStartCol();
    if (ServerRowUtils.getVector(row) instanceof IntLongVector) {
        IntLongVector vector = (IntLongVector) ServerRowUtils.getVector(row);
        if (vector.isDense()) {
            long[] data = vector.getStorage().getValues();
            for (int i = 0; i < data.length; i++) {
                out.writeLong(data[i]);
            }
        } else if (vector.isSorted()) {
            int[] indices = vector.getStorage().getIndices();
            long[] values = vector.getStorage().getValues();
            for (int i = 0; i < indices.length; i++) {
                out.writeLong(indices[i] + startCol);
                out.writeLong(values[i]);
            }
        } else {
            ObjectIterator<Int2LongMap.Entry> iter = vector.getStorage().entryIterator();
            Int2LongMap.Entry entry;
            while (iter.hasNext()) {
                entry = iter.next();
                out.writeLong(entry.getIntKey() + startCol);
                out.writeLong(entry.getLongValue());
            }
        }
    } else {
        LongLongVector vector = (LongLongVector) ServerRowUtils.getVector(row);
        if (vector.isSorted()) {
            long[] indices = vector.getStorage().getIndices();
            long[] values = vector.getStorage().getValues();
            for (int i = 0; i < indices.length; i++) {
                out.writeLong(indices[i] + startCol);
                out.writeLong(values[i]);
            }
        } else {
            ObjectIterator<Long2LongMap.Entry> iter = vector.getStorage().entryIterator();
            Long2LongMap.Entry entry;
            while (iter.hasNext()) {
                entry = iter.next();
                out.writeLong(entry.getLongKey() + startCol);
                out.writeLong(entry.getLongValue());
            }
        }
    }
}
Also used : IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) Long2LongMap(it.unimi.dsi.fastutil.longs.Long2LongMap) LongLongVector(com.tencent.angel.ml.math2.vector.LongLongVector) Int2LongMap(it.unimi.dsi.fastutil.ints.Int2LongMap) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator)

Example 39 with ObjectIterator

use of it.unimi.dsi.fastutil.objects.ObjectIterator in project angel by Tencent.

the class SnapshotFormat method save.

private void save(ServerIntFloatRow row, PSMatrixSaveContext saveContext, MatrixPartitionMeta meta, DataOutputStream out) throws IOException {
    int startCol = (int) meta.getStartCol();
    IntFloatVector vector = ServerRowUtils.getVector(row);
    if (vector.isDense()) {
        float[] data = vector.getStorage().getValues();
        for (int i = 0; i < data.length; i++) {
            out.writeFloat(data[i]);
        }
    } else if (vector.isSorted()) {
        int[] indices = vector.getStorage().getIndices();
        float[] values = vector.getStorage().getValues();
        for (int i = 0; i < indices.length; i++) {
            out.writeInt(indices[i] + startCol);
            out.writeFloat(values[i]);
        }
    } else {
        ObjectIterator<Int2FloatMap.Entry> iter = vector.getStorage().entryIterator();
        Int2FloatMap.Entry entry;
        while (iter.hasNext()) {
            entry = iter.next();
            out.writeInt(entry.getIntKey() + startCol);
            out.writeFloat(entry.getFloatValue());
        }
    }
}
Also used : Int2FloatMap(it.unimi.dsi.fastutil.ints.Int2FloatMap) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator)

Example 40 with ObjectIterator

use of it.unimi.dsi.fastutil.objects.ObjectIterator in project angel by Tencent.

the class ComplexRowFormat method save.

private void save(ServerIntAnyRow row, PSMatrixSaveContext saveContext, MatrixPartitionMeta partMeta, DataOutputStream output) throws IOException {
    IntElementStorage storage = row.getStorage();
    long startPos = partMeta.getStartCol();
    if (storage instanceof IntArrayElementStorage) {
        IElement[] data = ((IntArrayElementStorage) storage).getData();
        for (int i = 0; i < data.length; i++) {
            save(i + startPos, data[i], output);
        }
    } else if (storage instanceof IntElementMapStorage) {
        Int2ObjectOpenHashMap<IElement> data = ((IntElementMapStorage) storage).getData();
        ObjectIterator<Int2ObjectMap.Entry<IElement>> iter = data.int2ObjectEntrySet().fastIterator();
        while (iter.hasNext()) {
            Int2ObjectMap.Entry<IElement> entry = iter.next();
            save(entry.getIntKey() + startPos, entry.getValue(), output);
        }
    }
}
Also used : Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) IElement(com.tencent.angel.ps.storage.vector.element.IElement) Entry(java.util.Map.Entry) IntArrayElementStorage(com.tencent.angel.ps.storage.vector.storage.IntArrayElementStorage) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) IntElementMapStorage(com.tencent.angel.ps.storage.vector.storage.IntElementMapStorage) IntElementStorage(com.tencent.angel.ps.storage.vector.storage.IntElementStorage) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator)

Aggregations

ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)254 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)115 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)114 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)111 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)110 AngelException (com.tencent.angel.exception.AngelException)100 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)100 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)99 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)98 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)97 Storage (com.tencent.angel.ml.math2.storage.Storage)96 Int2FloatMap (it.unimi.dsi.fastutil.ints.Int2FloatMap)62 Int2LongMap (it.unimi.dsi.fastutil.ints.Int2LongMap)57 Int2DoubleMap (it.unimi.dsi.fastutil.ints.Int2DoubleMap)56 Int2IntMap (it.unimi.dsi.fastutil.ints.Int2IntMap)55 IntDoubleVector (com.tencent.angel.ml.math2.vector.IntDoubleVector)47 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)44 LongDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSortedVectorStorage)44 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)43 LongFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSortedVectorStorage)43