use of com.tencent.angel.ml.math2.storage.LongFloatSortedVectorStorage in project angel by Tencent.
the class MixedBinaryInNonZAExecutor method apply.
private static Vector apply(CompLongFloatVector v1, LongDummyVector 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();
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;
((LongFloatVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 1));
}
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.LongFloatSortedVectorStorage in project angel by Tencent.
the class HashRouterUtils method splitLongFloatVector.
public static void splitLongFloatVector(KeyHash hasher, MatrixMeta matrixMeta, LongFloatVector vector, KeyValuePart[] dataParts) {
int dataPartNum = dataParts.length;
int dataPartNumMinus1 = dataPartNum - 1;
if (isPow2(dataPartNum)) {
LongFloatVectorStorage storage = vector.getStorage();
if (storage.isSparse()) {
// Use iterator
LongFloatSparseVectorStorage sparseStorage = (LongFloatSparseVectorStorage) storage;
ObjectIterator<Long2FloatMap.Entry> iter = sparseStorage.entryIterator();
while (iter.hasNext()) {
Long2FloatMap.Entry keyValue = iter.next();
int partId = computeHashCode(hasher, keyValue.getLongKey()) & dataPartNumMinus1;
((HashLongKeysFloatValuesPart) dataParts[partId]).add(keyValue.getLongKey(), keyValue.getFloatValue());
}
} else {
// Key and value array pair
LongFloatSortedVectorStorage sortStorage = (LongFloatSortedVectorStorage) storage;
long[] keys = sortStorage.getIndices();
float[] values = sortStorage.getValues();
for (int i = 0; i < keys.length; i++) {
int partId = computeHashCode(hasher, keys[i]) & dataPartNumMinus1;
((HashLongKeysFloatValuesPart) dataParts[partId]).add(keys[i], values[i]);
}
}
} else {
LongFloatVectorStorage storage = vector.getStorage();
if (storage.isSparse()) {
// Use iterator
LongFloatSparseVectorStorage sparseStorage = (LongFloatSparseVectorStorage) storage;
ObjectIterator<Long2FloatMap.Entry> iter = sparseStorage.entryIterator();
while (iter.hasNext()) {
Long2FloatMap.Entry keyValue = iter.next();
int partId = computeHashCode(hasher, keyValue.getLongKey()) % dataPartNum;
((HashLongKeysFloatValuesPart) dataParts[partId]).add(keyValue.getLongKey(), keyValue.getFloatValue());
}
} else {
// Key and value array pair
LongFloatSortedVectorStorage sortStorage = (LongFloatSortedVectorStorage) storage;
long[] keys = sortStorage.getIndices();
float[] values = sortStorage.getValues();
for (int i = 0; i < keys.length; i++) {
int partId = computeHashCode(hasher, keys[i]) % dataPartNum;
((HashLongKeysFloatValuesPart) dataParts[partId]).add(keys[i], values[i]);
}
}
}
}
Aggregations