use of com.tencent.angel.psagent.matrix.MatrixClient in project angel by Tencent.
the class IncrementRowHashTest method testSparseFloatUDF.
public void testSparseFloatUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_FLOAT_MAT, 0);
int[] index = genIndexs(feaNum, nnz);
IntFloatVector deltaVec = new IntFloatVector(feaNum, new IntFloatSparseVectorStorage(feaNum, nnz));
for (int i = 0; i < index.length; i++) {
deltaVec.set(index[i], index[i]);
}
// for (int i = 0; i < feaNum; i++) {
// deltaVec.set(i, i);
// }
deltaVec.setRowId(0);
client1.increment(deltaVec, true);
IntFloatVector row = (IntFloatVector) client1.getRow(0);
for (int id : index) {
// System.out.println("id=" + id + ", value=" + row.get(id));
assertEquals(row.get(id), deltaVec.get(id), 0.000001);
}
Assert.assertTrue(index.length == row.size());
}
use of com.tencent.angel.psagent.matrix.MatrixClient in project angel by Tencent.
the class IncrementRowHashTest 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, true);
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());
}
use of com.tencent.angel.psagent.matrix.MatrixClient in project angel by Tencent.
the class IndexGetRowHashTest method testDenseLongUDF.
public void testDenseLongUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(DENSE_LONG_MAT, 0);
int matrixW1Id = client1.getMatrixId();
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);
client1.clock().get();
// IndexGet func = new IndexGet(new IndexGetParam(matrixW1Id, 0, index));
IntLongVector row = (IntLongVector) client1.get(0, index);
for (int id : index) {
// System.out.println("id=" + id + ", value=" + row.get(id));
Assert.assertEquals(row.get(id), deltaVec.get(id));
}
Assert.assertTrue(index.length == row.size());
}
use of com.tencent.angel.psagent.matrix.MatrixClient in project angel by Tencent.
the class IndexGetRowHashTest 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 = new IntIntVector(feaNum, new IntIntSparseVectorStorage(feaNum, nnz));
for (int i = 0; i < index.length; i++) {
deltaVec.set(index[i], index[i]);
}
// for (int i = 0; i < feaNum; i++) {
// deltaVec.set(i, i);
// }
deltaVec.setRowId(0);
client1.increment(deltaVec);
client1.clock().get();
// IndexGet func = new IndexGet(new IndexGetParam(matrixW1Id, 0, index));
IntIntVector row = (IntIntVector) client1.get(0, index);
for (int 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());
}
use of com.tencent.angel.psagent.matrix.MatrixClient in project angel by Tencent.
the class UpdateRowsTest method testSparseFloatUDF.
public void testSparseFloatUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_FLOAT_MAT, 0);
int[] index = genIndexs(feaNum, nnz);
IntFloatVector deltaVec = null;
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = new IntFloatVector(feaNum, new IntFloatSparseVectorStorage(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(((IntFloatVector) rows[i]).get(id), deltaVec.get(id), zero);
}
Assert.assertTrue(index.length == ((IntFloatVector) rows[i]).size());
}
client1.zero();
IntFloatVector[] deltaVecs = new IntFloatVector[rowNum];
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = VFactory.sparseFloatVector(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(((IntFloatVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
}
}
client1.zero();
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = VFactory.sparseFloatVector(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(((IntFloatVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
}
}
}
Aggregations