use of com.tencent.angel.ml.math2.storage.LongIntSortedVectorStorage in project angel by Tencent.
the class RangeRouterUtils method splitLongIntVector.
public static KeyValuePart[] splitLongIntVector(MatrixMeta matrixMeta, LongIntVector vector) {
LongIntVectorStorage storage = vector.getStorage();
if (storage.isSparse()) {
// Get keys and values
LongIntSparseVectorStorage sparseStorage = (LongIntSparseVectorStorage) storage;
long[] keys = sparseStorage.getIndices();
int[] values = sparseStorage.getValues();
return split(matrixMeta, vector.getRowId(), keys, values, false);
} else {
// Key and value array pair
LongIntSortedVectorStorage sortStorage = (LongIntSortedVectorStorage) storage;
long[] keys = sortStorage.getIndices();
int[] values = sortStorage.getValues();
return split(matrixMeta, vector.getRowId(), keys, values, true);
}
}
use of com.tencent.angel.ml.math2.storage.LongIntSortedVectorStorage in project angel by Tencent.
the class HashRouterUtils method splitLongIntVector.
public static void splitLongIntVector(KeyHash hasher, MatrixMeta matrixMeta, LongIntVector vector, KeyValuePart[] dataParts) {
int dataPartNum = dataParts.length;
int dataPartNumMinus1 = dataPartNum - 1;
if (isPow2(dataPartNum)) {
LongIntVectorStorage storage = vector.getStorage();
if (storage.isSparse()) {
// Use iterator
LongIntSparseVectorStorage sparseStorage = (LongIntSparseVectorStorage) storage;
ObjectIterator<Long2IntMap.Entry> iter = sparseStorage.entryIterator();
while (iter.hasNext()) {
Long2IntMap.Entry keyValue = iter.next();
int partId = computeHashCode(hasher, keyValue.getLongKey()) & dataPartNumMinus1;
((HashLongKeysIntValuesPart) dataParts[partId]).add(keyValue.getLongKey(), keyValue.getIntValue());
}
} else {
// Key and value array pair
LongIntSortedVectorStorage sortStorage = (LongIntSortedVectorStorage) storage;
long[] keys = sortStorage.getIndices();
int[] values = sortStorage.getValues();
for (int i = 0; i < keys.length; i++) {
int partId = computeHashCode(hasher, keys[i]) & dataPartNumMinus1;
((HashLongKeysIntValuesPart) dataParts[partId]).add(keys[i], values[i]);
}
}
} else {
LongIntVectorStorage storage = vector.getStorage();
if (storage.isSparse()) {
// Use iterator
LongIntSparseVectorStorage sparseStorage = (LongIntSparseVectorStorage) storage;
ObjectIterator<Long2IntMap.Entry> iter = sparseStorage.entryIterator();
while (iter.hasNext()) {
Long2IntMap.Entry keyValue = iter.next();
int partId = computeHashCode(hasher, keyValue.getLongKey()) % dataPartNum;
((HashLongKeysIntValuesPart) dataParts[partId]).add(keyValue.getLongKey(), keyValue.getIntValue());
}
} else {
// Key and value array pair
LongIntSortedVectorStorage sortStorage = (LongIntSortedVectorStorage) storage;
long[] keys = sortStorage.getIndices();
int[] values = sortStorage.getValues();
for (int i = 0; i < keys.length; i++) {
int partId = computeHashCode(hasher, keys[i]) % dataPartNum;
((HashLongKeysIntValuesPart) dataParts[partId]).add(keys[i], values[i]);
}
}
}
}
use of com.tencent.angel.ml.math2.storage.LongIntSortedVectorStorage in project angel by Tencent.
the class MixedBinaryInAllExecutor method apply.
private static Vector apply(CompLongIntVector v1, LongIntVector 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();
for (int i = 0; i < v1.getDim(); i++) {
int pidx = (int) (i / subDim);
long subidx = i % subDim;
if (v2.getStorage().hasKey(i)) {
((LongIntVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2.get(i)));
} else {
((LongIntVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 0));
}
}
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.storage.LongIntSortedVectorStorage in project angel by Tencent.
the class MixedBinaryInAllExecutor 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();
for (int i = 0; i < v1.getDim(); i++) {
int pidx = (int) (i / subDim);
long subidx = i % subDim;
((LongIntVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2.get(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++;
}
v1.setPartitions(res);
return v1;
}
use of com.tencent.angel.ml.math2.storage.LongIntSortedVectorStorage in project angel by Tencent.
the class MixedBinaryOutNonZAExecutor 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++;
}
return new CompLongIntVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), res, v1.getSubDim());
}
Aggregations