Search in sources :

Example 16 with TVector

use of com.tencent.angel.ml.math.TVector in project angel by Tencent.

the class RowSplitCombineUtils method combineServerDenseFloatRowSplits.

private static TVector combineServerDenseFloatRowSplits(List<ServerRow> rowSplits, MatrixMeta matrixMeta, int rowIndex) {
    int colNum = (int) matrixMeta.getColNum();
    float[] dataArray = new float[colNum];
    Collections.sort(rowSplits, serverRowComp);
    int clock = Integer.MAX_VALUE;
    int size = rowSplits.size();
    for (int i = 0; i < size; i++) {
        if (rowSplits.get(i).getClock() < clock) {
            clock = rowSplits.get(i).getClock();
        }
        ((ServerDenseFloatRow) rowSplits.get(i)).mergeTo(dataArray);
    }
    TVector row = new DenseFloatVector(colNum, dataArray);
    row.setMatrixId(matrixMeta.getId());
    row.setRowId(rowIndex);
    row.setClock(clock);
    return row;
}
Also used : TVector(com.tencent.angel.ml.math.TVector)

Example 17 with TVector

use of com.tencent.angel.ml.math.TVector in project angel by Tencent.

the class RowSplitCombineUtils method combineServerSparseDoubleRowSplits.

private static TVector combineServerSparseDoubleRowSplits(List<ServerRow> rowSplits, MatrixMeta matrixMeta, int rowIndex) {
    int colNum = (int) matrixMeta.getColNum();
    int splitNum = rowSplits.size();
    int totalElemNum = 0;
    int[] lens = new int[splitNum];
    Collections.sort(rowSplits, serverRowComp);
    int elemNum = 0;
    for (int i = 0; i < splitNum; i++) {
        elemNum = rowSplits.get(i).size();
        totalElemNum += elemNum;
        lens[i] = elemNum;
    }
    int[] indexes = new int[totalElemNum];
    double[] values = new double[totalElemNum];
    int clock = Integer.MAX_VALUE;
    int startPos = 0;
    for (int i = 0; i < splitNum; i++) {
        if (rowSplits.get(i).getClock() < clock) {
            clock = rowSplits.get(i).getClock();
        }
        ((ServerSparseDoubleRow) rowSplits.get(i)).mergeTo(indexes, values, startPos, lens[i]);
        startPos += lens[i];
    }
    TVector row = new SparseDoubleVector(colNum, indexes, values);
    row.setMatrixId(matrixMeta.getId());
    row.setRowId(rowIndex);
    row.setClock(clock);
    return row;
}
Also used : TVector(com.tencent.angel.ml.math.TVector)

Example 18 with TVector

use of com.tencent.angel.ml.math.TVector in project angel by Tencent.

the class RowSplitCombineUtils method combineServerSparseDoubleLongKeyRowSplits.

private static TVector combineServerSparseDoubleLongKeyRowSplits(List<ServerRow> rowSplits, MatrixMeta matrixMeta, int rowIndex) {
    int colNum = (int) matrixMeta.getColNum();
    int splitNum = rowSplits.size();
    int totalElemNum = 0;
    int[] lens = new int[splitNum];
    Collections.sort(rowSplits, serverRowComp);
    int elemNum = 0;
    for (int i = 0; i < splitNum; i++) {
        elemNum = rowSplits.get(i).size();
        totalElemNum += elemNum;
        lens[i] = elemNum;
    }
    long[] indexes = new long[totalElemNum];
    double[] values = new double[totalElemNum];
    int clock = Integer.MAX_VALUE;
    int startPos = 0;
    for (int i = 0; i < splitNum; i++) {
        if (rowSplits.get(i).getClock() < clock) {
            clock = rowSplits.get(i).getClock();
        }
        ((ServerSparseDoubleLongKeyRow) rowSplits.get(i)).mergeTo(indexes, values, startPos, lens[i]);
        startPos += lens[i];
    }
    TVector row = new SparseLongKeyDoubleVector(colNum, indexes, values);
    row.setMatrixId(matrixMeta.getId());
    row.setRowId(rowIndex);
    row.setClock(clock);
    return row;
}
Also used : TVector(com.tencent.angel.ml.math.TVector)

Example 19 with TVector

use of com.tencent.angel.ml.math.TVector in project angel by Tencent.

the class RowSplitCombineUtils method combineDenseDoubleRowSplits.

private static TVector combineDenseDoubleRowSplits(GetRowPipelineCache pipelineCache, MatrixMeta matrixMeta, int rowIndex) throws InterruptedException {
    int colNum = (int) matrixMeta.getColNum();
    double[] dataArray = new double[colNum];
    int clock = Integer.MAX_VALUE;
    while (true) {
        ServerRow split = pipelineCache.poll();
        if (split == null) {
            TVector row = new DenseDoubleVector(colNum, dataArray);
            row.setClock(clock);
            row.setMatrixId(matrixMeta.getId());
            row.setRowId(rowIndex);
            return row;
        }
        if (split.getClock() < clock) {
            clock = split.getClock();
        }
        ((ServerDenseDoubleRow) split).mergeTo(dataArray);
    }
}
Also used : TVector(com.tencent.angel.ml.math.TVector)

Example 20 with TVector

use of com.tencent.angel.ml.math.TVector in project angel by Tencent.

the class RowSplitCombineUtils method combineDenseIntRowSplits.

private static TVector combineDenseIntRowSplits(GetRowPipelineCache pipelineCache, MatrixMeta matrixMeta, int rowIndex) throws InterruptedException {
    int colNum = (int) matrixMeta.getColNum();
    int[] dataArray = new int[colNum];
    int clock = Integer.MAX_VALUE;
    while (true) {
        ServerRow split = pipelineCache.poll();
        if (split == null) {
            TVector row = new DenseIntVector(colNum, dataArray);
            row.setMatrixId(matrixMeta.getId());
            row.setRowId(rowIndex);
            row.setClock(clock);
            return row;
        }
        if (split.getClock() < clock) {
            clock = split.getClock();
        }
        ((ServerDenseIntRow) split).mergeTo(dataArray);
    }
}
Also used : TVector(com.tencent.angel.ml.math.TVector)

Aggregations

TVector (com.tencent.angel.ml.math.TVector)26 MatrixClient (com.tencent.angel.psagent.matrix.MatrixClient)6 Test (org.junit.Test)6 IOException (java.io.IOException)4 AngelException (com.tencent.angel.exception.AngelException)3 DenseDoubleVector (com.tencent.angel.ml.math.vector.DenseDoubleVector)3 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)3 MatrixStorage (com.tencent.angel.psagent.matrix.storage.MatrixStorage)3 GetRowsResult (com.tencent.angel.psagent.matrix.transport.adapter.GetRowsResult)3 PartitionKey (com.tencent.angel.PartitionKey)2 MasterServiceTest (com.tencent.angel.master.MasterServiceTest)2 DenseIntVector (com.tencent.angel.ml.math.vector.DenseIntVector)2 GetRowsFunc (com.tencent.angel.ml.matrix.psf.get.multi.GetRowsFunc)2 GetRowsParam (com.tencent.angel.ml.matrix.psf.get.multi.GetRowsParam)2 GetRowResult (com.tencent.angel.ml.matrix.psf.get.single.GetRowResult)2 RowIndex (com.tencent.angel.psagent.matrix.transport.adapter.RowIndex)2 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)2 Utils.genSparseFloatVector (com.tencent.angel.ml.Utils.genSparseFloatVector)1