Search in sources :

Example 11 with IntDoubleVector

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

the class SnapshotFormat method save.

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

Example 12 with IntDoubleVector

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

the class ColumnFormat method saveIntDoubleRows.

private void saveIntDoubleRows(ServerPartition part, ServerRow[] rows, MatrixPartitionMeta partMeta, PSMatrixSaveContext saveContext, DataOutputStream output) throws IOException {
    Vector vec = ServerRowUtils.getVector((ServerIntDoubleRow) rows[0]);
    // int size = rows.length;
    int indexOffset = (int) part.getPartitionKey().getStartCol();
    IntDoubleVectorStorage storage = ((IntDoubleVector) vec).getStorage();
    IntDoublesCol col = new IntDoublesCol(0, new double[rows.length]);
    int startCol = (int) rows[0].getStartCol();
    int endCol = (int) rows[0].getEndCol();
    if (storage.isDense()) {
        for (int i = startCol; i < endCol; i++) {
            col.colId = i;
            for (int j = 0; j < rows.length; j++) {
                col.colElems[j] = ((ServerIntDoubleRow) (rows[j])).get(col.colId);
            }
            save(col, output);
        }
    } else {
        if (saveContext.sortFirst()) {
            int[] indices = storage.getIndices();
            Sort.quickSort(indices, 0, indices.length - 1);
            for (int i = 0; i < indices.length; i++) {
                col.colId = indices[i] + indexOffset;
                for (int j = 0; j < rows.length; j++) {
                    col.colElems[j] = ((ServerIntDoubleRow) (rows[j])).get(col.colId);
                }
                save(col, output);
            }
        } else {
            ObjectIterator<Int2DoubleMap.Entry> iter = storage.entryIterator();
            while (iter.hasNext()) {
                col.colId = iter.next().getIntKey() + indexOffset;
                for (int j = 0; j < rows.length; j++) {
                    col.colElems[j] = ((ServerIntDoubleRow) (rows[j])).get(col.colId);
                }
                save(col, output);
            }
        }
    }
}
Also used : Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 13 with IntDoubleVector

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

the class ColumnFormat method saveLongDoubleRows.

private void saveLongDoubleRows(ServerPartition part, ServerRow[] rows, MatrixPartitionMeta partMeta, PSMatrixSaveContext saveContext, DataOutputStream output) throws IOException {
    Vector vec = ServerRowUtils.getVector((ServerLongDoubleRow) rows[0]);
    // int size = rows.size();
    long indexOffset = part.getPartitionKey().getStartCol();
    LongDoublesCol col = new LongDoublesCol(0, new double[rows.length]);
    if (vec instanceof IntDoubleVector) {
        IntDoubleVectorStorage storage = ((IntDoubleVector) vec).getStorage();
        long startCol = rows[0].getStartCol();
        long endCol = rows[0].getEndCol();
        if (storage.isDense()) {
            for (long i = startCol; i < endCol; i++) {
                col.colId = i;
                for (int j = 0; j < rows.length; j++) {
                    col.colElems[j] = ((ServerLongDoubleRow) (rows[j])).get(col.colId);
                }
                save(col, output);
            }
        } else {
            if (saveContext.sortFirst()) {
                int[] indices = storage.getIndices();
                Sort.quickSort(indices, 0, indices.length - 1);
                for (int i = 0; i < indices.length; i++) {
                    col.colId = indices[i] + indexOffset;
                    for (int j = 0; j < rows.length; j++) {
                        col.colElems[j] = ((ServerLongDoubleRow) (rows[j])).get(col.colId);
                    }
                    save(col, output);
                }
            } else {
                ObjectIterator<Int2DoubleMap.Entry> iter = storage.entryIterator();
                while (iter.hasNext()) {
                    col.colId = iter.next().getIntKey() + indexOffset;
                    for (int j = 0; j < rows.length; j++) {
                        col.colElems[j] = ((ServerLongDoubleRow) (rows[j])).get(col.colId);
                    }
                    save(col, output);
                }
            }
        }
    } else {
        LongDoubleVectorStorage storage = ((LongDoubleVector) vec).getStorage();
        if (saveContext.sortFirst()) {
            long[] indices = storage.getIndices();
            Sort.quickSort(indices, 0, indices.length - 1);
            for (int i = 0; i < indices.length; i++) {
                col.colId = indices[i] + indexOffset;
                for (int j = 0; j < rows.length; j++) {
                    col.colElems[j] = ((ServerLongDoubleRow) (rows[j])).get(col.colId);
                }
                save(col, output);
            }
        } else {
            ObjectIterator<Long2DoubleMap.Entry> iter = storage.entryIterator();
            while (iter.hasNext()) {
                col.colId = iter.next().getLongKey() + indexOffset;
                for (int j = 0; j < rows.length; j++) {
                    col.colElems[j] = ((ServerLongDoubleRow) (rows[j])).get(col.colId);
                }
                save(col, output);
            }
        }
    }
}
Also used : Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 14 with IntDoubleVector

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

the class RBCompIntDoubleMatrix method diag.

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

Example 15 with IntDoubleVector

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

the class RBCompIntDoubleMatrix method initEmpty.

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

Aggregations

IntDoubleVector (com.tencent.angel.ml.math2.vector.IntDoubleVector)95 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)55 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)51 Int2DoubleMap (it.unimi.dsi.fastutil.ints.Int2DoubleMap)51 CompIntDoubleVector (com.tencent.angel.ml.math2.vector.CompIntDoubleVector)40 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)32 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)32 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)32 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)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 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)26 IntDoubleDenseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage)23 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)20 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)20 IntIntSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage)20 IntIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage)20