use of com.tencent.angel.ml.matrix.MatrixMeta in project angel by Tencent.
the class LongKeysGetParam method split.
@Override
public List<PartitionGetParam> split() {
// Get matrix meta
MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
PartitionKey[] parts = meta.getPartitionKeys();
// Split
KeyPart[] nodeIdsParts = RouterUtils.split(meta, 0, nodeIds, false);
// Generate Part psf get param
List<PartitionGetParam> partParams = new ArrayList<>(parts.length);
assert parts.length == nodeIdsParts.length;
for (int i = 0; i < parts.length; i++) {
if (nodeIdsParts[i] != null && nodeIdsParts[i].size() > 0) {
partParams.add(new GeneralPartGetParam(matrixId, parts[i], nodeIdsParts[i]));
}
}
return partParams;
}
use of com.tencent.angel.ml.matrix.MatrixMeta in project angel by Tencent.
the class RowSplitCombineUtils method combineServerRowSplits.
/**
* Combine row splits of a single matrix row.
*
* @param rowSplits row splits
* @param matrixId matrix id
* @param rowIndex row index
* @return TVector merged row
*/
public static Vector combineServerRowSplits(List<ServerRow> rowSplits, int matrixId, int rowIndex) {
MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
RowType rowType = matrixMeta.getRowType();
switch(rowType) {
case T_DOUBLE_DENSE:
case T_DOUBLE_SPARSE:
return combineServerIntDoubleRowSplits(rowSplits, matrixMeta, rowIndex);
case T_FLOAT_DENSE:
case T_FLOAT_SPARSE:
return combineServerIntFloatRowSplits(rowSplits, matrixMeta, rowIndex);
case T_INT_DENSE:
case T_INT_SPARSE:
return combineServerIntIntRowSplits(rowSplits, matrixMeta, rowIndex);
case T_LONG_DENSE:
case T_LONG_SPARSE:
return combineServerIntLongRowSplits(rowSplits, matrixMeta, rowIndex);
case T_DOUBLE_SPARSE_LONGKEY:
return combineServerLongDoubleRowSplits(rowSplits, matrixMeta, rowIndex);
case T_FLOAT_SPARSE_LONGKEY:
return combineServerLongFloatRowSplits(rowSplits, matrixMeta, rowIndex);
case T_INT_SPARSE_LONGKEY:
return combineServerLongIntRowSplits(rowSplits, matrixMeta, rowIndex);
case T_LONG_SPARSE_LONGKEY:
return combineServerLongLongRowSplits(rowSplits, matrixMeta, rowIndex);
default:
throw new UnsupportedOperationException("Unsupport operation: merge " + rowType + " vector splits");
}
}
use of com.tencent.angel.ml.matrix.MatrixMeta in project angel by Tencent.
the class UserRequestAdapter method update.
public Future<VoidResult> update(int matrixId, int rowId, Vector delta, UpdateOp op) {
checkParams(matrixId, rowId);
delta.setMatrixId(matrixId);
delta.setRowId(rowId);
MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
PartitionKey[] parts = matrixMeta.getPartitionKeys();
CompStreamKeyValuePart[] splits = RouterUtils.splitStream(matrixMeta, delta);
FutureResult<VoidResult> result = new FutureResult<>();
int needRequestPartNum = noEmptyPartNum(splits);
if (needRequestPartNum == 0) {
result.set(null);
return result;
}
UpdateRowRequest request = new UpdateRowRequest(matrixId, rowId, op);
ResponseCache cache = new MapResponseCache(needRequestPartNum);
int requestId = request.getRequestId();
requestIdToResponseCache.put(requestId, cache);
requestIdToResultMap.put(requestId, result);
requests.put(requestId, request);
MatrixTransportClient matrixClient = PSAgentContext.get().getMatrixTransportClient();
for (int i = 0; i < splits.length; i++) {
if (splits[i] != null && splits[i].size() > 0) {
sendUpdateRequest(matrixClient, requestId, matrixId, parts[i].getPartitionId(), splits[i], op);
}
}
return result;
}
use of com.tencent.angel.ml.matrix.MatrixMeta in project angel by Tencent.
the class UserRequestAdapter method checkParams.
private void checkParams(int matrixId, int[] rowIds) {
MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
if (matrixMeta == null) {
throw new AngelException("can not find matrix " + matrixId);
}
if (rowIds == null || rowIds.length == 0) {
throw new AngelException("row ids is empty");
}
int rowNum = matrixMeta.getRowNum();
for (int rowId : rowIds) {
if (rowId < 0 || rowId >= rowNum) {
throw new AngelException("not valid row id, row id is in range[0," + rowNum + ")");
}
}
}
use of com.tencent.angel.ml.matrix.MatrixMeta in project angel by Tencent.
the class MergeUtils method combineServerRowSplits.
/**
* Combine row splits of a single matrix row.
*
* @param rowSplits row splits
* @param matrixId matrix id
* @param rowIndex row index
* @return TVector merged row
*/
public static Vector combineServerRowSplits(List<ServerRow> rowSplits, int matrixId, int rowIndex) {
MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
RowType rowType = matrixMeta.getRowType();
switch(rowType) {
case T_DOUBLE_DENSE:
case T_DOUBLE_SPARSE:
return combineServerIntDoubleRowSplits(rowSplits, matrixMeta, rowIndex);
case T_FLOAT_DENSE:
case T_FLOAT_SPARSE:
return combineServerIntFloatRowSplits(rowSplits, matrixMeta, rowIndex);
case T_INT_DENSE:
case T_INT_SPARSE:
return combineServerIntIntRowSplits(rowSplits, matrixMeta, rowIndex);
case T_LONG_DENSE:
case T_LONG_SPARSE:
return combineServerIntLongRowSplits(rowSplits, matrixMeta, rowIndex);
case T_DOUBLE_SPARSE_LONGKEY:
return combineServerLongDoubleRowSplits(rowSplits, matrixMeta, rowIndex);
case T_FLOAT_SPARSE_LONGKEY:
return combineServerLongFloatRowSplits(rowSplits, matrixMeta, rowIndex);
case T_INT_SPARSE_LONGKEY:
return combineServerLongIntRowSplits(rowSplits, matrixMeta, rowIndex);
case T_LONG_SPARSE_LONGKEY:
return combineServerLongLongRowSplits(rowSplits, matrixMeta, rowIndex);
default:
throw new UnsupportedOperationException("Unsupport operation: merge " + rowType + " vector splits");
}
}
Aggregations