Search in sources :

Example 1 with NeighborsAliasTableElement

use of com.tencent.angel.graph.psf.neighbors.samplebyaliastable.samplealiastable.NeighborsAliasTableElement in project angel by Tencent.

the class PartInitNeighborAliasTableParam method serialize.

@Override
public void serialize(ByteBuf buf) {
    super.serialize(buf);
    long nodeId;
    NeighborsAliasTableElement neighbors;
    int writeIndex = buf.writerIndex();
    int numNodesWriten = 0;
    buf.writeInt(0);
    for (int i = startIndex; i < endIndex; i++) {
        // get nodeId
        nodeId = nodeIds[i];
        // get  data the nodeId mapped 1.neighbors 2.tags 3.attrs
        neighbors = nodeId2Neighbors.get(nodeId);
        if (neighbors == null)
            continue;
        buf.writeLong(nodeId);
        buf.writeInt(neighbors.getNodesNum());
        // write out edges
        long[] nbrs = neighbors.getNeighborIds();
        for (int j = 0; j < nbrs.length; j++) {
            buf.writeLong(nbrs[j]);
        }
        // write out tags
        float[] accept = neighbors.getAccept();
        assert (accept.length == nbrs.length);
        for (int j = 0; j < accept.length; j++) {
            buf.writeFloat(accept[j]);
        }
        // write out attrs
        int[] alias = neighbors.getAlias();
        assert (alias.length == nbrs.length);
        for (int j = 0; j < alias.length; j++) {
            buf.writeInt(alias[j]);
        }
        numNodesWriten++;
    }
    buf.setInt(writeIndex, numNodesWriten);
}
Also used : NeighborsAliasTableElement(com.tencent.angel.graph.psf.neighbors.samplebyaliastable.samplealiastable.NeighborsAliasTableElement)

Example 2 with NeighborsAliasTableElement

use of com.tencent.angel.graph.psf.neighbors.samplebyaliastable.samplealiastable.NeighborsAliasTableElement in project angel by Tencent.

the class PartInitNeighborAliasTableParam method bufferLen.

@Override
public int bufferLen() {
    int len = super.bufferLen();
    len += 4;
    for (int i = startIndex; i < endIndex; i++) {
        NeighborsAliasTableElement nbrElem = nodeId2Neighbors.get(nodeIds[i]);
        if (nbrElem != null) {
            int numNodes = nbrElem.getNodesNum();
            // nodeId and numNodes
            len += 12;
            len += Long.BYTES * numNodes + Float.BYTES * numNodes + Integer.BYTES * numNodes;
        }
    }
    return len;
}
Also used : NeighborsAliasTableElement(com.tencent.angel.graph.psf.neighbors.samplebyaliastable.samplealiastable.NeighborsAliasTableElement)

Example 3 with NeighborsAliasTableElement

use of com.tencent.angel.graph.psf.neighbors.samplebyaliastable.samplealiastable.NeighborsAliasTableElement in project angel by Tencent.

the class PartInitNeighborAliasTableParam method deserialize.

@Override
public void deserialize(ByteBuf buf) {
    super.deserialize(buf);
    int len = buf.readInt();
    nodeId2Neighbors = new Long2ObjectArrayMap<>(len);
    for (int i = 0; i < len; i++) {
        long nodeId = buf.readLong();
        int numNeighbor = buf.readInt();
        long[] nbrs = new long[numNeighbor];
        float[] accept = new float[numNeighbor];
        int[] alias = new int[numNeighbor];
        for (int j = 0; j < numNeighbor; j++) {
            nbrs[j] = buf.readLong();
        }
        for (int j = 0; j < numNeighbor; j++) {
            accept[j] = buf.readFloat();
        }
        for (int j = 0; j < numNeighbor; j++) {
            alias[j] = buf.readInt();
        }
        NeighborsAliasTableElement nbrElem = new NeighborsAliasTableElement(nbrs, accept, alias);
        nodeId2Neighbors.put(nodeId, nbrElem);
    }
}
Also used : NeighborsAliasTableElement(com.tencent.angel.graph.psf.neighbors.samplebyaliastable.samplealiastable.NeighborsAliasTableElement)

Example 4 with NeighborsAliasTableElement

use of com.tencent.angel.graph.psf.neighbors.samplebyaliastable.samplealiastable.NeighborsAliasTableElement in project angel by Tencent.

the class InitNeighborAliasTable method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    PartInitNeighborAliasTableParam param = (PartInitNeighborAliasTableParam) partParam;
    ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
    RowBasedPartition part = (RowBasedPartition) matrix.getPartition(partParam.getPartKey().getPartitionId());
    ServerLongAnyRow row = (ServerLongAnyRow) part.getRow(0);
    ObjectIterator<Long2ObjectMap.Entry<NeighborsAliasTableElement>> iter = param.getNodeId2Neighbors().long2ObjectEntrySet().iterator();
    row.startWrite();
    try {
        while (iter.hasNext()) {
            Long2ObjectMap.Entry<NeighborsAliasTableElement> entry = iter.next();
            NeighborsAliasTableElement element = entry.getValue();
            if (element == null) {
                row.set(entry.getLongKey(), null);
            } else {
                row.set(entry.getLongKey(), new NeighborsAliasTableElement(element.getNeighborIds(), element.getAccept(), element.getAlias()));
            }
        }
    } finally {
        row.endWrite();
    }
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) NeighborsAliasTableElement(com.tencent.angel.graph.psf.neighbors.samplebyaliastable.samplealiastable.NeighborsAliasTableElement)

Aggregations

NeighborsAliasTableElement (com.tencent.angel.graph.psf.neighbors.samplebyaliastable.samplealiastable.NeighborsAliasTableElement)4 ServerMatrix (com.tencent.angel.ps.storage.matrix.ServerMatrix)1 RowBasedPartition (com.tencent.angel.ps.storage.partition.RowBasedPartition)1 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)1 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)1