use of com.tencent.angel.ml.math2.vector.LongIntVector in project angel by Tencent.
the class MixedBinaryInNonZAExecutor method apply.
private static Vector apply(CompLongFloatVector v1, LongIntVector v2, Binary op) {
LongFloatVector[] parts = v1.getPartitions();
Storage[] resParts = StorageSwitch.applyComp(v1, v2, op);
if (v2.isSparse()) {
if (!op.isKeepStorage()) {
for (int i = 0; i < parts.length; i++) {
if (parts[i].getStorage() instanceof LongFloatSortedVectorStorage) {
resParts[i] = new LongFloatSparseVectorStorage(parts[i].getDim(), parts[i].getStorage().getIndices(), parts[i].getStorage().getValues());
}
}
}
long subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
ObjectIterator<Long2IntMap.Entry> iter = v2.getStorage().entryIterator();
while (iter.hasNext()) {
Long2IntMap.Entry entry = iter.next();
long gidx = entry.getLongKey();
int pidx = (int) (gidx / subDim);
long subidx = gidx % subDim;
((LongFloatVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), entry.getIntValue()));
}
} else {
// sorted
if (!op.isKeepStorage()) {
for (int i = 0; i < parts.length; i++) {
if (parts[i].getStorage() instanceof LongFloatSortedVectorStorage) {
resParts[i] = new LongFloatSparseVectorStorage(parts[i].getDim(), parts[i].getStorage().getIndices(), parts[i].getStorage().getValues());
}
}
}
long subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
long[] v2Indices = v2.getStorage().getIndices();
int[] v2Values = v2.getStorage().getValues();
for (int i = 0; i < v2Indices.length; i++) {
long gidx = v2Indices[i];
int pidx = (int) (gidx / subDim);
long subidx = gidx % subDim;
((LongFloatVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2Values[i]));
}
}
LongFloatVector[] res = new LongFloatVector[parts.length];
int i = 0;
for (LongFloatVector part : parts) {
res[i] = new LongFloatVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (LongFloatVectorStorage) resParts[i]);
i++;
}
v1.setPartitions(res);
return v1;
}
use of com.tencent.angel.ml.math2.vector.LongIntVector in project angel by Tencent.
the class MixedBinaryInAllExecutor method apply.
private static Vector apply(CompLongDoubleVector v1, LongIntVector 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();
for (int i = 0; i < v1.getDim(); i++) {
int pidx = (int) (i / subDim);
long subidx = i % subDim;
if (v2.getStorage().hasKey(i)) {
((LongDoubleVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2.get(i)));
} else {
((LongDoubleVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 0));
}
}
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.vector.LongIntVector in project angel by Tencent.
the class MixedBinaryInAllExecutor method apply.
private static Vector apply(CompLongLongVector v1, LongIntVector v2, Binary op) {
LongLongVector[] 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 LongLongSortedVectorStorage) {
resParts[i] = new LongLongSparseVectorStorage(parts[i].getDim(), parts[i].getStorage().getIndices(), parts[i].getStorage().getValues());
}
}
}
long subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
for (int i = 0; i < v1.getDim(); i++) {
int pidx = (int) (i / subDim);
long subidx = i % subDim;
if (v2.getStorage().hasKey(i)) {
((LongLongVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2.get(i)));
} else {
((LongLongVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 0));
}
}
LongLongVector[] res = new LongLongVector[parts.length];
int i = 0;
for (LongLongVector part : parts) {
res[i] = new LongLongVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (LongLongVectorStorage) resParts[i]);
i++;
}
v1.setPartitions(res);
return v1;
}
use of com.tencent.angel.ml.math2.vector.LongIntVector in project angel by Tencent.
the class RBCompLongIntMatrix method initEmpty.
@Override
public void initEmpty(int idx) {
int numComp = (int) ((getDim() + subDim - 1) / subDim);
if (null == rows[idx]) {
LongIntVector[] tmpParts = new LongIntVector[numComp];
for (int i = 0; i < numComp; i++) {
LongIntSparseVectorStorage storage = new LongIntSparseVectorStorage(subDim);
tmpParts[i] = new LongIntVector(matrixId, idx, clock, (long) getDim(), storage);
}
CompLongIntVector tmpVect = new CompLongIntVector(matrixId, idx, clock, (long) getDim(), tmpParts, subDim);
rows[idx] = tmpVect;
}
}
use of com.tencent.angel.ml.math2.vector.LongIntVector in project angel by Tencent.
the class RowSplitCombineUtils method combineServerLongIntRowSplits.
private static Vector combineServerLongIntRowSplits(List<ServerRow> rowSplits, MatrixMeta matrixMeta, int rowIndex) {
long colNum = matrixMeta.getColNum();
int elemNum = 0;
int size = rowSplits.size();
for (int i = 0; i < size; i++) {
elemNum += rowSplits.get(i).size();
}
LongIntVector row = VFactory.sparseLongKeyIntVector(colNum, elemNum);
row.setMatrixId(matrixMeta.getId());
row.setRowId(rowIndex);
Collections.sort(rowSplits, serverRowComp);
int clock = Integer.MAX_VALUE;
for (int i = 0; i < size; i++) {
if (rowSplits.get(i) == null) {
continue;
}
if (rowSplits.get(i).getClock() < clock) {
clock = rowSplits.get(i).getClock();
}
((ServerLongIntRow) rowSplits.get(i)).mergeTo(row);
}
row.setClock(clock);
return row;
}
Aggregations