use of com.tencent.angel.ml.matrix.psf.update.base.VoidResult in project angel by Tencent.
the class UserRequestAdapter method update.
/**
* Update matrix use a udf.
*
* @param updateFunc update udf function
* @return Future<VoidResult> update future result
*/
public Future<VoidResult> update(UpdateFunc updateFunc) {
MatrixTransportClient matrixClient = PSAgentContext.get().getMatrixTransportClient();
UpdateParam param = updateFunc.getParam();
// Split the param use matrix partitions
List<PartitionUpdateParam> partParams = param.split();
int size = partParams.size();
UpdatePSFRequest request = new UpdatePSFRequest(updateFunc);
ResponseCache cache = new MapResponseCache(size);
FutureResult<VoidResult> result = new FutureResult<>();
int requestId = request.getRequestId();
requests.put(requestId, request);
requestIdToResponseCache.put(requestId, cache);
requestIdToResultMap.put(requestId, result);
// Send request to PSS
for (int i = 0; i < size; i++) {
sendUpdateUDFRequest(matrixClient, requestId, partParams.get(i).getMatrixId(), partParams.get(i).getPartKey().getPartitionId(), updateFunc, partParams.get(i));
}
return result;
}
use of com.tencent.angel.ml.matrix.psf.update.base.VoidResult in project angel by Tencent.
the class UpdateHandler method handle.
@Override
public void handle(FutureResult finalResult, UserRequest userRequest, ResponseCache responseCache) {
MapResponseCache cache = (MapResponseCache) responseCache;
// Check update result
boolean success = true;
String detail = "";
for (Response response : cache.getResponses().values()) {
success = success && (response.getResponseType() == ResponseType.SUCCESS);
if (!success) {
detail = response.getDetail();
break;
}
}
// Set the final result
if (success) {
finalResult.set(new VoidResult(com.tencent.angel.psagent.matrix.ResponseType.SUCCESS));
} else {
finalResult.set(new VoidResult(com.tencent.angel.psagent.matrix.ResponseType.FAILED, detail));
}
}
use of com.tencent.angel.ml.matrix.psf.update.base.VoidResult in project angel by Tencent.
the class MatrixTransportClient method update.
@Override
public FutureResult<VoidResult> update(UpdateFunc func, PartitionUpdateParam param) {
// Request header
RequestHeader header = createRequestHeader(-1, TransportMethod.UPDATE_PSF, param.getMatrixId(), param.getPartKey().getPartitionId());
// Request body
UpdateUDFRequest requestData = new UpdateUDFRequest(func.getClass().getName(), param);
// Request
Request request = new Request(header, requestData);
FutureResult<VoidResult> resultFuture = new FutureResult<>();
requestToResultMap.put(request, resultFuture);
// Send the request
sendUpdateRequest(request);
return resultFuture;
}
use of com.tencent.angel.ml.matrix.psf.update.base.VoidResult 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.psf.update.base.VoidResult 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;
}
Aggregations