Search in sources :

Example 1 with IntLongDenseVectorStorage

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);
}
Also used : IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) IntLongDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntLongDenseVectorStorage)

Example 2 with IntLongDenseVectorStorage

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);
}
Also used : CompIntLongVector(com.tencent.angel.ml.math2.vector.CompIntLongVector) IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) IntLongDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntLongDenseVectorStorage)

Example 3 with IntLongDenseVectorStorage

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]);
            }
        }
    }
}
Also used : IntLongSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntLongSparseVectorStorage) IntLongVectorStorage(com.tencent.angel.ml.math2.storage.IntLongVectorStorage) IntLongSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntLongSortedVectorStorage) Int2LongMap(it.unimi.dsi.fastutil.ints.Int2LongMap) IntLongDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntLongDenseVectorStorage)

Example 4 with IntLongDenseVectorStorage

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);
    }
}
Also used : IntLongSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntLongSparseVectorStorage) IntLongVectorStorage(com.tencent.angel.ml.math2.storage.IntLongVectorStorage) IntLongSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntLongSortedVectorStorage) IntLongDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntLongDenseVectorStorage)

Example 5 with IntLongDenseVectorStorage

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());
}
Also used : IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) IncrementRowsParam(com.tencent.angel.ml.matrix.psf.update.update.IncrementRowsParam) IncrementRows(com.tencent.angel.ml.matrix.psf.update.update.IncrementRows) Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) IntLongDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntLongDenseVectorStorage) IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector) Vector(com.tencent.angel.ml.math2.vector.Vector) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) LongLongVector(com.tencent.angel.ml.math2.vector.LongLongVector) IntIntVector(com.tencent.angel.ml.math2.vector.IntIntVector)

Aggregations

IntLongDenseVectorStorage (com.tencent.angel.ml.math2.storage.IntLongDenseVectorStorage)8 IntLongVector (com.tencent.angel.ml.math2.vector.IntLongVector)5 IntLongSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntLongSortedVectorStorage)3 IntLongSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntLongSparseVectorStorage)3 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)3 Int2LongMap (it.unimi.dsi.fastutil.ints.Int2LongMap)2 CompIntLongVector (com.tencent.angel.ml.math2.vector.CompIntLongVector)1 IntDoubleVector (com.tencent.angel.ml.math2.vector.IntDoubleVector)1 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)1 IntIntVector (com.tencent.angel.ml.math2.vector.IntIntVector)1 LongDoubleVector (com.tencent.angel.ml.math2.vector.LongDoubleVector)1 LongFloatVector (com.tencent.angel.ml.math2.vector.LongFloatVector)1 LongIntVector (com.tencent.angel.ml.math2.vector.LongIntVector)1 LongLongVector (com.tencent.angel.ml.math2.vector.LongLongVector)1 Vector (com.tencent.angel.ml.math2.vector.Vector)1 IncrementRows (com.tencent.angel.ml.matrix.psf.update.update.IncrementRows)1 IncrementRowsParam (com.tencent.angel.ml.matrix.psf.update.update.IncrementRowsParam)1 MatrixClient (com.tencent.angel.psagent.matrix.MatrixClient)1 Worker (com.tencent.angel.worker.Worker)1