use of com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage in project angel by Tencent.
the class MixedBinaryOutNonZAExecutor method apply.
private static Vector apply(CompLongFloatVector v1, LongFloatVector 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<Long2FloatMap.Entry> iter = v2.getStorage().entryIterator();
while (iter.hasNext()) {
Long2FloatMap.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.getFloatValue()));
}
} 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();
float[] 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++;
}
return new CompLongFloatVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), res, v1.getSubDim());
}
use of com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage 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.storage.LongFloatSparseVectorStorage in project angel by Tencent.
the class MixedBinaryInNonZAExecutor method apply.
private static Vector apply(CompLongFloatVector v1, LongLongVector 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<Long2LongMap.Entry> iter = v2.getStorage().entryIterator();
while (iter.hasNext()) {
Long2LongMap.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.getLongValue()));
}
} 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();
long[] 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.storage.LongFloatSparseVectorStorage in project angel by Tencent.
the class MixedBinaryInAllExecutor method apply.
private static Vector apply(CompLongFloatVector v1, LongLongVector v2, Binary op) {
LongFloatVector[] 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 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();
for (int i = 0; i < v1.getDim(); i++) {
int pidx = (int) (i / subDim);
long subidx = i % subDim;
if (v2.getStorage().hasKey(i)) {
((LongFloatVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2.get(i)));
} else {
((LongFloatVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 0));
}
}
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.storage.LongFloatSparseVectorStorage in project angel by Tencent.
the class RBCompLongFloatMatrix method initEmpty.
@Override
public void initEmpty(int idx) {
int numComp = (int) ((getDim() + subDim - 1) / subDim);
if (null == rows[idx]) {
LongFloatVector[] tmpParts = new LongFloatVector[numComp];
for (int i = 0; i < numComp; i++) {
LongFloatSparseVectorStorage storage = new LongFloatSparseVectorStorage(subDim);
tmpParts[i] = new LongFloatVector(matrixId, idx, clock, (long) getDim(), storage);
}
CompLongFloatVector tmpVect = new CompLongFloatVector(matrixId, idx, clock, (long) getDim(), tmpParts, subDim);
rows[idx] = tmpVect;
}
}
Aggregations