use of com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage in project angel by Tencent.
the class MixedBinaryInNonZAExecutor method apply.
private static Vector apply(CompLongDoubleVector v1, LongDummyVector v2, Binary op) {
LongDoubleVector[] parts = v1.getPartitions();
Storage[] resParts = StorageSwitch.applyComp(v1, v2, op);
if (!op.isKeepStorage()) {
for (int i = 0; i < parts.length; i++) {
if (parts[i].getStorage() instanceof LongDoubleSortedVectorStorage) {
resParts[i] = new LongDoubleSparseVectorStorage(parts[i].getDim(), parts[i].getStorage().getIndices(), parts[i].getStorage().getValues());
}
}
}
long subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
long[] v2Indices = v2.getIndices();
for (int i = 0; i < v2Indices.length; i++) {
long gidx = v2Indices[i];
int pidx = (int) (gidx / subDim);
long subidx = gidx % subDim;
((LongDoubleVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 1));
}
LongDoubleVector[] res = new LongDoubleVector[parts.length];
int i = 0;
for (LongDoubleVector part : parts) {
res[i] = new LongDoubleVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (LongDoubleVectorStorage) resParts[i]);
i++;
}
v1.setPartitions(res);
return v1;
}
use of com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage in project angel by Tencent.
the class UpdatePSFTest method testSparseDoubleLongKeyUDF.
public void testSparseDoubleLongKeyUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_DOUBLE_LONG_MAT, 0);
int matrixW1Id = client1.getMatrixId();
long[] index = genLongIndexs(feaNum, nnz);
LongDoubleVector deltaVec = new LongDoubleVector(feaNum, new LongDoubleSparseVectorStorage(feaNum, nnz));
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();
// client1.clock().get();
LongDoubleVector row = (LongDoubleVector) client1.getRow(0);
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.math2.storage.LongDoubleSparseVectorStorage in project angel by Tencent.
the class RBCompLongDoubleMatrix method initEmpty.
@Override
public void initEmpty(int idx) {
int numComp = (int) ((getDim() + subDim - 1) / subDim);
if (null == rows[idx]) {
LongDoubleVector[] tmpParts = new LongDoubleVector[numComp];
for (int i = 0; i < numComp; i++) {
LongDoubleSparseVectorStorage storage = new LongDoubleSparseVectorStorage(subDim);
tmpParts[i] = new LongDoubleVector(matrixId, idx, clock, (long) getDim(), storage);
}
CompLongDoubleVector tmpVect = new CompLongDoubleVector(matrixId, idx, clock, (long) getDim(), tmpParts, subDim);
rows[idx] = tmpVect;
}
}
use of com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage in project angel by Tencent.
the class RBLongDoubleMatrix method initEmpty.
@Override
public void initEmpty(int idx) {
if (null == rows[idx]) {
LongDoubleSparseVectorStorage storage = new LongDoubleSparseVectorStorage((long) getDim());
rows[idx] = new LongDoubleVector(matrixId, idx, clock, (long) getDim(), storage);
}
}
use of com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage in project angel by Tencent.
the class CooLongDoubleMatrix method getCol.
@Override
public Vector getCol(int idx) {
LongArrayList cols = new LongArrayList();
DoubleArrayList data = new DoubleArrayList();
for (int i = 0; i < colIndices.length; i++) {
if (colIndices[i] == idx) {
cols.add(rowIndices[i]);
data.add(values[i]);
}
}
LongDoubleSparseVectorStorage storage = new LongDoubleSparseVectorStorage(shape[0], cols.toLongArray(), data.toDoubleArray());
return new LongDoubleVector(getMatrixId(), 0, getClock(), shape[0], storage);
}
Aggregations