Search in sources :

Example 91 with PartitionKey

use of com.tencent.angel.PartitionKey in project angel by Tencent.

the class CompLongLongVectorSplitter method split.

@Override
public Map<PartitionKey, RowUpdateSplit> split(Vector vector, List<PartitionKey> parts) {
    LongLongVector[] vecParts = ((CompLongLongVector) vector).getPartitions();
    assert vecParts.length == parts.size();
    Map<PartitionKey, RowUpdateSplit> updateSplitMap = new HashMap<>(parts.size());
    for (int i = 0; i < vecParts.length; i++) {
        updateSplitMap.put(parts.get(i), new CompLongLongRowUpdateSplit(vector.getRowId(), vecParts[i]));
    }
    return updateSplitMap;
}
Also used : CompLongLongVector(com.tencent.angel.ml.math2.vector.CompLongLongVector) HashMap(java.util.HashMap) LongLongVector(com.tencent.angel.ml.math2.vector.LongLongVector) CompLongLongVector(com.tencent.angel.ml.math2.vector.CompLongLongVector) CompLongLongRowUpdateSplit(com.tencent.angel.psagent.matrix.oplog.cache.CompLongLongRowUpdateSplit) PartitionKey(com.tencent.angel.PartitionKey) RowUpdateSplit(com.tencent.angel.psagent.matrix.oplog.cache.RowUpdateSplit) CompLongLongRowUpdateSplit(com.tencent.angel.psagent.matrix.oplog.cache.CompLongLongRowUpdateSplit)

Example 92 with PartitionKey

use of com.tencent.angel.PartitionKey in project angel by Tencent.

the class RowUpdateSplitUtils method split.

/**
 * Split a array to vector splits by vector partitions in PS
 *
 * @param rowId need update row id
 * @param values column values, the dimension must equals to indices
 * @param parts partitions that contain this vector, this partition must be sorted by part start
 * column index
 * @return part to split map
 */
public static Map<PartitionKey, RowUpdateSplit> split(int rowId, int[] values, List<PartitionKey> parts) {
    Map<PartitionKey, RowUpdateSplit> ret = new HashMap<>();
    for (PartitionKey part : parts) {
        if (rowId >= part.getStartRow() && rowId < part.getEndRow()) {
            RowUpdateSplit split = new DenseIntRowUpdateSplit(rowId, (int) part.getStartCol(), (int) part.getEndCol(), values);
            ret.put(part, split);
        }
    }
    return ret;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) PartitionKey(com.tencent.angel.PartitionKey)

Example 93 with PartitionKey

use of com.tencent.angel.PartitionKey in project angel by Tencent.

the class RowUpdateSplitUtils method split.

public static Map<PartitionKey, HashIndicesView> split(int[] indices, List<PartitionKey> parts) {
    Map<PartitionKey, HashIndicesView> ret = new HashMap<>();
    Map<Integer, IntArrayList> partIndex2Indices = new HashMap<>();
    SortedMap<Integer, Integer> key2partIndex = new TreeMap<>();
    for (int i = 0; i < parts.size(); i++) {
        key2partIndex.put((int) parts.get(i).getEndCol(), parts.get(i).getPartitionId());
    }
    for (int j = 0; j < indices.length; j++) {
        int hash = HashUtils.getFNV1_32_HashCode(indices[j]);
        SortedMap<Integer, Integer> subMap = key2partIndex.tailMap(hash);
        int key = subMap.firstKey();
        int partIndex = subMap.get(key);
        if (partIndex2Indices.containsKey(partIndex)) {
            partIndex2Indices.get(partIndex).add(indices[j]);
        } else {
            IntArrayList splitIndices = new IntArrayList();
            splitIndices.add(indices[j]);
            partIndex2Indices.put(partIndex, splitIndices);
        }
    }
    for (Map.Entry<Integer, IntArrayList> entry : partIndex2Indices.entrySet()) {
        ret.put(parts.get(entry.getKey()), new HashIndicesView(entry.getValue().toIntArray()));
    }
    return ret;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) PartitionKey(com.tencent.angel.PartitionKey) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 94 with PartitionKey

use of com.tencent.angel.PartitionKey in project angel by Tencent.

the class RowUpdateSplitUtils method split.

/**
 * Split a array to vector splits by vector partitions in PS
 *
 * @param rowId need update row id
 * @param values column values, the dimension must equals to indices
 * @param parts partitions that contain this vector, this partition must be sorted by part start
 * column index
 * @return part to split map
 */
public static Map<PartitionKey, RowUpdateSplit> split(int rowId, float[] values, List<PartitionKey> parts) {
    Map<PartitionKey, RowUpdateSplit> ret = new HashMap<>();
    for (PartitionKey part : parts) {
        if (rowId >= part.getStartRow() && rowId < part.getEndRow()) {
            RowUpdateSplit split = new DenseFloatRowUpdateSplit(rowId, (int) part.getStartCol(), (int) part.getEndCol(), values);
            ret.put(part, split);
        }
    }
    return ret;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) PartitionKey(com.tencent.angel.PartitionKey)

Example 95 with PartitionKey

use of com.tencent.angel.PartitionKey in project angel by Tencent.

the class RowUpdateSplitUtils method split.

/**
 * Split a array to vector splits by vector partitions in PS
 *
 * @param rowId need update row id
 * @param values column values, the dimension must equals to indices
 * @param parts partitions that contain this vector, this partition must be sorted by part start
 * column index
 * @return part to split map
 */
public static Map<PartitionKey, RowUpdateSplit> split(int rowId, double[] values, List<PartitionKey> parts) {
    Map<PartitionKey, RowUpdateSplit> ret = new HashMap<>();
    for (PartitionKey part : parts) {
        if (rowId >= part.getStartRow() && rowId < part.getEndRow()) {
            RowUpdateSplit split = new DenseDoubleRowUpdateSplit(rowId, (int) part.getStartCol(), (int) part.getEndCol(), values);
            ret.put(part, split);
        }
    }
    return ret;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) PartitionKey(com.tencent.angel.PartitionKey)

Aggregations

PartitionKey (com.tencent.angel.PartitionKey)170 ArrayList (java.util.ArrayList)58 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)40 PartitionGetParam (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)28 PartitionGetResult (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)24 PartitionUpdateParam (com.tencent.angel.ml.matrix.psf.update.base.PartitionUpdateParam)22 HashMap (java.util.HashMap)20 ByteBuf (io.netty.buffer.ByteBuf)14 KeyPart (com.tencent.angel.psagent.matrix.transport.router.KeyPart)12 FutureResult (com.tencent.angel.psagent.matrix.transport.FutureResult)10 RowUpdateSplit (com.tencent.angel.psagent.matrix.oplog.cache.RowUpdateSplit)9 MatrixTransportClient (com.tencent.angel.psagent.matrix.transport.MatrixTransportClient)9 KeyValuePart (com.tencent.angel.psagent.matrix.transport.router.KeyValuePart)9 Test (org.junit.Test)9 MapResponseCache (com.tencent.angel.psagent.matrix.transport.response.MapResponseCache)7 ResponseCache (com.tencent.angel.psagent.matrix.transport.response.ResponseCache)7 Map (java.util.Map)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 AngelException (com.tencent.angel.exception.AngelException)5 CompStreamKeyValuePart (com.tencent.angel.psagent.matrix.transport.router.CompStreamKeyValuePart)5