Search in sources :

Example 1 with Pull

use of com.tencent.angel.ml.matrix.psf.aggr.Pull in project angel by Tencent.

the class PSFTestTask method run.

@Override
public void run(TaskContext taskContext) throws AngelException {
    try {
        MatrixClient client = taskContext.getMatrix("psf_test");
        Pull func = new Pull(client.getMatrixId(), 0);
        Pull func1 = new Pull(client.getMatrixId(), 1);
        while (taskContext.getEpoch() < 100) {
            taskContext.globalSync(client.getMatrixId());
            long startTs = System.currentTimeMillis();
            TVector row = ((GetRowResult) client.get(func)).getRow();
            TVector row1 = ((GetRowResult) client.get(func1)).getRow();
            LOG.info("Task " + taskContext.getTaskId() + " in iteration " + taskContext.getEpoch() + " pull use time=" + (System.currentTimeMillis() - startTs) + ", sum of row 0=" + sum((DenseDoubleVector) row) + " sum of row 1=" + sum((DenseDoubleVector) row1));
            double[] delta = new double[10000000];
            for (int i = 0; i < 10000000; i++) {
                delta[i] = 1.0;
            }
            DenseDoubleVector deltaV = new DenseDoubleVector(10000000, delta);
            deltaV.setMatrixId(client.getMatrixId());
            deltaV.setRowId(0);
            double[] delta1 = new double[10000000];
            for (int i = 0; i < 10000000; i++) {
                delta1[i] = 2.0;
            }
            DenseDoubleVector deltaV1 = new DenseDoubleVector(10000000, delta1);
            deltaV1.setMatrixId(client.getMatrixId());
            deltaV1.setRowId(1);
            client.increment(deltaV);
            client.increment(deltaV1);
            client.clock().get();
            taskContext.incEpoch();
        }
    } catch (Throwable x) {
        throw new AngelException("run task failed ", x);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) Pull(com.tencent.angel.ml.matrix.psf.aggr.Pull) DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) TVector(com.tencent.angel.ml.math.TVector) GetRowResult(com.tencent.angel.ml.matrix.psf.get.single.GetRowResult)

Example 2 with Pull

use of com.tencent.angel.ml.matrix.psf.aggr.Pull in project angel by Tencent.

the class AggrFuncTest method testPull.

@Test
public void testPull() throws InvalidParameterException, InterruptedException, ExecutionException {
    GetFunc func = new Pull(w2Client.getMatrixId(), 1);
    double[] result = ((DenseDoubleVector) (((GetRowResult) w2Client.get(func)).getRow())).getValues();
    for (int i = 0; i < dim; i++) {
        Assert.assertEquals(result[i], localArray1[i], delta);
    }
}
Also used : GetFunc(com.tencent.angel.ml.matrix.psf.get.base.GetFunc) Pull(com.tencent.angel.ml.matrix.psf.aggr.Pull) DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector) GetRowResult(com.tencent.angel.ml.matrix.psf.get.single.GetRowResult)

Aggregations

DenseDoubleVector (com.tencent.angel.ml.math.vector.DenseDoubleVector)2 Pull (com.tencent.angel.ml.matrix.psf.aggr.Pull)2 GetRowResult (com.tencent.angel.ml.matrix.psf.get.single.GetRowResult)2 AngelException (com.tencent.angel.exception.AngelException)1 TVector (com.tencent.angel.ml.math.TVector)1 GetFunc (com.tencent.angel.ml.matrix.psf.get.base.GetFunc)1 MatrixClient (com.tencent.angel.psagent.matrix.MatrixClient)1