use of com.tencent.angel.psagent.matrix.MatrixClient in project angel by Tencent.
the class UpdateRowsHashTest method testDenseIntUDF.
public void testDenseIntUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(DENSE_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 IntIntDenseVectorStorage(feaNum));
for (int i = 0; i < feaNum; i++) deltaVec.set(i, 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);
}
}
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);
}
}
}
use of com.tencent.angel.psagent.matrix.MatrixClient in project angel by Tencent.
the class UpdateRowsHashTest 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 = null;
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = new IntLongVector(feaNum, new IntLongDenseVectorStorage(feaNum));
for (int i = 0; i < feaNum; i++) deltaVec.set(i, 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(((IntLongVector) rows[i]).get(id), deltaVec.get(id), zero);
}
}
client1.zero();
IntLongVector[] deltaVecs = new IntLongVector[rowNum];
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = VFactory.sparseLongVector(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(((IntLongVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
}
}
client1.zero();
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = VFactory.sparseLongVector(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(((IntLongVector) rows[i]).get(id), deltaVecs[i].get(id), zero);
}
}
}
use of com.tencent.angel.psagent.matrix.MatrixClient in project angel by Tencent.
the class UpdateRowsHashTest method testDenseDoubleUDF.
public void testDenseDoubleUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(DENSE_DOUBLE_MAT, 0);
int[] index = genIndexs(feaNum, nnz);
IntDoubleVector deltaVec = null;
for (int rowId = 0; rowId < rowNum; rowId++) {
deltaVec = new IntDoubleVector(feaNum, new IntDoubleDenseVectorStorage(feaNum));
for (int i = 0; i < feaNum; i++) deltaVec.set(i, 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 = new IntDoubleVector(feaNum, new IntDoubleSparseVectorStorage(feaNum));
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);
}
}
}
use of com.tencent.angel.psagent.matrix.MatrixClient in project angel by Tencent.
the class UpdateRowsHashTest 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);
}
}
}
use of com.tencent.angel.psagent.matrix.MatrixClient 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);
}
}
}
Aggregations