use of com.tencent.angel.ml.math2.vector.CompLongIntVector 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.CompLongIntVector in project angel by Tencent.
the class MixedBinaryOutNonZAExecutor method apply.
private static Vector apply(CompLongIntVector v1, LongIntVector v2, Binary op) {
LongIntVector[] 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 LongIntSortedVectorStorage) {
resParts[i] = new LongIntSparseVectorStorage(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;
((LongIntVectorStorage) 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 LongIntSortedVectorStorage) {
resParts[i] = new LongIntSparseVectorStorage(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;
((LongIntVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2Values[i]));
}
}
LongIntVector[] res = new LongIntVector[parts.length];
int i = 0;
for (LongIntVector part : parts) {
res[i] = new LongIntVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (LongIntVectorStorage) resParts[i]);
i++;
}
return new CompLongIntVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), res, v1.getSubDim());
}
use of com.tencent.angel.ml.math2.vector.CompLongIntVector in project angel by Tencent.
the class MixedBinaryInNonZAExecutor method apply.
private static Vector apply(CompLongIntVector v1, LongDummyVector v2, Binary op) {
LongIntVector[] 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 LongIntSortedVectorStorage) {
resParts[i] = new LongIntSparseVectorStorage(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;
((LongIntVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 1));
}
LongIntVector[] res = new LongIntVector[parts.length];
int i = 0;
for (LongIntVector part : parts) {
res[i] = new LongIntVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (LongIntVectorStorage) resParts[i]);
i++;
}
v1.setPartitions(res);
return v1;
}
use of com.tencent.angel.ml.math2.vector.CompLongIntVector in project angel by Tencent.
the class MixedBinaryInZAExecutor method apply.
private static Vector apply(CompLongIntVector v1, LongDummyVector v2, Binary op) {
LongIntVector[] parts = v1.getPartitions();
Storage[] resParts = StorageSwitch.applyComp(v1, v2, op);
if (v1.size() > v2.size()) {
long subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
long[] v2Indices = v2.getIndices();
for (int i = 0; i < v2Indices.length; i++) {
long idx = v2Indices[i];
int pidx = (int) (idx / subDim);
long subidx = idx % subDim;
if (parts[pidx].hasKey(subidx)) {
((LongIntVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 1));
}
}
} else {
long base = 0;
for (int i = 0; i < parts.length; i++) {
LongIntVector part = parts[i];
LongIntVectorStorage resPart = (LongIntVectorStorage) resParts[i];
if (part.isDense()) {
int[] partValues = part.getStorage().getValues();
int[] resPartValues = resPart.getValues();
for (int j = 0; j < partValues.length; j++) {
if (v2.hasKey(j + base)) {
resPartValues[j] = op.apply(partValues[j], v2.get(j + base));
}
}
} else if (part.isSparse()) {
ObjectIterator<Long2IntMap.Entry> piter = part.getStorage().entryIterator();
while (piter.hasNext()) {
Long2IntMap.Entry entry = piter.next();
long idx = entry.getLongKey();
if (v2.hasKey(idx + base)) {
resPart.set(idx, op.apply(entry.getIntValue(), v2.get(idx + base)));
}
}
} else {
// sorted
if (op.isKeepStorage()) {
long[] partIndices = part.getStorage().getIndices();
int[] partValues = part.getStorage().getValues();
long[] resPartIndices = resPart.getIndices();
int[] resPartValues = resPart.getValues();
for (int j = 0; j < partIndices.length; j++) {
long idx = partIndices[j];
if (v2.hasKey(idx + base)) {
resPartIndices[j] = idx;
resPartValues[j] = op.apply(partValues[j], v2.get(idx + base));
}
}
} else {
long[] partIndices = part.getStorage().getIndices();
int[] partValues = part.getStorage().getValues();
for (int j = 0; j < partIndices.length; j++) {
long idx = partIndices[j];
if (v2.hasKey(idx + base)) {
resPart.set(idx, op.apply(partValues[j], v2.get(idx + base)));
}
}
}
}
base += part.getDim();
}
}
LongIntVector[] res = new LongIntVector[parts.length];
int i = 0;
for (LongIntVector part : parts) {
res[i] = new LongIntVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (LongIntVectorStorage) resParts[i]);
i++;
}
v1.setPartitions(res);
return v1;
}
use of com.tencent.angel.ml.math2.vector.CompLongIntVector in project angel by Tencent.
the class VectorUtils method emptyLike.
private static ComponentVector emptyLike(ComponentVector v) {
ComponentVector result;
if (v instanceof CompIntDoubleVector) {
IntDoubleVector[] parts = new IntDoubleVector[v.getNumPartitions()];
IntDoubleVector[] refParts = ((CompIntDoubleVector) v).getPartitions();
for (int i = 0; i < refParts.length; i++) {
if (null != refParts[i]) {
parts[i] = (IntDoubleVector) emptyLike((SimpleVector) refParts[i]);
}
}
result = new CompIntDoubleVector(((CompIntDoubleVector) v).getMatrixId(), ((CompIntDoubleVector) v).getRowId(), ((CompIntDoubleVector) v).getClock(), ((CompIntDoubleVector) v).getDim(), parts, ((CompIntDoubleVector) v).getSubDim());
} else if (v instanceof CompIntFloatVector) {
IntFloatVector[] parts = new IntFloatVector[v.getNumPartitions()];
IntFloatVector[] refParts = ((CompIntFloatVector) v).getPartitions();
for (int i = 0; i < refParts.length; i++) {
if (null != refParts[i]) {
parts[i] = (IntFloatVector) emptyLike((SimpleVector) refParts[i]);
}
}
result = new CompIntFloatVector(((CompIntFloatVector) v).getMatrixId(), ((CompIntFloatVector) v).getRowId(), ((CompIntFloatVector) v).getClock(), ((CompIntFloatVector) v).getDim(), parts, ((CompIntFloatVector) v).getSubDim());
} else if (v instanceof CompIntLongVector) {
IntLongVector[] parts = new IntLongVector[v.getNumPartitions()];
IntLongVector[] refParts = ((CompIntLongVector) v).getPartitions();
for (int i = 0; i < refParts.length; i++) {
if (null != refParts[i]) {
parts[i] = (IntLongVector) emptyLike((SimpleVector) refParts[i]);
}
}
result = new CompIntLongVector(((CompIntLongVector) v).getMatrixId(), ((CompIntLongVector) v).getRowId(), ((CompIntLongVector) v).getClock(), ((CompIntLongVector) v).getDim(), parts, ((CompIntLongVector) v).getSubDim());
} else if (v instanceof CompIntIntVector) {
IntIntVector[] parts = new IntIntVector[v.getNumPartitions()];
IntIntVector[] refParts = ((CompIntIntVector) v).getPartitions();
for (int i = 0; i < refParts.length; i++) {
if (null != refParts[i]) {
parts[i] = (IntIntVector) emptyLike((SimpleVector) refParts[i]);
}
}
result = new CompIntIntVector(((CompIntIntVector) v).getMatrixId(), ((CompIntIntVector) v).getRowId(), ((CompIntIntVector) v).getClock(), ((CompIntIntVector) v).getDim(), parts, ((CompIntIntVector) v).getSubDim());
} else if (v instanceof CompLongDoubleVector) {
LongDoubleVector[] parts = new LongDoubleVector[v.getNumPartitions()];
LongDoubleVector[] refParts = ((CompLongDoubleVector) v).getPartitions();
for (int i = 0; i < refParts.length; i++) {
if (null != refParts[i]) {
parts[i] = (LongDoubleVector) emptyLike((SimpleVector) refParts[i]);
}
}
result = new CompLongDoubleVector(((CompLongDoubleVector) v).getMatrixId(), ((CompLongDoubleVector) v).getRowId(), ((CompLongDoubleVector) v).getClock(), ((CompLongDoubleVector) v).getDim(), parts, ((CompLongDoubleVector) v).getSubDim());
} else if (v instanceof CompLongFloatVector) {
LongFloatVector[] parts = new LongFloatVector[v.getNumPartitions()];
LongFloatVector[] refParts = ((CompLongFloatVector) v).getPartitions();
for (int i = 0; i < refParts.length; i++) {
if (null != refParts[i]) {
parts[i] = (LongFloatVector) emptyLike((SimpleVector) refParts[i]);
}
}
result = new CompLongFloatVector(((CompLongFloatVector) v).getMatrixId(), ((CompLongFloatVector) v).getRowId(), ((CompLongFloatVector) v).getClock(), ((CompLongFloatVector) v).getDim(), parts, ((CompLongFloatVector) v).getSubDim());
} else if (v instanceof CompLongLongVector) {
LongLongVector[] parts = new LongLongVector[v.getNumPartitions()];
LongLongVector[] refParts = ((CompLongLongVector) v).getPartitions();
for (int i = 0; i < refParts.length; i++) {
if (null != refParts[i]) {
parts[i] = (LongLongVector) emptyLike((SimpleVector) refParts[i]);
}
}
result = new CompLongLongVector(((CompLongLongVector) v).getMatrixId(), ((CompLongLongVector) v).getRowId(), ((CompLongLongVector) v).getClock(), ((CompLongLongVector) v).getDim(), parts, ((CompLongLongVector) v).getSubDim());
} else if (v instanceof CompLongIntVector) {
LongIntVector[] parts = new LongIntVector[v.getNumPartitions()];
LongIntVector[] refParts = ((CompLongIntVector) v).getPartitions();
for (int i = 0; i < refParts.length; i++) {
if (null != refParts[i]) {
parts[i] = (LongIntVector) emptyLike((SimpleVector) refParts[i]);
}
}
result = new CompLongIntVector(((CompLongIntVector) v).getMatrixId(), ((CompLongIntVector) v).getRowId(), ((CompLongIntVector) v).getClock(), ((CompLongIntVector) v).getDim(), parts, ((CompLongIntVector) v).getSubDim());
} else {
throw new AngelException("The operation is not support!");
}
return result;
}
Aggregations