Search in sources :

Example 1 with IndexGetParam

use of com.tencent.angel.ml.matrix.psf.get.enhance.indexed.IndexGetParam in project angel by Tencent.

the class GetValueOfIndexTask method sparseDouble.

public void sparseDouble(TaskContext tContext) {
    long startGen = System.currentTimeMillis();
    int[] index = genIndexs(feaNum, nnz);
    long cost = System.currentTimeMillis() - startGen;
    LOG.info("Gen index cost: " + cost + " ms.");
    try {
        MatrixClient sMatClient = tContext.getMatrix(SPARSE_DOUBLE_MAT);
        // Set PS Model values
        long startInc = System.currentTimeMillis();
        SparseDoubleVector delt = new SparseDoubleVector(feaNum);
        for (int i = 0; i < feaNum; i++) delt.set(i, (double) i);
        sMatClient.increment(0, delt);
        sMatClient.clock().get();
        long costInc = System.currentTimeMillis() - startInc;
        LOG.info("Increment delt cost " + costInc + " ms.");
        // Wait for all tasks finish this clock
        sMatClient.getTaskContext().globalSync(sMatClient.getMatrixId());
        // Get values of index array
        long startGet = System.currentTimeMillis();
        IndexGetFunc func = new IndexGetFunc(new IndexGetParam(tContext.getMatrix(DENSE_DOUBLE_MAT).getMatrixId(), 0, index));
        SparseDoubleVector row = (SparseDoubleVector) ((GetRowResult) sMatClient.get(func)).getRow();
        long costGet = System.currentTimeMillis() - startGet;
        LOG.info("Get row of indexs cost " + costGet + " ms.");
    } catch (Throwable e) {
        throw new AngelException(e);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) IndexGetFunc(com.tencent.angel.ml.matrix.psf.get.enhance.indexed.IndexGetFunc) IndexGetParam(com.tencent.angel.ml.matrix.psf.get.enhance.indexed.IndexGetParam) SparseDoubleVector(com.tencent.angel.ml.math.vector.SparseDoubleVector)

Example 2 with IndexGetParam

use of com.tencent.angel.ml.matrix.psf.get.enhance.indexed.IndexGetParam in project angel by Tencent.

the class GetValueOfIndexTask method denseDouble.

public void denseDouble(TaskContext tContext) {
    long startGen = System.currentTimeMillis();
    int[] index = genIndexs(feaNum, nnz);
    long cost = System.currentTimeMillis() - startGen;
    LOG.info("Gen index cost: " + cost + " ms.");
    try {
        MatrixClient dMatClient = tContext.getMatrix(DENSE_DOUBLE_MAT);
        // Set PS Model values
        long startInc = System.currentTimeMillis();
        DenseDoubleVector delt = new DenseDoubleVector(feaNum);
        for (int i = 0; i < feaNum; i++) delt.set(i, (double) i);
        dMatClient.increment(0, delt);
        dMatClient.clock().get();
        long costInc = System.currentTimeMillis() - startInc;
        LOG.info("Increment delt cost " + costInc + " ms.");
        // Wait for all tasks finish this clock
        dMatClient.getTaskContext().globalSync(dMatClient.getMatrixId());
        // Get values of index array
        long startGet = System.currentTimeMillis();
        IndexGetFunc func = new IndexGetFunc(new IndexGetParam(tContext.getMatrix(DENSE_DOUBLE_MAT).getMatrixId(), 0, index));
        SparseDoubleVector row = (SparseDoubleVector) ((GetRowResult) dMatClient.get(func)).getRow();
        long costGet = System.currentTimeMillis() - startGet;
        LOG.info("Get row of indexs cost " + costGet + " ms.");
    } catch (Throwable e) {
        throw new AngelException(e);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) IndexGetFunc(com.tencent.angel.ml.matrix.psf.get.enhance.indexed.IndexGetFunc) IndexGetParam(com.tencent.angel.ml.matrix.psf.get.enhance.indexed.IndexGetParam) SparseDoubleVector(com.tencent.angel.ml.math.vector.SparseDoubleVector)

Aggregations

AngelException (com.tencent.angel.exception.AngelException)2 SparseDoubleVector (com.tencent.angel.ml.math.vector.SparseDoubleVector)2 IndexGetFunc (com.tencent.angel.ml.matrix.psf.get.enhance.indexed.IndexGetFunc)2 IndexGetParam (com.tencent.angel.ml.matrix.psf.get.enhance.indexed.IndexGetParam)2 MatrixClient (com.tencent.angel.psagent.matrix.MatrixClient)2 DenseDoubleVector (com.tencent.angel.ml.math.vector.DenseDoubleVector)1