Search in sources :

Example 6 with FutureResult

use of com.tencent.angel.psagent.matrix.transport.FutureResult in project angel by Tencent.

the class MatrixClientImpl method asyncGet.

@Override
public Future<Vector> asyncGet(int rowId, long[] indices) throws AngelException {
    checkRowId(rowId);
    checkNotNull(indices, "indices");
    // Return a empty vector
    if (indices.length == 0) {
        LOG.warn("parameter indices is empty, you should check it, just return a empty vector now!!!");
        FutureResult<Vector> result = new FutureResult<>();
        result.set(generateEmptyVec(rowId));
        return result;
    }
    try {
        return PSAgentContext.get().getUserRequestAdapter().get(matrixId, rowId, indices);
    } catch (Throwable x) {
        throw new AngelException(x);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) FutureResult(com.tencent.angel.psagent.matrix.transport.FutureResult) Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 7 with FutureResult

use of com.tencent.angel.psagent.matrix.transport.FutureResult in project angel by Tencent.

the class MatrixClientImpl method asyncGet.

@Override
public Future<Vector> asyncGet(int rowId, int[] indices) throws AngelException {
    checkRowId(rowId);
    checkNotNull(indices, "indices");
    // Return a empty vector
    if (indices.length == 0) {
        LOG.warn("parameter indices is empty, you should check it, just return a empty vector now!!!");
        FutureResult<Vector> result = new FutureResult<>();
        result.set(generateEmptyVec(rowId));
        return result;
    }
    try {
        return PSAgentContext.get().getUserRequestAdapter().get(matrixId, rowId, indices);
    } catch (Throwable x) {
        throw new AngelException(x);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) FutureResult(com.tencent.angel.psagent.matrix.transport.FutureResult) Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 8 with FutureResult

use of com.tencent.angel.psagent.matrix.transport.FutureResult in project angel by Tencent.

the class MatrixClientImpl method asyncGet.

@Override
public Future<Vector[]> asyncGet(int[] rowIds, int[] indices) throws AngelException {
    checkNotNull(rowIds, "rowIds");
    checkNotNull(indices, "indices");
    if (rowIds.length == 0) {
        LOG.warn("parameter rowIds is empty, you should check it, just return a empty vector array now!!!");
        FutureResult<Vector[]> result = new FutureResult<>();
        result.set(new Vector[0]);
        return result;
    }
    // Return a empty vector
    if (indices.length == 0) {
        LOG.warn("parameter indices is empty, you should check it, just return empty vectors now!!!");
        FutureResult<Vector[]> result = new FutureResult<>();
        result.set(generateEmptyVecs(rowIds));
        return result;
    }
    try {
        return PSAgentContext.get().getUserRequestAdapter().get(matrixId, rowIds, indices);
    } catch (Throwable x) {
        throw new AngelException(x);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) FutureResult(com.tencent.angel.psagent.matrix.transport.FutureResult)

Example 9 with FutureResult

use of com.tencent.angel.psagent.matrix.transport.FutureResult in project angel by Tencent.

the class MatrixClientImpl method asyncGet.

@Override
public Future<Vector[]> asyncGet(int[] rowIds, long[] indices) throws AngelException {
    checkNotNull(rowIds, "rowIds");
    checkNotNull(indices, "indices");
    if (rowIds.length == 0) {
        LOG.warn("parameter rowIds is empty, you should check it, just return a empty vector array now!!!");
        FutureResult<Vector[]> result = new FutureResult<>();
        result.set(new Vector[0]);
        return result;
    }
    // Return a empty vector
    if (indices.length == 0) {
        LOG.warn("parameter indices is empty, you should check it, just return empty vectors now!!!");
        FutureResult<Vector[]> result = new FutureResult<>();
        result.set(generateEmptyVecs(rowIds));
        return result;
    }
    try {
        return PSAgentContext.get().getUserRequestAdapter().get(matrixId, rowIds, indices);
    } catch (Throwable x) {
        throw new AngelException(x);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) FutureResult(com.tencent.angel.psagent.matrix.transport.FutureResult)

Example 10 with FutureResult

use of com.tencent.angel.psagent.matrix.transport.FutureResult in project angel by Tencent.

the class UserRequestAdapter method getRow.

public FutureResult<Vector> getRow(int matrixId, int rowId) {
    checkParams(matrixId, rowId);
    // Get partitions for this row
    List<PartitionKey> parts = PSAgentContext.get().getMatrixMetaManager().getPartitions(matrixId, rowId);
    GetRowRequest request = new GetRowRequest(matrixId, rowId);
    int requestId = request.getRequestId();
    FutureResult<Vector> result = new FutureResult<>();
    ResponseCache responseCache = new MapResponseCache(parts.size());
    requests.put(requestId, request);
    requestIdToResultMap.put(requestId, result);
    requestIdToResponseCache.put(requestId, responseCache);
    MatrixTransportClient matrixClient = PSAgentContext.get().getMatrixTransportClient();
    for (PartitionKey part : parts) {
        LOG.info("Get row " + part);
        sendGetRowRequest(matrixClient, requestId, part.getMatrixId(), rowId, part.getPartitionId());
    }
    return result;
}
Also used : MatrixTransportClient(com.tencent.angel.psagent.matrix.transport.MatrixTransportClient) FutureResult(com.tencent.angel.psagent.matrix.transport.FutureResult) IndexPartGetRowRequest(com.tencent.angel.ps.server.data.request.IndexPartGetRowRequest) PartitionKey(com.tencent.angel.PartitionKey) MapResponseCache(com.tencent.angel.psagent.matrix.transport.response.MapResponseCache) ResponseCache(com.tencent.angel.psagent.matrix.transport.response.ResponseCache) Vector(com.tencent.angel.ml.math2.vector.Vector) MapResponseCache(com.tencent.angel.psagent.matrix.transport.response.MapResponseCache)

Aggregations

FutureResult (com.tencent.angel.psagent.matrix.transport.FutureResult)29 PartitionKey (com.tencent.angel.PartitionKey)10 AngelException (com.tencent.angel.exception.AngelException)10 MatrixTransportClient (com.tencent.angel.psagent.matrix.transport.MatrixTransportClient)9 MapResponseCache (com.tencent.angel.psagent.matrix.transport.response.MapResponseCache)9 ResponseCache (com.tencent.angel.psagent.matrix.transport.response.ResponseCache)9 VoidResult (com.tencent.angel.ml.matrix.psf.update.base.VoidResult)8 Vector (com.tencent.angel.ml.math2.vector.Vector)6 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)5 Response (com.tencent.angel.ml.matrix.transport.Response)4 CompStreamKeyValuePart (com.tencent.angel.psagent.matrix.transport.router.CompStreamKeyValuePart)3 ServerPartition (com.tencent.angel.ps.impl.matrix.ServerPartition)2 KeyPart (com.tencent.angel.psagent.matrix.transport.router.KeyPart)2 ByteBuf (io.netty.buffer.ByteBuf)2 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 GetParam (com.tencent.angel.ml.matrix.psf.get.base.GetParam)1 GetResult (com.tencent.angel.ml.matrix.psf.get.base.GetResult)1 PartitionGetParam (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)1 PartitionUpdateParam (com.tencent.angel.ml.matrix.psf.update.base.PartitionUpdateParam)1