use of com.tencent.angel.ml.math2.storage.IntLongDenseVectorStorage in project angel by Tencent.
the class RBLongLongMatrix method diag.
@Override
public Vector diag() {
long[] resArr = new long[rows.length];
for (int i = 0; i < rows.length; i++) {
if (null == rows[i]) {
resArr[i] = 0;
} else {
resArr[i] = rows[i].get(i);
}
}
IntLongDenseVectorStorage storage = new IntLongDenseVectorStorage(resArr);
return new IntLongVector(getMatrixId(), 0, getClock(), resArr.length, storage);
}
use of com.tencent.angel.ml.math2.storage.IntLongDenseVectorStorage in project angel by Tencent.
the class RBCompIntLongMatrix method diag.
@Override
public Vector diag() {
long[] resArr = new long[rows.length];
for (int i = 0; i < rows.length; i++) {
if (null == rows[i]) {
resArr[i] = 0;
} else {
resArr[i] = rows[i].get(i);
}
}
IntLongDenseVectorStorage storage = new IntLongDenseVectorStorage(resArr);
return new IntLongVector(getMatrixId(), 0, getClock(), resArr.length, storage);
}
use of com.tencent.angel.ml.math2.storage.IntLongDenseVectorStorage in project angel by Tencent.
the class HashRouterUtils method splitIntLongVector.
public static void splitIntLongVector(KeyHash hasher, MatrixMeta matrixMeta, IntLongVector vector, KeyValuePart[] dataParts) {
int dataPartNum = dataParts.length;
int dataPartNumMinus1 = dataPartNum - 1;
if (isPow2(dataPartNum)) {
IntLongVectorStorage storage = vector.getStorage();
if (storage.isSparse()) {
// Use iterator
IntLongSparseVectorStorage sparseStorage = (IntLongSparseVectorStorage) storage;
ObjectIterator<Int2LongMap.Entry> iter = sparseStorage.entryIterator();
while (iter.hasNext()) {
Int2LongMap.Entry keyValue = iter.next();
int partId = computeHashCode(hasher, keyValue.getIntKey()) & dataPartNumMinus1;
((HashIntKeysLongValuesPart) dataParts[partId]).add(keyValue.getIntKey(), keyValue.getLongValue());
}
} else if (storage.isDense()) {
// Get values
IntLongDenseVectorStorage denseStorage = (IntLongDenseVectorStorage) storage;
long[] values = denseStorage.getValues();
for (int i = 0; i < values.length; i++) {
int partId = computeHashCode(hasher, i) & dataPartNumMinus1;
((HashIntKeysLongValuesPart) dataParts[partId]).add(i, values[i]);
}
} else {
// Key and value array pair
IntLongSortedVectorStorage sortStorage = (IntLongSortedVectorStorage) storage;
int[] keys = sortStorage.getIndices();
long[] values = sortStorage.getValues();
for (int i = 0; i < keys.length; i++) {
int partId = computeHashCode(hasher, keys[i]) & dataPartNumMinus1;
((HashIntKeysLongValuesPart) dataParts[partId]).add(keys[i], values[i]);
}
}
} else {
IntLongVectorStorage storage = vector.getStorage();
if (storage.isSparse()) {
// Use iterator
IntLongSparseVectorStorage sparseStorage = (IntLongSparseVectorStorage) storage;
ObjectIterator<Int2LongMap.Entry> iter = sparseStorage.entryIterator();
while (iter.hasNext()) {
Int2LongMap.Entry keyValue = iter.next();
int partId = computeHashCode(hasher, keyValue.getIntKey()) % dataPartNum;
((HashIntKeysLongValuesPart) dataParts[partId]).add(keyValue.getIntKey(), keyValue.getLongValue());
}
} else if (storage.isDense()) {
// Get values
IntLongDenseVectorStorage denseStorage = (IntLongDenseVectorStorage) storage;
long[] values = denseStorage.getValues();
for (int i = 0; i < values.length; i++) {
int partId = computeHashCode(hasher, i) % dataPartNum;
((HashIntKeysLongValuesPart) dataParts[partId]).add(i, values[i]);
}
} else {
// Key and value array pair
IntLongSortedVectorStorage sortStorage = (IntLongSortedVectorStorage) storage;
int[] keys = sortStorage.getIndices();
long[] values = sortStorage.getValues();
for (int i = 0; i < keys.length; i++) {
int partId = computeHashCode(hasher, keys[i]) % dataPartNum;
((HashIntKeysLongValuesPart) dataParts[partId]).add(keys[i], values[i]);
}
}
}
}
use of com.tencent.angel.ml.math2.storage.IntLongDenseVectorStorage in project angel by Tencent.
the class RangeRouterUtils method splitIntLongVector.
public static KeyValuePart[] splitIntLongVector(MatrixMeta matrixMeta, IntLongVector vector) {
IntLongVectorStorage storage = vector.getStorage();
if (storage.isSparse()) {
// Get keys and values
IntLongSparseVectorStorage sparseStorage = (IntLongSparseVectorStorage) storage;
int[] keys = sparseStorage.getIndices();
long[] values = sparseStorage.getValues();
return split(matrixMeta, vector.getRowId(), keys, values, false);
} else if (storage.isDense()) {
// Get values
IntLongDenseVectorStorage denseStorage = (IntLongDenseVectorStorage) storage;
long[] values = denseStorage.getValues();
return split(matrixMeta, vector.getRowId(), values);
} else {
// Key and value array pair
IntLongSortedVectorStorage sortStorage = (IntLongSortedVectorStorage) storage;
int[] keys = sortStorage.getIndices();
long[] values = sortStorage.getValues();
return split(matrixMeta, vector.getRowId(), keys, values, true);
}
}
use of com.tencent.angel.ml.math2.storage.IntLongDenseVectorStorage in project angel by Tencent.
the class UpdatePSFTest method testDenseLongUDF.
public void testDenseLongUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(DENSE_LONG_MAT, 0);
int matrixW1Id = client1.getMatrixId();
int[] index = genIndexs(feaNum, nnz);
IntLongVector deltaVec = new IntLongVector(feaNum, new IntLongDenseVectorStorage(feaNum));
for (int i = 0; i < feaNum; i++) {
deltaVec.set(i, i);
}
deltaVec.setRowId(0);
Vector[] updates = new Vector[1];
updates[0] = deltaVec;
client1.asyncUpdate(new IncrementRows(new IncrementRowsParam(matrixW1Id, updates))).get();
IntLongVector row = (IntLongVector) client1.getRow(0);
for (int id : index) {
// System.out.println("id=" + id + ", value=" + row.get(id));
Assert.assertEquals(row.get(id), deltaVec.get(id));
}
Assert.assertTrue(feaNum == row.size());
}
Aggregations