Search in sources :

Example 51 with IntFloatVector

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

the class Node method deepClone.

@Override
public com.tencent.angel.graph.data.Node deepClone() {
    IntFloatVector cloneFeats = feats.clone();
    long[] cloneNeighbors = new long[neighbors.length];
    System.arraycopy(neighbors, 0, cloneNeighbors, 0, neighbors.length);
    if (types == null) {
        return new com.tencent.angel.graph.data.Node(cloneFeats, cloneNeighbors);
    } else {
        int[] cloneTypes = new int[types.length];
        System.arraycopy(types, 0, cloneTypes, 0, types.length);
        return new com.tencent.angel.graph.data.Node(cloneFeats, cloneNeighbors, cloneTypes);
    }
}
Also used : IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 52 with IntFloatVector

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

the class SampleUtils method sampleNodeFeatByCount.

public static IntFloatVector[] sampleNodeFeatByCount(ServerRow row, int count, long seed) {
    Random r = new Random(seed);
    IntFloatVector[] feats = new IntFloatVector[count];
    int bound = row.size() - count;
    int skip = bound > 0 ? r.nextInt(bound) : 0;
    ObjectIterator<Entry<IElement>> it = (((ServerLongAnyRow) row).getStorage()).iterator();
    it.skip(skip);
    for (int i = 0; i < count; i++) {
        feats[i] = ((GraphNode) it.next().getValue()).getFeats();
    }
    return feats;
}
Also used : Entry(it.unimi.dsi.fastutil.longs.Long2ObjectMap.Entry) Random(java.util.Random) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 53 with IntFloatVector

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

the class PartGetNodeFeatsResult method deserialize.

@Override
public void deserialize(ByteBuf input) {
    partId = ByteBufSerdeUtils.deserializeInt(input);
    int size = ByteBufSerdeUtils.deserializeInt(input);
    nodeIdTofeats = new Long2ObjectOpenHashMap<>(size);
    for (int i = 0; i < size; i++) {
        long nodeId = ByteBufSerdeUtils.deserializeLong(input);
        IntFloatVector nodeFeats = (IntFloatVector) ByteBufSerdeUtils.deserializeVector(input);
        nodeIdTofeats.put(nodeId, nodeFeats);
    }
}
Also used : IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 54 with IntFloatVector

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

the class GetEdgeFeats 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();
                ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
                Long2ObjectOpenHashMap<IntFloatVector[]> nodeIdToFeats = new Long2ObjectOpenHashMap<>(nodeIds.length);
                for (long nodeId : nodeIds) {
                    if (row.get(nodeId) == null) {
                        // If node not exist, just skip
                        continue;
                    }
                    IntFloatVector[] edgeFeats = ((GraphNode) (row.get(nodeId))).getEdgeFeatures();
                    if (edgeFeats != null) {
                        nodeIdToFeats.put(nodeId, edgeFeats);
                    }
                }
                return new PartGetEdgeFeatsResult(param.getPartKey().getPartitionId(), nodeIdToFeats);
            }
        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) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 55 with IntFloatVector

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

the class NodeUtils method deserialize.

public static IntFloatVector deserialize(ByteBuf input) {
    IntFloatVector feats;
    int dim = input.readInt();
    int len = input.readInt();
    StorageMethod storageMethod = StorageMethod.valuesOf(input.readInt());
    switch(storageMethod) {
        case DENSE:
            {
                float[] values = new float[len];
                for (int i = 0; i < len; i++) {
                    values[i] = input.readFloat();
                }
                feats = VFactory.denseFloatVector(values);
                break;
            }
        case SPARSE:
            {
                feats = VFactory.sparseFloatVector(dim, len);
                for (int i = 0; i < len; i++) {
                    feats.set(input.readInt(), input.readFloat());
                }
                break;
            }
        case SORTED:
            {
                int[] keys = new int[len];
                float[] values = new float[len];
                for (int i = 0; i < len; i++) {
                    keys[i] = input.readInt();
                    values[i] = input.readFloat();
                }
                feats = VFactory.sortedFloatVector(dim, keys, values);
                break;
            }
        default:
            throw new UnsupportedOperationException("Unsupport storage type " + storageMethod);
    }
    return feats;
}
Also used : StorageMethod(com.tencent.angel.ps.storage.vector.storage.StorageMethod) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Aggregations

IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)104 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)60 Int2FloatMap (it.unimi.dsi.fastutil.ints.Int2FloatMap)57 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)50 CompIntFloatVector (com.tencent.angel.ml.math2.vector.CompIntFloatVector)34 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)33 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)32 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)32 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)31 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)30 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)30 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)30 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)30 Storage (com.tencent.angel.ml.math2.storage.Storage)30 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)25 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)21 AngelException (com.tencent.angel.exception.AngelException)20 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)20 IntIntSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage)20 IntIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage)20