use of com.tencent.angel.ml.matrix.psf.get.indexed.LongIndexGetParam in project angel by Tencent.
the class IndexGetRowHashTest method testSparseLongLongKeyUDF.
public void testSparseLongLongKeyUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_LONG_LONG_MAT, 0);
int matrixW1Id = client1.getMatrixId();
long[] index = genLongIndexs(feaNum, nnz);
LongLongVector deltaVec = new LongLongVector(feaNum, new LongLongSparseVectorStorage(feaNum, nnz));
for (int i = 0; i < nnz; i++) deltaVec.set(index[i], index[i]);
deltaVec.setRowId(0);
client1.increment(deltaVec);
client1.clock().get();
LongIndexGet func = new LongIndexGet(new LongIndexGetParam(matrixW1Id, 0, index));
LongLongVector row = (LongLongVector) client1.get(0, index);
for (long 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.ml.matrix.psf.get.indexed.LongIndexGetParam in project angel by Tencent.
the class IndexGetRowTest 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 = new LongIntVector(feaNum, new LongIntSparseVectorStorage(feaNum, nnz));
for (int i = 0; i < nnz; i++) deltaVec.set(index[i], (int) index[i]);
deltaVec.setRowId(0);
client1.increment(deltaVec);
client1.clock().get();
LongIndexGet func = new LongIndexGet(new LongIndexGetParam(matrixW1Id, 0, index));
LongIntVector row = (LongIntVector) client1.get(0, index);
for (long 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.ml.matrix.psf.get.indexed.LongIndexGetParam in project angel by Tencent.
the class IndexGetRowTest method testSparseLongLongKeyUDF.
public void testSparseLongLongKeyUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_LONG_LONG_MAT, 0);
int matrixW1Id = client1.getMatrixId();
long[] index = genLongIndexs(feaNum, nnz);
LongLongVector deltaVec = new LongLongVector(feaNum, new LongLongSparseVectorStorage(feaNum, nnz));
for (int i = 0; i < nnz; i++) deltaVec.set(index[i], index[i]);
deltaVec.setRowId(0);
client1.increment(deltaVec);
client1.clock().get();
LongIndexGet func = new LongIndexGet(new LongIndexGetParam(matrixW1Id, 0, index));
LongLongVector row = (LongLongVector) client1.get(0, index);
for (long 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.ml.matrix.psf.get.indexed.LongIndexGetParam in project angel by Tencent.
the class MatrixRowGetUDFTask method run.
@Override
public void run(TaskContext taskContext) throws AngelException {
try {
MatrixClient matrixClient = taskContext.getMatrix(MatrixRowGetTest.SPARSE_LONGKEY_FLOAT_MAT);
MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(MatrixRowGetTest.SPARSE_LONGKEY_FLOAT_MAT);
long[] indices = genLongIndexs(matrixMeta.getColNum(), MatrixRowGetTest.longnnz);
long[] getIndices = genGetLongIndexs(indices, MatrixRowGetTest.nGet);
LongFloatVector deltatest = VFactory.sparseLongKeyFloatVector(matrixMeta.getColNum(), MatrixRowGetTest.longnnz);
for (int i = 0; i < MatrixRowGetTest.longnnz; i++) {
deltatest.set(indices[i], (float) (indices[i] * 1.3));
}
deltatest.setRowId(0);
LOG.info(" delta use " + deltatest.getType() + " type storage");
int updateTime = 0;
long startTs = System.currentTimeMillis();
try {
matrixClient.increment(0, deltatest, true);
long startoneTs = System.currentTimeMillis();
LOG.info("increment time= " + (startoneTs - startTs));
while (true) {
LongIndexGet funca = new LongIndexGet(new LongIndexGetParam(matrixClient.getMatrixId(), 0, getIndices));
LongFloatVector tempOne = (LongFloatVector) ((GetRowResult) PSAgentContext.get().getUserRequestAdapter().get(funca).get()).getRow();
updateTime++;
if (updateTime % 10 == 0) {
LOG.info("get times = " + updateTime + ", avg update time=" + (System.currentTimeMillis() - startoneTs) / updateTime);
}
}
} catch (Throwable ie) {
LOG.info("mistake happened in MatrixRowGet try");
}
} catch (InvalidParameterException e) {
LOG.error("get matrix failed ", e);
throw new AngelException(e);
}
}
Aggregations