Search in sources :

Example 31 with CompIntFloatVector

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

the class MixedBinaryOutZAExecutor method apply.

private static Vector apply(CompIntFloatVector v1, IntDummyVector v2, Binary op) {
    IntFloatVector[] parts = v1.getPartitions();
    Storage[] resParts = StorageSwitch.applyComp(v1, v2, op);
    if (v1.size() > v2.size()) {
        int subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
        int[] v2Indices = v2.getIndices();
        for (int i = 0; i < v2Indices.length; i++) {
            int idx = v2Indices[i];
            int pidx = (int) (idx / subDim);
            int subidx = idx % subDim;
            if (parts[pidx].hasKey(subidx)) {
                ((IntFloatVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 1));
            }
        }
    } else {
        int base = 0;
        for (int i = 0; i < parts.length; i++) {
            IntFloatVector part = parts[i];
            IntFloatVectorStorage resPart = (IntFloatVectorStorage) resParts[i];
            if (part.isDense()) {
                float[] partValues = part.getStorage().getValues();
                float[] resPartValues = resPart.getValues();
                for (int j = 0; j < partValues.length; j++) {
                    if (v2.hasKey(j + base)) {
                        resPartValues[j] = op.apply(partValues[j], v2.get(j + base));
                    }
                }
            } else if (part.isSparse()) {
                ObjectIterator<Int2FloatMap.Entry> piter = part.getStorage().entryIterator();
                while (piter.hasNext()) {
                    Int2FloatMap.Entry entry = piter.next();
                    int idx = entry.getIntKey();
                    if (v2.hasKey(idx + base)) {
                        resPart.set(idx, op.apply(entry.getFloatValue(), v2.get(idx + base)));
                    }
                }
            } else {
                // sorted
                if (op.isKeepStorage()) {
                    int[] partIndices = part.getStorage().getIndices();
                    float[] partValues = part.getStorage().getValues();
                    int[] resPartIndices = resPart.getIndices();
                    float[] resPartValues = resPart.getValues();
                    for (int j = 0; j < partIndices.length; j++) {
                        int idx = partIndices[j];
                        if (v2.hasKey(idx + base)) {
                            resPartIndices[j] = idx;
                            resPartValues[j] = op.apply(partValues[j], v2.get(idx + base));
                        }
                    }
                } else {
                    int[] partIndices = part.getStorage().getIndices();
                    float[] partValues = part.getStorage().getValues();
                    for (int j = 0; j < partIndices.length; j++) {
                        int idx = partIndices[j];
                        if (v2.hasKey(idx + base)) {
                            resPart.set(idx, op.apply(partValues[j], v2.get(idx + base)));
                        }
                    }
                }
            }
            base += part.getDim();
        }
    }
    IntFloatVector[] res = new IntFloatVector[parts.length];
    int i = 0;
    for (IntFloatVector part : parts) {
        res[i] = new IntFloatVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (IntFloatVectorStorage) resParts[i]);
        i++;
    }
    return new CompIntFloatVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), res, v1.getSubDim());
}
Also used : CompIntFloatVector(com.tencent.angel.ml.math2.vector.CompIntFloatVector) IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage) IntIntVectorStorage(com.tencent.angel.ml.math2.storage.IntIntVectorStorage) Storage(com.tencent.angel.ml.math2.storage.Storage) LongIntVectorStorage(com.tencent.angel.ml.math2.storage.LongIntVectorStorage) IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage) LongDoubleVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage) IntDoubleVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage) LongLongVectorStorage(com.tencent.angel.ml.math2.storage.LongLongVectorStorage) LongFloatVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatVectorStorage) IntLongVectorStorage(com.tencent.angel.ml.math2.storage.IntLongVectorStorage) Int2FloatMap(it.unimi.dsi.fastutil.ints.Int2FloatMap) CompIntFloatVector(com.tencent.angel.ml.math2.vector.CompIntFloatVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator)

Example 32 with CompIntFloatVector

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

