Search in sources :

Example 1 with IntFloatDenseVectorStorage

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

the class RBLongFloatMatrix 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 2 with IntFloatDenseVectorStorage

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

the class BlasFloatMatrix method getRow.

@Override
public Vector getRow(int i) {
    float[] row = new float[numCols];
    System.arraycopy(data, i * numCols, row, 0, numCols);
    IntFloatDenseVectorStorage storage = new IntFloatDenseVectorStorage(row);
    return new IntFloatVector(getMatrixId(), i, getClock(), numCols, storage);
}
Also used : IntFloatDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 3 with IntFloatDenseVectorStorage

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

the class RBCompIntFloatMatrix 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) CompIntFloatVector(com.tencent.angel.ml.math2.vector.CompIntFloatVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 4 with IntFloatDenseVectorStorage

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

the class RBCompLongFloatMatrix 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 5 with IntFloatDenseVectorStorage

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

the class DotMatrixExecutor method apply.

private static Vector apply(BlasFloatMatrix mat, boolean trans, IntLongVector v) {
    int m = mat.getNumRows(), n = mat.getNumCols();
    float[] resArr;
    if (trans) {
        assert m == v.getDim();
        resArr = new float[n];
    } else {
        assert n == v.getDim();
        resArr = new float[m];
    }
    int r = mat.getNumRows(), c = mat.getNumCols();
    float[] data = mat.getData();
    if (v.isDense()) {
        float[] tempArray = ArrayCopy.copy(v.getStorage().getValues(), new float[v.getDim()]);
        if (trans) {
            blas.sgemv("N", c, r, 1.0f, data, c, tempArray, 1, 0.0f, resArr, 1);
        } else {
            blas.sgemv("T", c, r, 1.0f, data, c, tempArray, 1, 0.0f, resArr, 1);
        }
    } else if (v.isSparse()) {
        if (trans) {
            for (int j = 0; j < c; j++) {
                ObjectIterator<Int2LongMap.Entry> iter = v.getStorage().entryIterator();
                while (iter.hasNext()) {
                    Int2LongMap.Entry entry = iter.next();
                    int i = entry.getIntKey();
                    resArr[j] += data[i * c + j] * entry.getLongValue();
                }
            }
        } else {
            for (int i = 0; i < r; i++) {
                ObjectIterator<Int2LongMap.Entry> iter = v.getStorage().entryIterator();
                while (iter.hasNext()) {
                    Int2LongMap.Entry entry = iter.next();
                    int j = entry.getIntKey();
                    resArr[i] += data[i * c + j] * entry.getLongValue();
                }
            }
        }
    } else {
        // sorted
        if (trans) {
            for (int j = 0; j < r; j++) {
                int[] idxs = v.getStorage().getIndices();
                long[] vals = v.getStorage().getValues();
                for (int k = 0; k < idxs.length; k++) {
                    resArr[j] += data[idxs[k] * c + j] * vals[k];
                }
            }
        } else {
            for (int i = 0; i < r; i++) {
                int[] idxs = v.getStorage().getIndices();
                long[] vals = v.getStorage().getValues();
                for (int k = 0; k < idxs.length; k++) {
                    resArr[i] += data[i * c + idxs[k]] * vals[k];
                }
            }
        }
    }
    IntFloatDenseVectorStorage storage = new IntFloatDenseVectorStorage(resArr);
    return new IntFloatVector(v.getMatrixId(), v.getClock(), 0, resArr.length, storage);
}
Also used : IntFloatDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage) Int2LongMap(it.unimi.dsi.fastutil.ints.Int2LongMap) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator)

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