use of com.tencent.angel.ml.matrix.MatrixMeta in project angel by Tencent.
the class RowSplitCombineUtils method combineIndexRowSplits.
/**
* Combine the row splits.
*
* @param matrixId Matrix id
* @param rowId row id
* @param resultSize keys number
* @param keyParts keys partitions
* @param valueParts values partitions
* @return merged vector
*/
public static Vector combineIndexRowSplits(int matrixId, int rowId, int resultSize, KeyPart[] keyParts, ValuePart[] valueParts) {
// Get matrix meta
MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
RowType rowType = matrixMeta.getRowType();
switch(rowType) {
case T_DOUBLE_DENSE:
case T_DOUBLE_SPARSE:
return combineIntDoubleIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
case T_FLOAT_DENSE:
case T_FLOAT_SPARSE:
return combineIntFloatIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
case T_INT_DENSE:
case T_INT_SPARSE:
return combineIntIntIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
case T_LONG_DENSE:
case T_LONG_SPARSE:
return combineIntLongIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
case T_DOUBLE_SPARSE_LONGKEY:
return combineLongDoubleIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
case T_FLOAT_SPARSE_LONGKEY:
return combineLongFloatIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
case T_INT_SPARSE_LONGKEY:
return combineLongIntIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
case T_LONG_SPARSE_LONGKEY:
return combineLongLongIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
default:
throw new UnsupportedOperationException("unsupport row type " + rowType);
}
}
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[] rowIds, Vector[] rows, UpdateOp op) {
assert rowIds.length == rows.length;
checkParams(matrixId, rowIds);
for (int i = 0; i < rowIds.length; i++) {
rows[i].setRowId(rowIds[i]);
}
MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
PartitionKey[] parts = matrixMeta.getPartitionKeys();
CompStreamKeyValuePart[] splits = RouterUtils.splitStream(matrixMeta, rows);
int needRequestPartNum = noEmptyPartNum(splits);
FutureResult<VoidResult> result = new FutureResult<>();
if (needRequestPartNum == 0) {
result.set(null);
return result;
}
UpdateRowsRequest request = new UpdateRowsRequest(matrixId, 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 update.
public Future<VoidResult> update(int matrixId, Matrix delta, UpdateOp op) {
checkParams(matrixId);
delta.setMatrixId(matrixId);
MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
PartitionKey[] parts = matrixMeta.getPartitionKeys();
CompStreamKeyValuePart[] splits = RouterUtils.splitStream(matrixMeta, delta);
int needRequestPartNum = noEmptyPartNum(splits);
FutureResult<VoidResult> result = new FutureResult<>();
if (needRequestPartNum == 0) {
result.set(null);
return result;
}
UpdateMatrixRequest request = new UpdateMatrixRequest(matrixId, 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 get.
private FutureResult<Vector> get(IndexGetRowRequest request) {
MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(request.getMatrixId());
PartitionKey[] parts = matrixMeta.getPartitionKeys();
// Split the user request to partition requests
FutureResult<Vector> result = new FutureResult<>();
KeyPart[] splits;
long startTs = System.currentTimeMillis();
if (request instanceof IntIndexGetRowRequest) {
splits = RouterUtils.split(matrixMeta, -1, ((IntIndexGetRowRequest) request).getKeys());
} else if (request instanceof LongIndexGetRowRequest) {
splits = RouterUtils.split(matrixMeta, -1, ((LongIndexGetRowRequest) request).getKeys());
} else {
throw new UnsupportedOperationException("Unsupport index request type " + request.getClass().toString());
}
LOG.info("Get by indices split use time: " + (System.currentTimeMillis() - startTs));
assert parts.length == splits.length;
// filter empty partition requests
int needRequestPartNum = noEmptyPartNum(splits);
if (needRequestPartNum == 0) {
result.set(null);
return result;
}
// Create partition results cache
ResponseCache cache = new MapResponseCache(needRequestPartNum);
int requestId = request.getRequestId();
requestIdToResponseCache.put(requestId, cache);
requestIdToResultMap.put(requestId, result);
requests.put(requestId, request);
// Send all the partition requests
MatrixTransportClient matrixClient = PSAgentContext.get().getMatrixTransportClient();
for (int i = 0; i < splits.length; i++) {
if (splits[i] != null && splits[i].size() > 0) {
sendIndexGetRowRequest(matrixClient, requestId, request.getMatrixId(), request.getRowId(), parts[i].getPartitionId(), splits[i], request.getFunc());
}
}
return result;
}
use of com.tencent.angel.ml.matrix.MatrixMeta in project angel by Tencent.
the class MergeUtils method combineIndexRowSplits.
/**
* Combine the row splits.
*
* @param matrixId Matrix id
* @param rowId row id
* @param resultSize keys number
* @param keyParts keys partitions
* @param valueParts values partitions
* @return merged vector
*/
public static Vector combineIndexRowSplits(int matrixId, int rowId, int resultSize, KeyPart[] keyParts, ValuePart[] valueParts) {
// Get matrix meta
MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
RowType rowType = matrixMeta.getRowType();
switch(rowType) {
case T_DOUBLE_DENSE:
case T_DOUBLE_SPARSE:
return combineIntDoubleIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
case T_FLOAT_DENSE:
case T_FLOAT_SPARSE:
return combineIntFloatIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
case T_INT_DENSE:
case T_INT_SPARSE:
return combineIntIntIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
case T_LONG_DENSE:
case T_LONG_SPARSE:
return combineIntLongIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
case T_DOUBLE_SPARSE_LONGKEY:
return combineLongDoubleIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
case T_FLOAT_SPARSE_LONGKEY:
return combineLongFloatIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
case T_INT_SPARSE_LONGKEY:
return combineLongIntIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
case T_LONG_SPARSE_LONGKEY:
return combineLongLongIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
default:
throw new UnsupportedOperationException("unsupport row type " + rowType);
}
}
Aggregations