Search in sources :

Example 1 with DenseIntMatrix

use of com.tencent.angel.ml.math.matrix.DenseIntMatrix in project angel by Tencent.

the class TransportTest method testGetFlowDenseIntMatrix.

@Test
public void testGetFlowDenseIntMatrix() throws Exception {
    try {
        Worker worker = LocalClusterContext.get().getWorker(worker0Attempt0Id).getWorker();
        MatrixClient mat = worker.getPSAgent().getMatrixClient("dense_int_mat_1", 0);
        DenseIntMatrix expect = new DenseIntMatrix(diRow, diCol);
        RowIndex rowIndex = new RowIndex();
        for (int i = 0; i < diRow; i++) rowIndex.addRowId(i);
        GetRowsResult result = mat.getRowsFlow(rowIndex, diRow / 2);
        TVector row;
        while ((row = result.take()) != null) {
            assertArrayEquals(((DenseIntVector) expect.getRow(row.getRowId())).getValues(), ((DenseIntVector) row).getValues());
        }
        Random rand = new Random(System.currentTimeMillis());
        for (int rowId = 0; rowId < diRow; rowId++) {
            DenseIntVector update = new DenseIntVector(diCol);
            for (int j = 0; j < ddCol; j += 3) update.set(j, rand.nextInt());
            mat.increment(rowId, update);
            expect.getRow(rowId).plusBy(update);
        }
        mat.clock().get();
        rowIndex = new RowIndex();
        for (int i = 0; i < ddRow; i++) rowIndex.addRowId(i);
        result = mat.getRowsFlow(rowIndex, 2);
        while ((row = result.take()) != null) {
            assertArrayEquals(((DenseIntVector) expect.getRow(row.getRowId())).getValues(), ((DenseIntVector) row).getValues());
        }
        rowIndex = new RowIndex();
        for (int i = 0; i < ddRow; i++) rowIndex.addRowId(i);
        result = mat.getRowsFlow(rowIndex, 2);
        while (true) {
            row = result.poll();
            if (result.isFetchOver() && row == null)
                break;
            if (row == null)
                continue;
            assertArrayEquals(((DenseIntVector) expect.getRow(row.getRowId())).getValues(), ((DenseIntVector) row).getValues());
        }
    } catch (Exception x) {
        LOG.error("run testGetFlowDenseIntMatrix failed ", x);
        throw x;
    }
}
Also used : DenseIntMatrix(com.tencent.angel.ml.math.matrix.DenseIntMatrix) RowIndex(com.tencent.angel.psagent.matrix.transport.adapter.RowIndex) Random(java.util.Random) GetRowsResult(com.tencent.angel.psagent.matrix.transport.adapter.GetRowsResult) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) TVector(com.tencent.angel.ml.math.TVector) IOException(java.io.IOException) DenseIntVector(com.tencent.angel.ml.math.vector.DenseIntVector) MasterServiceTest(com.tencent.angel.master.MasterServiceTest) Test(org.junit.Test)

Aggregations

MasterServiceTest (com.tencent.angel.master.MasterServiceTest)1 TVector (com.tencent.angel.ml.math.TVector)1 DenseIntMatrix (com.tencent.angel.ml.math.matrix.DenseIntMatrix)1 DenseIntVector (com.tencent.angel.ml.math.vector.DenseIntVector)1 MatrixClient (com.tencent.angel.psagent.matrix.MatrixClient)1 GetRowsResult (com.tencent.angel.psagent.matrix.transport.adapter.GetRowsResult)1 RowIndex (com.tencent.angel.psagent.matrix.transport.adapter.RowIndex)1 IOException (java.io.IOException)1 Random (java.util.Random)1 Test (org.junit.Test)1