Search in sources :

Example 36 with ServerRow

use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.

the class MatrixUtils method getRow.

public static ServerRow getRow(MatrixStorageManager storageManager, int matrixId, int partId, int rowId) {
    ServerMatrix matrix = storageManager.getMatrix(matrixId);
    if (matrix == null) {
        throw new ObjectNotFoundException("Can not find matrix " + matrixId);
    }
    ServerPartition part = matrix.getPartition(partId);
    if (part == null) {
        throw new ObjectNotFoundException("Can not find partition " + partId + " of matrix " + matrixId);
    }
    if (!(part instanceof RowBasedPartition)) {
        throw new UnsupportedOperationException("Get row only support for RowBasedPartition");
    }
    ServerRow row = ((RowBasedPartition) part).getRow(rowId);
    if (row == null) {
        throw new ObjectNotFoundException("Can not find row " + rowId + " of matrix " + matrixId + " in partition " + partId);
    }
    return row;
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) ObjectNotFoundException(com.tencent.angel.ps.server.data.exception.ObjectNotFoundException) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition)

Example 37 with ServerRow

use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.

the class Add method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    PartIncrementRowsParam param = (PartIncrementRowsParam) partParam;
    List<RowUpdateSplit> updates = param.getUpdates();
    for (RowUpdateSplit update : updates) {
        ServerRow row = psContext.getMatrixStorageManager().getRow(param.getPartKey(), update.getRowId());
        row.startWrite();
        try {
            Vector vector = getVector(param.getMatrixId(), update.getRowId(), param.getPartKey());
            vector.iadd(update.getVector());
        } finally {
            row.endWrite();
        }
    }
}
Also used : PartIncrementRowsParam(com.tencent.angel.ml.matrix.psf.update.update.PartIncrementRowsParam) RowUpdateSplit(com.tencent.angel.psagent.matrix.oplog.cache.RowUpdateSplit) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 38 with ServerRow

use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.

the class Utils method pick.

public static ArrayList<Map.Entry<ServerRow, ArrayList<Integer>>> pick(ServerRow[] serverRows, Long[] rows, Long[] cols, Double[] values) {
    assert (rows.length == cols.length && rows.length == values.length);
    ArrayList<Map.Entry<ServerRow, ArrayList<Integer>>> result = new ArrayList<>();
    for (ServerRow row : serverRows) {
        long rowId = row.getRowId();
        long startCol = row.getStartCol();
        long endCol = row.getEndCol();
        ArrayList<Integer> indics = new ArrayList<Integer>();
        for (int i = 0; i <= rows.length; i++) {
            if (rowId == rows[i] && cols[i] >= startCol && cols[i] < endCol) {
                indics.add(i);
            }
        }
        Map.Entry<ServerRow, ArrayList<Integer>> pair = new java.util.AbstractMap.SimpleEntry<>(row, indics);
        result.add(pair);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) Map(java.util.Map)

Example 39 with ServerRow

use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.

the class LikelihoodFunc method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    PartitionKey pkey = partParam.getPartKey();
    pkey = psContext.getMatrixMetaManager().getMatrixMeta(pkey.getMatrixId()).getPartitionMeta(pkey.getPartitionId()).getPartitionKey();
    int ws = pkey.getStartRow();
    int es = pkey.getEndRow();
    if (partParam instanceof LikelihoodParam.LikelihoodPartParam) {
        LikelihoodParam.LikelihoodPartParam param = (LikelihoodParam.LikelihoodPartParam) partParam;
        float beta = param.getBeta();
        double lgammaBeta = Gamma.logGamma(beta);
        double ll = 0;
        for (int w = ws; w < es; w++) {
            ServerRow row = psContext.getMatrixStorageManager().getRow(pkey, w);
            try {
                row.startRead();
                ll += likelihood((ServerIntIntRow) row, beta, lgammaBeta);
            } finally {
                row.endRead();
            }
        }
        return new ScalarPartitionAggrResult(ll);
    } else {
        throw new AngelException("Should be LikelihoodParam.LikelihoodPartParam");
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) ScalarPartitionAggrResult(com.tencent.angel.ml.matrix.psf.aggr.enhance.ScalarPartitionAggrResult) PartitionKey(com.tencent.angel.PartitionKey) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) ServerIntIntRow(com.tencent.angel.ps.storage.vector.ServerIntIntRow)

Example 40 with ServerRow

use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.

the class ResetFunc method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    RowBasedPartition part = (RowBasedPartition) psContext.getMatrixStorageManager().getPart(partParam.getMatrixId(), partParam.getPartKey().getPartitionId());
    if (part != null) {
        int startRow = part.getPartitionKey().getStartRow();
        int endRow = part.getPartitionKey().getEndRow();
        for (int i = startRow; i < endRow; i++) {
            ServerRow row = part.getRow(i);
            if (row == null) {
                continue;
            }
            row.reset();
        // reset(row);
        }
    }
}
Also used : ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition)

Aggregations

ServerRow (com.tencent.angel.ps.storage.vector.ServerRow)42 Vector (com.tencent.angel.ml.math2.vector.Vector)13 RowBasedPartition (com.tencent.angel.ps.storage.partition.RowBasedPartition)6 PartIncrementRowsParam (com.tencent.angel.ml.matrix.psf.update.update.PartIncrementRowsParam)5 RowUpdateSplit (com.tencent.angel.psagent.matrix.oplog.cache.RowUpdateSplit)5 ArrayList (java.util.ArrayList)5 PartitionKey (com.tencent.angel.PartitionKey)4 ServerIntIntRow (com.tencent.angel.ps.storage.vector.ServerIntIntRow)4 AngelException (com.tencent.angel.exception.AngelException)2 FloatVector (com.tencent.angel.ml.math2.vector.FloatVector)2 RowType (com.tencent.angel.ml.matrix.RowType)2 PartitionGetRowsParam (com.tencent.angel.ml.matrix.psf.get.getrows.PartitionGetRowsParam)2 GetRowSplitResponse (com.tencent.angel.ps.server.data.response.GetRowSplitResponse)2 GetRowsSplitResponse (com.tencent.angel.ps.server.data.response.GetRowsSplitResponse)2 Response (com.tencent.angel.ps.server.data.response.Response)2 MatrixStorageManager (com.tencent.angel.ps.storage.MatrixStorageManager)2 ServerMatrix (com.tencent.angel.ps.storage.matrix.ServerMatrix)2 ServerPartition (com.tencent.angel.ps.storage.partition.ServerPartition)2 ServerRowsStorage (com.tencent.angel.ps.storage.partition.storage.ServerRowsStorage)2 KeyPart (com.tencent.angel.psagent.matrix.transport.router.KeyPart)2