Search in sources :

Example 56 with Vector

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

the class ColumnFormat method saveLongIntRows.

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

Example 57 with Vector

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

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

use of com.tencent.angel.ml.math2.vector.Vector 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)

Example 60 with Vector

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

the class CsrFloatMatrix method getRow.

@Override
public Vector getRow(int idx) {
    IntArrayList cols = new IntArrayList();
    FloatArrayList data = new FloatArrayList();
    int rowNum = indptr.length - 1;
    assert (idx < rowNum);
    for (int i = indptr[idx]; i < indptr[idx + 1]; i++) {
        cols.add(indices[i]);
        data.add(values[i]);
    }
    IntFloatSparseVectorStorage storage = new IntFloatSparseVectorStorage(shape[1], cols.toIntArray(), data.toFloatArray());
    return new IntFloatVector(getMatrixId(), idx, getClock(), shape[1], storage);
}
Also used : IntFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage) FloatArrayList(it.unimi.dsi.fastutil.floats.FloatArrayList) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Aggregations

IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)189 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)188 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)188 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)186 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)185 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)183 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)183 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)182 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)170 Storage (com.tencent.angel.ml.math2.storage.Storage)169 LongDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage)127 LongFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage)125 LongLongSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongLongSparseVectorStorage)121 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)119 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)119 LongIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongIntSparseVectorStorage)119 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)118 LongDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSortedVectorStorage)118 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)117 LongFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSortedVectorStorage)117