Search in sources :

Example 6 with LongIndexGet

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

the class IndexGetRowHashTest method testSparseLongLongKeyUDF.

public void testSparseLongLongKeyUDF() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_LONG_LONG_MAT, 0);
    int matrixW1Id = client1.getMatrixId();
    long[] index = genLongIndexs(feaNum, nnz);
    LongLongVector deltaVec = new LongLongVector(feaNum, new LongLongSparseVectorStorage(feaNum, nnz));
    for (int i = 0; i < nnz; i++) deltaVec.set(index[i], index[i]);
    deltaVec.setRowId(0);
    client1.increment(deltaVec);
    client1.clock().get();
    LongIndexGet func = new LongIndexGet(new LongIndexGetParam(matrixW1Id, 0, index));
    LongLongVector row = (LongLongVector) client1.get(0, index);
    for (long id : index) {
        // System.out.println("id=" + id + ", value=" + row.get(id));
        Assert.assertTrue(row.get(id) == deltaVec.get(id));
    }
// Assert.assertTrue(index.length == row.size());
}
Also used : Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) LongIndexGetParam(com.tencent.angel.ml.matrix.psf.get.indexed.LongIndexGetParam) LongIndexGet(com.tencent.angel.ml.matrix.psf.get.indexed.LongIndexGet)

Example 7 with LongIndexGet

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

the class IndexGetRowTest method testSparseIntLongKeyUDF.

public void testSparseIntLongKeyUDF() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_INT_LONG_MAT, 0);
    int matrixW1Id = client1.getMatrixId();
    long[] index = genLongIndexs(feaNum, nnz);
    LongIntVector deltaVec = new LongIntVector(feaNum, new LongIntSparseVectorStorage(feaNum, nnz));
    for (int i = 0; i < nnz; i++) deltaVec.set(index[i], (int) index[i]);
    deltaVec.setRowId(0);
    client1.increment(deltaVec);
    client1.clock().get();
    LongIndexGet func = new LongIndexGet(new LongIndexGetParam(matrixW1Id, 0, index));
    LongIntVector row = (LongIntVector) client1.get(0, index);
    for (long id : index) {
        // System.out.println("id=" + id + ", value=" + row.get(id));
        Assert.assertTrue(row.get(id) == deltaVec.get(id));
    }
// Assert.assertTrue(index.length == row.size());
}
Also used : Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) LongIndexGetParam(com.tencent.angel.ml.matrix.psf.get.indexed.LongIndexGetParam) LongIndexGet(com.tencent.angel.ml.matrix.psf.get.indexed.LongIndexGet)

Example 8 with LongIndexGet

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

the class IndexGetRowTest method testSparseLongLongKeyUDF.

public void testSparseLongLongKeyUDF() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_LONG_LONG_MAT, 0);
    int matrixW1Id = client1.getMatrixId();
    long[] index = genLongIndexs(feaNum, nnz);
    LongLongVector deltaVec = new LongLongVector(feaNum, new LongLongSparseVectorStorage(feaNum, nnz));
    for (int i = 0; i < nnz; i++) deltaVec.set(index[i], index[i]);
    deltaVec.setRowId(0);
    client1.increment(deltaVec);
    client1.clock().get();
    LongIndexGet func = new LongIndexGet(new LongIndexGetParam(matrixW1Id, 0, index));
    LongLongVector row = (LongLongVector) client1.get(0, index);
    for (long id : index) {
        // System.out.println("id=" + id + ", value=" + row.get(id));
        Assert.assertTrue(row.get(id) == deltaVec.get(id));
    }
// Assert.assertTrue(index.length == row.size());
}
Also used : Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) LongIndexGetParam(com.tencent.angel.ml.matrix.psf.get.indexed.LongIndexGetParam) LongIndexGet(com.tencent.angel.ml.matrix.psf.get.indexed.LongIndexGet)

Example 9 with LongIndexGet

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

the class MatrixRowGetUDFTask method run.

@Override
public void run(TaskContext taskContext) throws AngelException {
    try {
        MatrixClient matrixClient = taskContext.getMatrix(MatrixRowGetTest.SPARSE_LONGKEY_FLOAT_MAT);
        MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(MatrixRowGetTest.SPARSE_LONGKEY_FLOAT_MAT);
        long[] indices = genLongIndexs(matrixMeta.getColNum(), MatrixRowGetTest.longnnz);
        long[] getIndices = genGetLongIndexs(indices, MatrixRowGetTest.nGet);
        LongFloatVector deltatest = VFactory.sparseLongKeyFloatVector(matrixMeta.getColNum(), MatrixRowGetTest.longnnz);
        for (int i = 0; i < MatrixRowGetTest.longnnz; i++) {
            deltatest.set(indices[i], (float) (indices[i] * 1.3));
        }
        deltatest.setRowId(0);
        LOG.info(" delta use " + deltatest.getType() + " type storage");
        int updateTime = 0;
        long startTs = System.currentTimeMillis();
        try {
            matrixClient.increment(0, deltatest, true);
            long startoneTs = System.currentTimeMillis();
            LOG.info("increment time= " + (startoneTs - startTs));
            while (true) {
                LongIndexGet funca = new LongIndexGet(new LongIndexGetParam(matrixClient.getMatrixId(), 0, getIndices));
                LongFloatVector tempOne = (LongFloatVector) ((GetRowResult) PSAgentContext.get().getUserRequestAdapter().get(funca).get()).getRow();
                updateTime++;
                if (updateTime % 10 == 0) {
                    LOG.info("get times = " + updateTime + ", avg update time=" + (System.currentTimeMillis() - startoneTs) / updateTime);
                }
            }
        } catch (Throwable ie) {
            LOG.info("mistake happened in MatrixRowGet try");
        }
    } catch (InvalidParameterException e) {
        LOG.error("get matrix failed ", e);
        throw new AngelException(e);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) InvalidParameterException(com.tencent.angel.exception.InvalidParameterException) MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector) LongIndexGetParam(com.tencent.angel.ml.matrix.psf.get.indexed.LongIndexGetParam) LongIndexGet(com.tencent.angel.ml.matrix.psf.get.indexed.LongIndexGet)

Aggregations

LongIndexGet (com.tencent.angel.ml.matrix.psf.get.indexed.LongIndexGet)9 LongIndexGetParam (com.tencent.angel.ml.matrix.psf.get.indexed.LongIndexGetParam)9 MatrixClient (com.tencent.angel.psagent.matrix.MatrixClient)9 Worker (com.tencent.angel.worker.Worker)8 AngelException (com.tencent.angel.exception.AngelException)1 InvalidParameterException (com.tencent.angel.exception.InvalidParameterException)1 LongFloatVector (com.tencent.angel.ml.math2.vector.LongFloatVector)1 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)1