Search in sources :

Example 86 with Storage

use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.

the class ColumnFormat method saveIntIntRows.

private void saveIntIntRows(ServerPartition part, ServerRow[] rows, MatrixPartitionMeta partMeta, PSMatrixSaveContext saveContext, DataOutputStream output) throws IOException {
    Vector vec = ServerRowUtils.getVector((ServerIntIntRow) rows[0]);
    // int size = rows.size();
    int indexOffset = (int) part.getPartitionKey().getStartCol();
    IntIntVectorStorage storage = ((IntIntVector) vec).getStorage();
    IntIntsCol col = new IntIntsCol(0, new int[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] = ((ServerIntIntRow) (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] = ((ServerIntIntRow) (rows[j])).get(col.colId);
                }
                save(col, output);
            }
        } else {
            ObjectIterator<Int2IntMap.Entry> iter = storage.entryIterator();
            while (iter.hasNext()) {
                col.colId = iter.next().getIntKey() + indexOffset;
                for (int j = 0; j < rows.length; j++) {
                    col.colElems[j] = ((ServerIntIntRow) (rows[j])).get(col.colId);
                }
                save(col, output);
            }
        }
    }
}
Also used : Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 87 with Storage

use of com.tencent.angel.ml.math2.storage.Storage 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 88 with Storage

use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.

the class RBCompLongFloatMatrix method initEmpty.

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

Example 89 with Storage

use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.

the class RBCompLongLongMatrix method initEmpty.

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

Example 90 with Storage

use of com.tencent.angel.ml.math2.storage.Storage 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);
}
Also used : LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) LongDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage) DoubleArrayList(it.unimi.dsi.fastutil.doubles.DoubleArrayList)

Aggregations

IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)187 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)186 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)185 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)183 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)182 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)181 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)180 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)180 Storage (com.tencent.angel.ml.math2.storage.Storage)169 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)139 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)123 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)123 LongFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage)121 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)119 LongDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSortedVectorStorage)119 LongDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage)119 LongIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongIntSparseVectorStorage)119 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)118 LongFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSortedVectorStorage)118 IntIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage)117