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);
}
}
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;
}
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);
}
}
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());
}
}
}
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;
}
Aggregations