Search in sources :

Example 11 with IntLongVector

use of com.tencent.angel.ml.math2.vector.IntLongVector 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 12 with IntLongVector

use of com.tencent.angel.ml.math2.vector.IntLongVector in project angel by Tencent.

the class SnapshotFormat method save.

private void save(ServerIntLongRow row, PSMatrixSaveContext saveContext, MatrixPartitionMeta meta, DataOutputStream out) throws IOException {
    int startCol = (int) meta.getStartCol();
    IntLongVector vector = 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.writeInt(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.writeInt(entry.getIntKey() + startCol);
            out.writeLong(entry.getLongValue());
        }
    }
}
Also used : IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) Int2LongMap(it.unimi.dsi.fastutil.ints.Int2LongMap) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator)

Example 13 with IntLongVector

use of com.tencent.angel.ml.math2.vector.IntLongVector in project angel by Tencent.

the class BlasFloatMatrix method setRow.

public Matrix setRow(int i, Vector v) {
    if (v instanceof IntFloatVector) {
        float[] rowData;
        if (v.isDense()) {
            rowData = ((IntFloatVector) v).getStorage().getValues();
        } else if (v.isSparse()) {
            rowData = new float[numCols];
            ObjectIterator<Int2FloatMap.Entry> iter = ((IntFloatVector) v).getStorage().entryIterator();
            while (iter.hasNext()) {
                Int2FloatMap.Entry entry = iter.next();
                int j = entry.getIntKey();
                rowData[j] = entry.getFloatValue();
            }
        } else {
            // sorted
            rowData = new float[numCols];
            int[] idxs = ((IntFloatVector) v).getStorage().getIndices();
            float[] values = ((IntFloatVector) v).getStorage().getValues();
            int size = ((IntFloatVector) v).size();
            for (int k = 0; k < size; k++) {
                int j = idxs[k];
                rowData[j] = values[k];
            }
        }
        System.arraycopy(rowData, 0, data, i * numCols, numCols);
    } else if (v instanceof IntLongVector) {
        long[] rowData;
        if (v.isDense()) {
            rowData = ((IntLongVector) v).getStorage().getValues();
        } else if (v.isSparse()) {
            rowData = new long[numCols];
            ObjectIterator<Int2LongMap.Entry> iter = ((IntLongVector) v).getStorage().entryIterator();
            while (iter.hasNext()) {
                Int2LongMap.Entry entry = iter.next();
                int j = entry.getIntKey();
                rowData[j] = entry.getLongValue();
            }
        } else {
            // sorted
            rowData = new long[numCols];
            int[] idxs = ((IntLongVector) v).getStorage().getIndices();
            long[] values = ((IntLongVector) v).getStorage().getValues();
            int size = ((IntLongVector) v).size();
            for (int k = 0; k < size; k++) {
                int j = idxs[k];
                rowData[j] = values[k];
            }
        }
        for (int j = 0; j < numCols; j++) {
            data[i * numCols + j] = rowData[j];
        }
    } else if (v instanceof IntIntVector) {
        int[] rowData;
        if (v.isDense()) {
            rowData = ((IntIntVector) v).getStorage().getValues();
        } else if (v.isSparse()) {
            rowData = new int[numCols];
            ObjectIterator<Int2IntMap.Entry> iter = ((IntIntVector) v).getStorage().entryIterator();
            while (iter.hasNext()) {
                Int2IntMap.Entry entry = iter.next();
                int j = entry.getIntKey();
                rowData[j] = entry.getIntValue();
            }
        } else {
            // sorted
            rowData = new int[numCols];
            int[] idxs = ((IntIntVector) v).getStorage().getIndices();
            int[] values = ((IntIntVector) v).getStorage().getValues();
            int size = ((IntIntVector) v).size();
            for (int k = 0; k < size; k++) {
                int j = idxs[k];
                rowData[j] = values[k];
            }
        }
        for (int j = 0; j < numCols; j++) {
            data[i * numCols + j] = rowData[j];
        }
    } else if (v instanceof IntDummyVector) {
        int[] rowData = new int[numCols];
        int[] idxs = ((IntDummyVector) v).getIndices();
        int size = ((IntDummyVector) v).size();
        for (int k = 0; k < size; k++) {
            int j = idxs[k];
            rowData[j] = 1;
        }
        for (int j = 0; j < numCols; j++) {
            data[i * numCols + j] = rowData[j];
        }
    } else {
        throw new AngelException("The operation is not supported!");
    }
    return this;
}
Also used : IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) AngelException(com.tencent.angel.exception.AngelException) IntIntVector(com.tencent.angel.ml.math2.vector.IntIntVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator) IntDummyVector(com.tencent.angel.ml.math2.vector.IntDummyVector) Int2FloatMap(it.unimi.dsi.fastutil.ints.Int2FloatMap) Int2LongMap(it.unimi.dsi.fastutil.ints.Int2LongMap) Int2IntMap(it.unimi.dsi.fastutil.ints.Int2IntMap)

Example 14 with IntLongVector

use of com.tencent.angel.ml.math2.vector.IntLongVector in project angel by Tencent.

the class RBCompIntLongMatrix method initEmpty.

@Override
public void initEmpty(int idx) {
    int numComp = (int) ((getDim() + subDim - 1) / subDim);
    if (null == rows[idx]) {
        IntLongVector[] tmpParts = new IntLongVector[numComp];
        for (int i = 0; i < numComp; i++) {
            IntLongSparseVectorStorage storage = new IntLongSparseVectorStorage(subDim);
            tmpParts[i] = new IntLongVector(matrixId, idx, clock, (int) getDim(), storage);
        }
        CompIntLongVector tmpVect = new CompIntLongVector(matrixId, idx, clock, (int) getDim(), tmpParts, subDim);
        rows[idx] = tmpVect;
    }
}
Also used : CompIntLongVector(com.tencent.angel.ml.math2.vector.CompIntLongVector) IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) IntLongSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntLongSparseVectorStorage) CompIntLongVector(com.tencent.angel.ml.math2.vector.CompIntLongVector)

Example 15 with IntLongVector

use of com.tencent.angel.ml.math2.vector.IntLongVector in project angel by Tencent.

the class RBCompIntLongMatrix method diag.

@Override
public Vector diag() {
    long[] resArr = new long[rows.length];
    for (int i = 0; i < rows.length; i++) {
        if (null == rows[i]) {
            resArr[i] = 0;
        } else {
            resArr[i] = rows[i].get(i);
        }
    }
    IntLongDenseVectorStorage storage = new IntLongDenseVectorStorage(resArr);
    return new IntLongVector(getMatrixId(), 0, getClock(), resArr.length, storage);
}
Also used : CompIntLongVector(com.tencent.angel.ml.math2.vector.CompIntLongVector) IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) IntLongDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntLongDenseVectorStorage)

Aggregations

ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)55 Int2LongMap (it.unimi.dsi.fastutil.ints.Int2LongMap)52 IntLongVector (com.tencent.angel.ml.math2.vector.IntLongVector)47 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)45 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)33 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)33 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)32 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)30 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)30 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)30 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)30 Storage (com.tencent.angel.ml.math2.storage.Storage)30 IntLongSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntLongSparseVectorStorage)25 CompIntLongVector (com.tencent.angel.ml.math2.vector.CompIntLongVector)25 IntLongSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntLongSortedVectorStorage)24 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)21 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)21 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)20 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)20 IntIntSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage)20