Search in sources :

Example 26 with TVector

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

the class CompSparseIntMatrixOpLog method split.

/**
 * Split the update according to the matrix partitions
 *
 * @param psUpdateData partition -> row split list map
 */
public void split(Map<PartitionKey, List<RowUpdateSplit>> psUpdateData) {
    long startTime = System.currentTimeMillis();
    MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    List<PartitionKey> partitions = PSAgentContext.get().getMatrixMetaManager().getPartitions(matrixId);
    int row = matrixMeta.getRowNum();
    for (int rowId = 0; rowId < row; rowId++) {
        TVector vector = getRow(rowId);
        if (vector == null)
            continue;
        // Filter it, removing zero values
        if (enableFilter && isNeedFilter(vector)) {
            vector = vector.filter(0.0);
        }
        // Doing average or not
        if (matrixMeta.isAverage()) {
            vector.timesBy(1.0 / PSAgentContext.get().getTotalTaskNum());
        }
        // Split this row according the matrix partitions
        Map<PartitionKey, RowUpdateSplit> splits = RowUpdateSplitUtils.split(vector, partitions);
        removeRow(rowId);
        // Add the splits to the result container
        for (Map.Entry<PartitionKey, RowUpdateSplit> entry : splits.entrySet()) {
            List<RowUpdateSplit> rowSplits = psUpdateData.get(entry.getKey());
            if (rowSplits == null) {
                rowSplits = new ArrayList<>();
                psUpdateData.put(entry.getKey(), rowSplits);
            }
            rowSplits.add(entry.getValue());
        }
    }
    LOG.debug("taking " + (System.currentTimeMillis() - startTime) + " ms to split logs for matrix=" + matrixId);
}
Also used : MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) PartitionKey(com.tencent.angel.PartitionKey) TVector(com.tencent.angel.ml.math.TVector) Map(java.util.Map)

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