use of com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage in project angel by Tencent.
the class RBCompIntFloatMatrix method initEmpty.
@Override
public void initEmpty(int idx) {
int numComp = (int) ((getDim() + subDim - 1) / subDim);
if (null == rows[idx]) {
IntFloatVector[] tmpParts = new IntFloatVector[numComp];
for (int i = 0; i < numComp; i++) {
IntFloatSparseVectorStorage storage = new IntFloatSparseVectorStorage(subDim);
tmpParts[i] = new IntFloatVector(matrixId, idx, clock, (int) getDim(), storage);
}
CompIntFloatVector tmpVect = new CompIntFloatVector(matrixId, idx, clock, (int) getDim(), tmpParts, subDim);
rows[idx] = tmpVect;
}
}
use of com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage in project angel by Tencent.
the class CsrFloatMatrix method getCol.
@Override
public Vector getCol(int idx) {
IntArrayList cols = new IntArrayList();
FloatArrayList data = new FloatArrayList();
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]);
}
}
IntFloatSparseVectorStorage storage = new IntFloatSparseVectorStorage(shape[0], cols.toIntArray(), data.toFloatArray());
return new IntFloatVector(getMatrixId(), 0, getClock(), shape[0], storage);
}
use of com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage in project angel by Tencent.
the class MixedBinaryOutAllExecutor method apply.
private static Vector apply(CompIntFloatVector v1, IntDummyVector v2, Binary op) {
IntFloatVector[] 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 IntFloatSortedVectorStorage) {
resParts[i] = new IntFloatSparseVectorStorage(parts[i].getDim(), parts[i].getStorage().getIndices(), parts[i].getStorage().getValues());
}
}
}
int subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
for (int i = 0; i < v1.getDim(); i++) {
int pidx = (int) (i / subDim);
int subidx = i % subDim;
((IntFloatVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2.get(i)));
}
IntFloatVector[] res = new IntFloatVector[parts.length];
int i = 0;
for (IntFloatVector part : parts) {
res[i] = new IntFloatVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (IntFloatVectorStorage) resParts[i]);
i++;
}
return new CompIntFloatVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), res, v1.getSubDim());
}
Aggregations