Search in sources :

Example 66 with Vector

use of com.tencent.angel.ml.math2.vector.Vector in project angel by Tencent.

the class CooIntFloatMatrix method getRow.

@Override
public Vector getRow(int idx) {
    IntArrayList cols = new IntArrayList();
    FloatArrayList data = new FloatArrayList();
    for (int i = 0; i < rowIndices.length; i++) {
        if (rowIndices[i] == idx) {
            cols.add(colIndices[i]);
            data.add(values[i]);
        }
    }
    IntFloatSparseVectorStorage storage = new IntFloatSparseVectorStorage(shape[1], cols.toIntArray(), data.toFloatArray());
    return new IntFloatVector(getMatrixId(), idx, getClock(), shape[1], storage);
}
Also used : IntFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage) FloatArrayList(it.unimi.dsi.fastutil.floats.FloatArrayList) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 67 with Vector

use of com.tencent.angel.ml.math2.vector.Vector 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 68 with Vector

use of com.tencent.angel.ml.math2.vector.Vector in project angel by Tencent.

the class BlasFloatMatrix method setRow.

public Matrix setRow(int i, Vector v) {
    if (v instanceof IntFloatVector) {
        float[] rowData;
        if (v.isDense()) {
            rowData = ((IntFloatVector) v).getStorage().getValues();
        } else if (v.isSparse()) {
            rowData = new float[numCols];
            ObjectIterator<Int2FloatMap.Entry> iter = ((IntFloatVector) v).getStorage().entryIterator();
            while (iter.hasNext()) {
                Int2FloatMap.Entry entry = iter.next();
                int j = entry.getIntKey();
                rowData[j] = entry.getFloatValue();
            }
        } else {
            // sorted
            rowData = new float[numCols];
            int[] idxs = ((IntFloatVector) v).getStorage().getIndices();
            float[] values = ((IntFloatVector) v).getStorage().getValues();
            int size = ((IntFloatVector) v).size();
            for (int k = 0; k < size; k++) {
                int j = idxs[k];
                rowData[j] = values[k];
            }
        }
        System.arraycopy(rowData, 0, data, i * numCols, numCols);
    } else if (v instanceof IntLongVector) {
        long[] rowData;
        if (v.isDense()) {
            rowData = ((IntLongVector) v).getStorage().getValues();
        } else if (v.isSparse()) {
            rowData = new long[numCols];
            ObjectIterator<Int2LongMap.Entry> iter = ((IntLongVector) v).getStorage().entryIterator();
            while (iter.hasNext()) {
                Int2LongMap.Entry entry = iter.next();
                int j = entry.getIntKey();
                rowData[j] = entry.getLongValue();
            }
        } else {
            // sorted
            rowData = new long[numCols];
            int[] idxs = ((IntLongVector) v).getStorage().getIndices();
            long[] values = ((IntLongVector) v).getStorage().getValues();
            int size = ((IntLongVector) v).size();
            for (int k = 0; k < size; k++) {
                int j = idxs[k];
                rowData[j] = values[k];
            }
        }
        for (int j = 0; j < numCols; j++) {
            data[i * numCols + j] = rowData[j];
        }
    } else if (v instanceof IntIntVector) {
        int[] rowData;
        if (v.isDense()) {
            rowData = ((IntIntVector) v).getStorage().getValues();
        } else if (v.isSparse()) {
            rowData = new int[numCols];
            ObjectIterator<Int2IntMap.Entry> iter = ((IntIntVector) v).getStorage().entryIterator();
            while (iter.hasNext()) {
                Int2IntMap.Entry entry = iter.next();
                int j = entry.getIntKey();
                rowData[j] = entry.getIntValue();
            }
        } else {
            // sorted
            rowData = new int[numCols];
            int[] idxs = ((IntIntVector) v).getStorage().getIndices();
            int[] values = ((IntIntVector) v).getStorage().getValues();
            int size = ((IntIntVector) v).size();
            for (int k = 0; k < size; k++) {
                int j = idxs[k];
                rowData[j] = values[k];
            }
        }
        for (int j = 0; j < numCols; j++) {
            data[i * numCols + j] = rowData[j];
        }
    } else if (v instanceof IntDummyVector) {
        int[] rowData = new int[numCols];
        int[] idxs = ((IntDummyVector) v).getIndices();
        int size = ((IntDummyVector) v).size();
        for (int k = 0; k < size; k++) {
            int j = idxs[k];
            rowData[j] = 1;
        }
        for (int j = 0; j < numCols; j++) {
            data[i * numCols + j] = rowData[j];
        }
    } else {
        throw new AngelException("The operation is not supported!");
    }
    return this;
}
Also used : IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) AngelException(com.tencent.angel.exception.AngelException) IntIntVector(com.tencent.angel.ml.math2.vector.IntIntVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator) IntDummyVector(com.tencent.angel.ml.math2.vector.IntDummyVector) Int2FloatMap(it.unimi.dsi.fastutil.ints.Int2FloatMap) Int2LongMap(it.unimi.dsi.fastutil.ints.Int2LongMap) Int2IntMap(it.unimi.dsi.fastutil.ints.Int2IntMap)

Example 69 with Vector

use of com.tencent.angel.ml.math2.vector.Vector 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 70 with Vector

use of com.tencent.angel.ml.math2.vector.Vector 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)

Aggregations

IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)189 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)188 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)188 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)186 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)185 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)183 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)183 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)182 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)170 Storage (com.tencent.angel.ml.math2.storage.Storage)169 LongDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage)127 LongFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage)125 LongLongSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongLongSparseVectorStorage)121 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)119 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)119 LongIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongIntSparseVectorStorage)119 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)118 LongDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSortedVectorStorage)118 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)117 LongFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSortedVectorStorage)117