the class UpdateColsFunc method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    PartitionUpdateColsParam param = (PartitionUpdateColsParam) partParam;
    int[] rows = param.rows;
    long[] cols = param.cols;
    Vector vector = param.vector;
    UpdateOp op = param.op;
    int matId = param.getMatrixId();
    int partitionId = param.getPartKey().getPartitionId();
    RowBasedPartition partition = (RowBasedPartition) psContext.getMatrixStorageManager().getPart(matId, partitionId);
    switch(partition.getRowType()) {
        case T_DOUBLE_DENSE:
        case T_DOUBLE_SPARSE:
            {
                ServerIntDoubleRow[] doubles = new ServerIntDoubleRow[rows.length];
                for (int r = 0; r < rows.length; r++) doubles[r] = (ServerIntDoubleRow) partition.getRow(rows[r]);
                doUpdate((CompIntDoubleVector) vector, rows, cols, doubles, op);
                return;
            }
        case T_DOUBLE_SPARSE_LONGKEY:
            {
                ServerLongDoubleRow[] doubles = new ServerLongDoubleRow[rows.length];
                for (int r = 0; r < rows.length; r++) doubles[r] = (ServerLongDoubleRow) partition.getRow(rows[r]);
                doUpdate((CompIntDoubleVector) vector, rows, cols, doubles, op);
                return;
            }
        case T_FLOAT_DENSE:
        case T_FLOAT_SPARSE:
            {
                ServerIntFloatRow[] floats = new ServerIntFloatRow[rows.length];
                for (int r = 0; r < rows.length; r++) floats[r] = (ServerIntFloatRow) partition.getRow(rows[r]);
                doUpdate((CompIntFloatVector) vector, rows, cols, floats, op);
                return;
            }
        case T_FLOAT_SPARSE_LONGKEY:
            {
                ServerLongFloatRow[] floats = new ServerLongFloatRow[rows.length];
                for (int r = 0; r < rows.length; r++) floats[r] = (ServerLongFloatRow) partition.getRow(rows[r]);
                doUpdate((CompIntFloatVector) vector, rows, cols, floats, op);
                return;
            }
        default:
            throw new AngelException("Data type should be double or float!");
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) CompIntFloatVector(com.tencent.angel.ml.math2.vector.CompIntFloatVector) UpdateOp(com.tencent.angel.ps.server.data.request.UpdateOp) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) CompIntFloatVector(com.tencent.angel.ml.math2.vector.CompIntFloatVector) CompIntDoubleVector(com.tencent.angel.ml.math2.vector.CompIntDoubleVector) Vector(com.tencent.angel.ml.math2.vector.Vector) CompIntDoubleVector(com.tencent.angel.ml.math2.vector.CompIntDoubleVector)

Example 33 with CompIntFloatVector

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

the class MatrixUtils method rbCompDense2Blas.

public static BlasFloatMatrix rbCompDense2Blas(RBCompIntFloatMatrix mat) {
    assert mat != null;
    int dim = (int) mat.getDim();
    int subDim = mat.getSubDim();
    CompIntFloatVector[] rows = mat.getRows();
    float[] data = new float[rows.length * dim];
    int rowId = 0;
    for (CompIntFloatVector row : rows) {
        IntFloatVector[] partitions = row.getPartitions();
        int partId = 0;
        for (IntFloatVector part : partitions) {
            assert part.isDense();
            float[] src = part.getStorage().getValues();
            System.arraycopy(src, 0, data, rowId * dim + partId * subDim, src.length);
            partId += 1;
        }
        rowId += 1;
    }
    return MFactory.denseFloatMatrix(rows.length, dim, data);
}
Also used : CompIntFloatVector(com.tencent.angel.ml.math2.vector.CompIntFloatVector) CompIntFloatVector(com.tencent.angel.ml.math2.vector.CompIntFloatVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Aggregations

CompIntFloatVector (com.tencent.angel.ml.math2.vector.CompIntFloatVector)33 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)32 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)24 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)24 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)24 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)24 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)24 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)24 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)24 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)24 Storage (com.tencent.angel.ml.math2.storage.Storage)24 Int2FloatMap (it.unimi.dsi.fastutil.ints.Int2FloatMap)23 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)23 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)17 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)16 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)16 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)16 IntIntSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage)16 IntIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage)16 IntLongSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntLongSortedVectorStorage)16