Search in sources :

Example 1 with FloatArrayList

use of it.unimi.dsi.fastutil.floats.FloatArrayList in project angel by Tencent.

the class GetLabels method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    GeneralPartGetParam param = (GeneralPartGetParam) partParam;
    KeyPart keyPart = param.getIndicesPart();
    switch(keyPart.getKeyType()) {
        case LONG:
            {
                // Long type node id
                long[] nodeIds = ((ILongKeyPartOp) keyPart).getKeys();
                ServerLongFloatRow row = (ServerLongFloatRow) psContext.getMatrixStorageManager().getRow(param.getPartKey(), 0);
                LongArrayList keys = new LongArrayList();
                FloatArrayList vals = new FloatArrayList();
                for (int i = 0; i < nodeIds.length; i++) {
                    if (row.exist(nodeIds[i])) {
                        keys.add(nodeIds[i]);
                        vals.add(row.get(nodeIds[i]));
                    }
                }
                return new GetLabelsPartResult(keys.toLongArray(), vals.toFloatArray());
            }
        default:
            {
                // TODO: support String, Int, and Any type node id
                throw new InvalidParameterException("Unsupport index type " + keyPart.getKeyType());
            }
    }
}
Also used : InvalidParameterException(com.tencent.angel.exception.InvalidParameterException) GeneralPartGetParam(com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) ServerLongFloatRow(com.tencent.angel.ps.storage.vector.ServerLongFloatRow) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) FloatArrayList(it.unimi.dsi.fastutil.floats.FloatArrayList)

Example 2 with FloatArrayList

use of it.unimi.dsi.fastutil.floats.FloatArrayList 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 3 with FloatArrayList

use of it.unimi.dsi.fastutil.floats.FloatArrayList in project angel by Tencent.

the class CsrFloatMatrix method getRow.

@Override
public Vector getRow(int idx) {
    IntArrayList cols = new IntArrayList();
    FloatArrayList data = new FloatArrayList();
    int rowNum = indptr.length - 1;
    assert (idx < rowNum);
    for (int i = indptr[idx]; i < indptr[idx + 1]; i++) {
        cols.add(indices[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 4 with FloatArrayList

use of it.unimi.dsi.fastutil.floats.FloatArrayList in project angel by Tencent.

the class CooIntFloatMatrix method getCol.

@Override
public Vector getCol(int idx) {
    IntArrayList cols = new IntArrayList();
    FloatArrayList data = new FloatArrayList();
    for (int i = 0; i < colIndices.length; i++) {
        if (colIndices[i] == idx) {
            cols.add(rowIndices[i]);
            data.add(values[i]);
        }
    }
    IntFloatSparseVectorStorage storage = new IntFloatSparseVectorStorage(shape[0], cols.toIntArray(), data.toFloatArray());
    return new IntFloatVector(getMatrixId(), 0, getClock(), shape[0], 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 5 with FloatArrayList

use of it.unimi.dsi.fastutil.floats.FloatArrayList in project angel by Tencent.

the class CooLongFloatMatrix method getRow.

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

Aggregations

FloatArrayList (it.unimi.dsi.fastutil.floats.FloatArrayList)7 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)4 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)4 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)4 LongArrayList (it.unimi.dsi.fastutil.longs.LongArrayList)3 LongFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage)2 LongFloatVector (com.tencent.angel.ml.math2.vector.LongFloatVector)2 InvalidParameterException (com.tencent.angel.exception.InvalidParameterException)1 GeneralPartGetParam (com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam)1 ServerLongFloatRow (com.tencent.angel.ps.storage.vector.ServerLongFloatRow)1 KeyPart (com.tencent.angel.psagent.matrix.transport.router.KeyPart)1