Search in sources :

Example 21 with Worker

use of com.tencent.angel.worker.Worker in project angel by Tencent.

the class UpdateRowsHashTest method testSparseDoubleUDF.

public void testSparseDoubleUDF() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_DOUBLE_MAT, 0);
    int[] index = genIndexs(feaNum, nnz);
    IntDoubleVector deltaVec = null;
    for (int rowId = 0; rowId < rowNum; rowId++) {
        deltaVec = new IntDoubleVector(feaNum, new IntDoubleSparseVectorStorage(feaNum));
        for (int i = 0; i < index.length; i++) {
            deltaVec.set(index[i], index[i]);
        }
        client1.update(rowId, deltaVec);
    }
    int[] rowIds = new int[rowNum];
    for (int i = 0; i < rowNum; i++) {
        rowIds[i] = i;
    }
    Vector[] rows = client1.get(rowIds, index);
    for (int i = 0; i < rowNum; i++) {
        for (int id : index) {
            Assert.assertEquals(((IntDoubleVector) rows[i]).get(id), deltaVec.get(id), zero);
        }
    }
    client1.zero();
    IntDoubleVector[] deltaVecs = new IntDoubleVector[rowNum];
    for (int rowId = 0; rowId < rowNum; rowId++) {
        deltaVec = VFactory.sparseDoubleVector(feaNum, index.length);
        for (int i = 0; i < index.length; i++) {
            deltaVec.set(index[i], index[i]);
        }
        deltaVecs[rowId] = deltaVec;
    }
    client1.update(rowIds, deltaVecs);
    rows = client1.get(rowIds, index);
    for (int i = 0; i < rowNum; i++) {
        for (int id : index) {
            Assert.assertEquals(((IntDoubleVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
        }
    }
    client1.zero();
    for (int rowId = 0; rowId < rowNum; rowId++) {
        deltaVec = new IntDoubleVector(feaNum, new IntDoubleSparseVectorStorage(feaNum));
        for (int i = 0; i < index.length; i++) {
            deltaVec.set(index[i], index[i]);
        }
        deltaVecs[rowId] = deltaVec;
    }
    client1.increment(rowIds, deltaVecs, true);
    rows = client1.get(rowIds, index);
    for (int i = 0; i < rowNum; i++) {
        for (int id : index) {
            Assert.assertEquals(((IntDoubleVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
        }
    }
}
Also used : Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient)

Example 22 with Worker

use of com.tencent.angel.worker.Worker in project angel by Tencent.

the class UpdateRowsHashTest method testSparseIntUDF.

public void testSparseIntUDF() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_INT_MAT, 0);
    int matrixW1Id = client1.getMatrixId();
    int[] index = genIndexs(feaNum, nnz);
    IntIntVector deltaVec = null;
    for (int rowId = 0; rowId < rowNum; rowId++) {
        deltaVec = new IntIntVector(feaNum, new IntIntSparseVectorStorage(feaNum));
        for (int i = 0; i < index.length; i++) {
            deltaVec.set(index[i], index[i]);
        }
        client1.update(rowId, deltaVec);
    }
    int[] rowIds = new int[rowNum];
    for (int i = 0; i < rowNum; i++) {
        rowIds[i] = i;
    }
    Vector[] rows = client1.get(rowIds, index);
    for (int i = 0; i < rowNum; i++) {
        for (int id : index) {
            Assert.assertEquals(((IntIntVector) rows[i]).get(id), deltaVec.get(id), zero);
        }
        Assert.assertTrue(index.length == ((IntIntVector) rows[i]).size());
    }
    client1.zero();
    IntIntVector[] deltaVecs = new IntIntVector[rowNum];
    for (int rowId = 0; rowId < rowNum; rowId++) {
        deltaVec = VFactory.sparseIntVector(feaNum, index.length);
        for (int i = 0; i < index.length; i++) {
            deltaVec.set(index[i], index[i]);
        }
        deltaVecs[rowId] = deltaVec;
    }
    client1.update(rowIds, deltaVecs);
    rows = client1.get(rowIds, index);
    for (int i = 0; i < rowNum; i++) {
        for (int id : index) {
            Assert.assertEquals(((IntIntVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
        }
    }
    client1.zero();
    for (int rowId = 0; rowId < rowNum; rowId++) {
        deltaVec = VFactory.sparseIntVector(feaNum, index.length);
        for (int i = 0; i < index.length; i++) {
            deltaVec.set(index[i], index[i]);
        }
        deltaVecs[rowId] = deltaVec;
    }
    client1.increment(rowIds, deltaVecs, true);
    rows = client1.get(rowIds, index);
    for (int i = 0; i < rowNum; i++) {
        for (int id : index) {
            Assert.assertEquals(((IntIntVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
        }
    }
}
Also used : Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient)

Example 23 with Worker

use of com.tencent.angel.worker.Worker in project angel by Tencent.

the class GetRowHashTest method testDenseLongUDF.

public void testDenseLongUDF() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client1 = worker.getPSAgent().getMatrixClient(DENSE_LONG_MAT, 0);
    int[] index = genIndexs(feaNum, nnz);
    IntLongVector deltaVec = new IntLongVector(feaNum, new IntLongDenseVectorStorage(feaNum));
    for (int i = 0; i < feaNum; i++) deltaVec.set(i, i);
    deltaVec.setRowId(0);
    client1.increment(deltaVec);
    IntLongVector row = (IntLongVector) client1.getRow(0);
    for (int id : index) {
        // System.out.println("id=" + id + ", value=" + row.get(id));
        Assert.assertEquals(row.get(id), deltaVec.get(id));
    }
    Assert.assertTrue(feaNum == row.size());
}
Also used : Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient)

Example 24 with Worker

use of com.tencent.angel.worker.Worker in project angel by Tencent.

the class GetRowHashTest method testDenseFloatUDF.

public void testDenseFloatUDF() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client1 = worker.getPSAgent().getMatrixClient(DENSE_FLOAT_MAT, 0);
    int[] index = genIndexs(feaNum, nnz);
    IntFloatVector deltaVec = new IntFloatVector(feaNum, new IntFloatDenseVectorStorage(feaNum));
    for (int i = 0; i < feaNum; i++) deltaVec.set(i, i);
    deltaVec.setRowId(0);
    client1.increment(deltaVec);
    IntFloatVector row = (IntFloatVector) client1.getRow(0);
    for (int id : index) {
        Assert.assertTrue(row.get(id) == deltaVec.get(id));
    }
    Assert.assertTrue(feaNum == row.size());
}
Also used : Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient)

Example 25 with Worker

use of com.tencent.angel.worker.Worker in project angel by Tencent.

the class GetRowHashTest method testDenseIntUDF.

public void testDenseIntUDF() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client1 = worker.getPSAgent().getMatrixClient(DENSE_INT_MAT, 0);
    int[] index = genIndexs(feaNum, nnz);
    IntIntVector deltaVec = new IntIntVector(feaNum, new IntIntDenseVectorStorage(feaNum));
    for (int i = 0; i < feaNum; i++) deltaVec.set(i, i);
    deltaVec.setRowId(0);
    client1.increment(deltaVec);
    IntIntVector row = (IntIntVector) client1.getRow(0);
    for (int id : index) {
        Assert.assertTrue(row.get(id) == deltaVec.get(id));
    }
    Assert.assertTrue(feaNum == row.size());
}
Also used : Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient)

Aggregations

Worker (com.tencent.angel.worker.Worker)196 MatrixClient (com.tencent.angel.psagent.matrix.MatrixClient)183 Test (org.junit.Test)21 AMTaskManager (com.tencent.angel.master.task.AMTaskManager)13 IntDoubleVector (com.tencent.angel.ml.math2.vector.IntDoubleVector)13 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)13 IntIntVector (com.tencent.angel.ml.math2.vector.IntIntVector)13 IntLongVector (com.tencent.angel.ml.math2.vector.IntLongVector)12 LongDoubleVector (com.tencent.angel.ml.math2.vector.LongDoubleVector)12 LongFloatVector (com.tencent.angel.ml.math2.vector.LongFloatVector)12 LongIntVector (com.tencent.angel.ml.math2.vector.LongIntVector)12 LongLongVector (com.tencent.angel.ml.math2.vector.LongLongVector)12 Vector (com.tencent.angel.ml.math2.vector.Vector)12 IncrementRows (com.tencent.angel.ml.matrix.psf.update.update.IncrementRows)12 IncrementRowsParam (com.tencent.angel.ml.matrix.psf.update.update.IncrementRowsParam)12 WorkerManager (com.tencent.angel.master.worker.WorkerManager)10 Location (com.tencent.angel.common.location.Location)9 AngelApplicationMaster (com.tencent.angel.master.AngelApplicationMaster)9 LongIndexGet (com.tencent.angel.ml.matrix.psf.get.indexed.LongIndexGet)8 LongIndexGetParam (com.tencent.angel.ml.matrix.psf.get.indexed.LongIndexGetParam)8