use of com.tencent.angel.psagent.matrix.MatrixClient in project angel by Tencent.
the class GetRowsTest method testSparseDoubleLongKeyCompUDF.
public void testSparseDoubleLongKeyCompUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_DOUBLE_LONG_MAT_COMP, 0);
int matrixW1Id = client1.getMatrixId();
long blockColNum = worker.getPSAgent().getMatrixMetaManager().getMatrixMeta(matrixW1Id).getBlockColNum();
long[] index = genLongIndexs(feaNum, nnz);
CompLongDoubleVector deltaVec = null;
for (int rowId = 0; rowId < rowNum; rowId++) {
int partNum = (feaNum + (int) blockColNum - 1) / (int) blockColNum;
LongDoubleVector[] subVecs = new LongDoubleVector[partNum];
for (int i = 0; i < partNum; i++) {
subVecs[i] = VFactory.sparseLongKeyDoubleVector((int) blockColNum);
}
deltaVec = new CompLongDoubleVector(feaNum, subVecs, (int) blockColNum);
for (int i = 0; i < nnz; i++) deltaVec.set(index[i], index[i]);
client1.increment(rowId, deltaVec, true);
}
int[] rowIds = new int[rowNum];
for (int i = 0; i < rowNum; i++) {
rowIds[i] = i;
}
Vector[] rows = client1.getRows(rowIds);
for (int i = 0; i < rowNum; i++) {
for (long id : index) {
LOG.debug("rows[" + i + "][" + id + "]=" + ((CompLongDoubleVector) rows[i]).get(id) + ", delta[" + id + "]=" + deltaVec.get(id));
Assert.assertEquals(((CompLongDoubleVector) rows[i]).get(id), deltaVec.get(id), zero);
}
}
}
use of com.tencent.angel.psagent.matrix.MatrixClient in project angel by Tencent.
the class GetRowsTest 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 = null;
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = new LongIntVector(feaNum, new LongIntSparseVectorStorage(feaNum));
for (int i = 0; i < index.length; i++) {
deltaVec.set(index[i], (int) index[i]);
}
client1.increment(rowId, deltaVec, true);
}
int[] rowIds = new int[rowNum];
for (int i = 0; i < rowNum; i++) {
rowIds[i] = i;
}
Vector[] rows = client1.getRows(rowIds);
for (int i = 0; i < rowNum; i++) {
for (long id : index) {
Assert.assertEquals(((LongIntVector) rows[i]).get(id), deltaVec.get(id), zero);
}
}
}
use of com.tencent.angel.psagent.matrix.MatrixClient in project angel by Tencent.
the class GetRowsTest method testDenseIntCompUDF.
public void testDenseIntCompUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(DENSE_INT_MAT_COMP, 0);
int matrixW1Id = client1.getMatrixId();
int[] index = genIndexs(feaNum, nnz);
CompIntIntVector deltaVec = null;
for (int rowId = 0; rowId < rowNum; rowId++) {
long blockColNum = worker.getPSAgent().getMatrixMetaManager().getMatrixMeta(matrixW1Id).getBlockColNum();
int partNum = (feaNum + (int) blockColNum - 1) / (int) blockColNum;
IntIntVector[] subVecs = new IntIntVector[partNum];
for (int i = 0; i < partNum; i++) {
subVecs[i] = VFactory.denseIntVector((int) blockColNum);
}
deltaVec = new CompIntIntVector(feaNum, subVecs, (int) blockColNum);
for (int i = 0; i < feaNum; i++) deltaVec.set(i, i);
client1.increment(rowId, deltaVec, true);
}
int[] rowIds = new int[rowNum];
for (int i = 0; i < rowNum; i++) {
rowIds[i] = i;
}
Vector[] rows = client1.getRows(rowIds);
for (int i = 0; i < rowNum; i++) {
for (int id : index) {
Assert.assertEquals(((CompIntIntVector) rows[i]).get(id), deltaVec.get(id), zero);
}
}
}
use of com.tencent.angel.psagent.matrix.MatrixClient in project angel by Tencent.
the class GetRowsTest 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.increment(rowId, deltaVec, true);
}
int[] rowIds = new int[rowNum];
for (int i = 0; i < rowNum; i++) {
rowIds[i] = i;
}
Vector[] rows = client1.getRows(rowIds);
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());
}
}
use of com.tencent.angel.psagent.matrix.MatrixClient in project angel by Tencent.
the class GetRowsTest method testSparseLongLongKeyCompUDF.
public void testSparseLongLongKeyCompUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_LONG_LONG_MAT_COMP, 0);
int matrixW1Id = client1.getMatrixId();
long blockColNum = worker.getPSAgent().getMatrixMetaManager().getMatrixMeta(matrixW1Id).getBlockColNum();
long[] index = genLongIndexs(feaNum, nnz);
CompLongLongVector deltaVec = null;
for (int rowId = 0; rowId < rowNum; rowId++) {
int partNum = (feaNum + (int) blockColNum - 1) / (int) blockColNum;
LongLongVector[] subVecs = new LongLongVector[partNum];
for (int i = 0; i < partNum; i++) {
subVecs[i] = VFactory.sparseLongKeyLongVector((int) blockColNum);
}
deltaVec = new CompLongLongVector(feaNum, subVecs, (int) blockColNum);
for (int i = 0; i < nnz; i++) deltaVec.set(index[i], index[i]);
client1.increment(rowId, deltaVec, true);
}
int[] rowIds = new int[rowNum];
for (int i = 0; i < rowNum; i++) {
rowIds[i] = i;
}
Vector[] rows = client1.getRows(rowIds);
for (int i = 0; i < rowNum; i++) {
for (long id : index) {
Assert.assertEquals(((CompLongLongVector) rows[i]).get(id), deltaVec.get(id), zero);
}
}
}
Aggregations