Search in sources :

Example 11 with IntFloatDenseVectorStorage

use of com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage in project angel by Tencent.

the class RangeRouterUtils method splitIntFloatVector.

public static KeyValuePart[] splitIntFloatVector(MatrixMeta matrixMeta, IntFloatVector vector) {
    IntFloatVectorStorage storage = vector.getStorage();
    if (storage.isSparse()) {
        // Get keys and values
        IntFloatSparseVectorStorage sparseStorage = (IntFloatSparseVectorStorage) storage;
        int[] keys = sparseStorage.getIndices();
        float[] values = sparseStorage.getValues();
        return split(matrixMeta, vector.getRowId(), keys, values, false);
    } else if (storage.isDense()) {
        // Get values
        IntFloatDenseVectorStorage denseStorage = (IntFloatDenseVectorStorage) storage;
        float[] values = denseStorage.getValues();
        return split(matrixMeta, vector.getRowId(), values);
    } else {
        // Key and value array pair
        IntFloatSortedVectorStorage sortStorage = (IntFloatSortedVectorStorage) storage;
        int[] keys = sortStorage.getIndices();
        float[] values = sortStorage.getValues();
        return split(matrixMeta, vector.getRowId(), keys, values, true);
    }
}
Also used : IntFloatSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage) IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage) IntFloatDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage) IntFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)

Example 12 with IntFloatDenseVectorStorage

use of com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage in project angel by Tencent.

the class CompIntFloatRowUpdateSplit method serialize.

@Override
public void serialize(ByteBuf buf) {
    super.serialize(buf);
    IntFloatVectorStorage storage = split.getStorage();
    if (storage instanceof IntFloatSparseVectorStorage) {
        buf.writeInt(storage.size());
        ObjectIterator<Int2FloatMap.Entry> iter = storage.entryIterator();
        Int2FloatMap.Entry entry;
        while (iter.hasNext()) {
            entry = iter.next();
            buf.writeInt(entry.getIntKey());
            buf.writeFloat(entry.getFloatValue());
        }
    } else if (storage instanceof IntFloatSortedVectorStorage) {
        buf.writeInt(storage.size());
        int[] indices = storage.getIndices();
        float[] values = storage.getValues();
        for (int i = 0; i < indices.length; i++) {
            buf.writeInt(indices[i]);
            buf.writeFloat(values[i]);
        }
    } else if (storage instanceof IntFloatDenseVectorStorage) {
        float[] values = storage.getValues();
        int writeSize = values.length < maxItemNum ? values.length : maxItemNum;
        buf.writeInt(writeSize);
        for (int i = 0; i < writeSize; i++) {
            buf.writeFloat(values[i]);
        }
    } else {
        throw new UnsupportedOperationException("unsupport split for storage " + storage.getClass().getName());
    }
}
Also used : IntFloatSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage) IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage) IntFloatDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage) IntFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage) Int2FloatMap(it.unimi.dsi.fastutil.ints.Int2FloatMap)

Example 13 with IntFloatDenseVectorStorage

use of com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage in project angel by Tencent.

the class RBIntFloatMatrix method diag.

@Override
public Vector diag() {
    float[] resArr = new float[rows.length];
    for (int i = 0; i < rows.length; i++) {
        if (null == rows[i]) {
            resArr[i] = 0;
        } else {
            resArr[i] = rows[i].get(i);
        }
    }
    IntFloatDenseVectorStorage storage = new IntFloatDenseVectorStorage(resArr);
    return new IntFloatVector(getMatrixId(), 0, getClock(), resArr.length, storage);
}
Also used : IntFloatDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 14 with IntFloatDenseVectorStorage

use of com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage in project angel by Tencent.

the class RBIntFloatMatrix method dot.

@Override
public Vector dot(Vector other) {
    float[] resArr = new float[rows.length];
    for (int i = 0; i < rows.length; i++) {
        resArr[i] = (float) rows[i].dot(other);
    }
    IntFloatDenseVectorStorage storage = new IntFloatDenseVectorStorage(resArr);
    return new IntFloatVector(matrixId, 0, clock, rows.length, storage);
}
Also used : IntFloatDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 15 with IntFloatDenseVectorStorage

use of com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage in project angel by Tencent.

the class BlasFloatMatrix method getCol.

@Override
public Vector getCol(int j) {
    float[] col = new float[numRows];
    for (int i = 0; i < numRows; i++) {
        col[i] = data[i * numCols + j];
    }
    IntFloatDenseVectorStorage storage = new IntFloatDenseVectorStorage(col);
    return new IntFloatVector(getMatrixId(), 0, getClock(), numRows, storage);
}
Also used : IntFloatDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Aggregations

IntFloatDenseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage)19 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)16 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)3 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)3 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)3 Int2FloatMap (it.unimi.dsi.fastutil.ints.Int2FloatMap)3 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)3 CompIntFloatVector (com.tencent.angel.ml.math2.vector.CompIntFloatVector)2 IntDoubleVector (com.tencent.angel.ml.math2.vector.IntDoubleVector)1 IntIntVector (com.tencent.angel.ml.math2.vector.IntIntVector)1 IntLongVector (com.tencent.angel.ml.math2.vector.IntLongVector)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