use of com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage in project angel by Tencent.
the class UpdatePSFTest method testSparseDoubleUDF.
public void testSparseDoubleUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_DOUBLE_MAT, 0);
int matrixW1Id = client1.getMatrixId();
// genIndexs(feaNum, nnz);
int[] index = new int[feaNum];
for (int i = 0; i < index.length; i++) {
index[i] = i;
}
IntDoubleVector deltaVec = new IntDoubleVector(feaNum, new IntDoubleSparseVectorStorage(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);
Vector[] updates = new Vector[1];
updates[0] = deltaVec;
client1.asyncUpdate(new IncrementRows(new IncrementRowsParam(matrixW1Id, updates))).get();
IntDoubleVector row = (IntDoubleVector) client1.getRow(0);
for (int id : index) {
// System.out.println("id=" + id + ", value=" + row.get(id));
Assert.assertEquals(row.get(id), deltaVec.get(id), 0);
}
Assert.assertTrue(index.length == row.size());
}
use of com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage in project angel by Tencent.
the class CooIntDoubleMatrix method getRow.
@Override
public Vector getRow(int idx) {
IntArrayList cols = new IntArrayList();
DoubleArrayList data = new DoubleArrayList();
for (int i = 0; i < rowIndices.length; i++) {
if (rowIndices[i] == idx) {
cols.add(colIndices[i]);
data.add(values[i]);
}
}
IntDoubleSparseVectorStorage storage = new IntDoubleSparseVectorStorage(shape[1], cols.toIntArray(), data.toDoubleArray());
return new IntDoubleVector(getMatrixId(), idx, getClock(), shape[1], storage);
}
use of com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage in project angel by Tencent.
the class CooIntDoubleMatrix method getCol.
@Override
public Vector getCol(int idx) {
IntArrayList cols = new IntArrayList();
DoubleArrayList data = new DoubleArrayList();
for (int i = 0; i < colIndices.length; i++) {
if (colIndices[i] == idx) {
cols.add(rowIndices[i]);
data.add(values[i]);
}
}
IntDoubleSparseVectorStorage storage = new IntDoubleSparseVectorStorage(shape[0], cols.toIntArray(), data.toDoubleArray());
return new IntDoubleVector(getMatrixId(), 0, getClock(), shape[0], storage);
}
use of com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage in project angel by Tencent.
the class CsrDoubleMatrix method getRow.
@Override
public Vector getRow(int idx) {
IntArrayList cols = new IntArrayList();
DoubleArrayList data = new DoubleArrayList();
int rowNum = indptr.length - 1;
assert (idx < rowNum);
for (int i = indptr[idx]; i < indptr[idx + 1]; i++) {
cols.add(indices[i]);
data.add(values[i]);
}
IntDoubleSparseVectorStorage storage = new IntDoubleSparseVectorStorage(shape[1], cols.toIntArray(), data.toDoubleArray());
return new IntDoubleVector(getMatrixId(), idx, getClock(), shape[1], storage);
}
use of com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage in project angel by Tencent.
the class CsrDoubleMatrix method getCol.
@Override
public Vector getCol(int idx) {
IntArrayList cols = new IntArrayList();
DoubleArrayList data = new DoubleArrayList();
int[] rows = new int[indices.length];
int i = 0;
int j = 0;
while (i < indptr.length - 1 && j < indptr.length - 1) {
int r = indptr[i + 1] - indptr[i];
for (int p = j; p < j + r; p++) {
rows[p] = i;
}
if (r != 0) {
j++;
}
i++;
}
for (int id = 0; id < indices.length; id++) {
if (indices[id] == idx) {
cols.add(rows[id]);
data.add(values[id]);
}
}
IntDoubleSparseVectorStorage storage = new IntDoubleSparseVectorStorage(shape[0], cols.toIntArray(), data.toDoubleArray());
return new IntDoubleVector(getMatrixId(), 0, getClock(), shape[0], storage);
}
Aggregations