use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class MixedBinaryInAllExecutor 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++;
}
v1.setPartitions(res);
return v1;
}
use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class StorageSwitch method applyComp.
public static Storage[] applyComp(ComponentVector v1, Vector v2, Binary op) {
Vector[] parts = v1.getPartitions();
Storage[] resParts = new Storage[parts.length];
int k = 0;
if (op.getOpType() == OpType.UNION) {
if (v2.isDense()) {
for (Vector part : parts) {
if (part.isDense()) {
if (op.isInplace()) {
resParts[k] = part.getStorage();
} else {
resParts[k] = part.copy().getStorage();
}
} else if (part.isSparse()) {
if (op.isKeepStorage()) {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySparse, part.dim());
} else {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptyDense);
}
} else {
if (op.isKeepStorage()) {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySorted, part.dim());
} else {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptyDense);
}
}
k++;
}
} else {
for (Vector part : parts) {
if (op.isInplace()) {
resParts[k] = part.getStorage();
} else {
resParts[k] = part.copy().getStorage();
}
k++;
}
}
} else if (op.getOpType() == OpType.INTERSECTION) {
if (v2.isDense()) {
for (Vector part : parts) {
if (part.isDense()) {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptyDense);
} else if (part.isSparse()) {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySparse);
} else {
if (op.isKeepStorage()) {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySorted);
} else {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySparse);
}
}
k++;
}
} else {
if (((Vector) v1).getSize() > v2.getSize()) {
for (Vector part : parts) {
if (op.isKeepStorage()) {
if (part.isDense()) {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptyDense);
} else if (part.isSparse()) {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySparse);
} else {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySorted);
}
} else {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySparse);
}
k++;
}
} else {
for (Vector part : parts) {
if (part.isDense()) {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptyDense);
} else if (part.isSparse()) {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySparse);
} else {
if (op.isKeepStorage()) {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySorted);
} else {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySparse);
}
}
k++;
}
}
}
} else {
// OpType.ALL
for (Vector part : parts) {
if (part.isDense()) {
if (op.isInplace()) {
resParts[k] = part.getStorage();
} else {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptyDense);
}
} else {
if (op.isKeepStorage()) {
if (part.isSparse()) {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySparse, part.dim());
} else {
// sorted
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySorted, part.dim());
}
} else {
if (part.getStorage() instanceof LongKeyVectorStorage) {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySparse, part.dim());
} else {
resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptyDense);
}
}
}
k++;
}
}
return resParts;
}
use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class IntIntVector method max.
public int max() {
IntIntVectorStorage idstorage = (IntIntVectorStorage) storage;
if (idstorage.size() == 0)
return 0;
int maxval = Integer.MIN_VALUE;
if (idstorage.isSparse()) {
IntIterator iter = idstorage.valueIterator();
while (iter.hasNext()) {
int val = iter.nextInt();
if (val > maxval) {
maxval = val;
}
}
} else {
for (int val : idstorage.getValues()) {
if (val > maxval) {
maxval = val;
}
}
}
return maxval;
}
use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class IntFloatVector method numZeros.
public int numZeros() {
IntFloatVectorStorage dstorage = (IntFloatVectorStorage) storage;
if (dstorage.size() == 0)
return (int) dim;
int numZero = 0;
if (dstorage.isSparse()) {
FloatIterator iter = dstorage.valueIterator();
while (iter.hasNext()) {
if (iter.nextFloat() != 0) {
numZero += 1;
}
}
} else {
for (float val : dstorage.getValues()) {
if (val != 0) {
numZero += 1;
}
}
}
return (int) getDim() - numZero;
}
use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class IntFloatVector method max.
public float max() {
IntFloatVectorStorage idstorage = (IntFloatVectorStorage) storage;
if (idstorage.size() == 0)
return 0;
float maxval = Float.MIN_VALUE;
if (idstorage.isSparse()) {
FloatIterator iter = idstorage.valueIterator();
while (iter.hasNext()) {
float val = iter.nextFloat();
if (val > maxval) {
maxval = val;
}
}
} else {
for (float val : idstorage.getValues()) {
if (val > maxval) {
maxval = val;
}
}
}
return maxval;
}
Aggregations