use of com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp in project angel by Tencent.
the class ServerRowUtils method getByKeys.
public static ValuePart getByKeys(ServerRow row, KeyPart keyPart) {
ValuePart result;
if (keyPart instanceof IIntKeyPartOp) {
// Index is int
IIntKeyPartOp intKeyPart = (IIntKeyPartOp) keyPart;
if (row instanceof ServerIntFloatRow) {
float[] values = ((ServerIntFloatRow) row).get(intKeyPart.getKeys());
result = new FloatValuesPart(values);
} else if (row instanceof ServerIntDoubleRow) {
double[] values = ((ServerIntDoubleRow) row).get(intKeyPart.getKeys());
result = new DoubleValuesPart(values);
} else if (row instanceof ServerIntIntRow) {
int[] values = ((ServerIntIntRow) row).get(intKeyPart.getKeys());
result = new IntValuesPart(values);
} else if (row instanceof ServerIntLongRow) {
long[] values = ((ServerIntLongRow) row).get(intKeyPart.getKeys());
result = new LongValuesPart(values);
} else {
throw new UnsupportedOperationException("Unsupport row type " + row.getClass().getName());
}
} else if (keyPart instanceof ILongKeyPartOp) {
// Index is long
ILongKeyPartOp longKeyPart = (ILongKeyPartOp) keyPart;
if (row instanceof ServerLongFloatRow) {
float[] values = ((ServerLongFloatRow) row).get(longKeyPart.getKeys());
result = new FloatValuesPart(values);
} else if (row instanceof ServerLongDoubleRow) {
double[] values = ((ServerLongDoubleRow) row).get(longKeyPart.getKeys());
result = new DoubleValuesPart(values);
} else if (row instanceof ServerLongIntRow) {
int[] values = ((ServerLongIntRow) row).get(longKeyPart.getKeys());
result = new IntValuesPart(values);
} else if (row instanceof ServerLongLongRow) {
long[] values = ((ServerLongLongRow) row).get(longKeyPart.getKeys());
result = new LongValuesPart(values);
} else {
throw new UnsupportedOperationException("Unsupport row type " + row.getClass().getName());
}
} else {
throw new UnsupportedOperationException("Unsupport index type " + keyPart.getClass().getName());
}
return result;
}
use of com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp in project angel by Tencent.
the class SampleNeighborWithType method partitionGet.
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
PartSampleNeighborWithTypeParam sampleParam = (PartSampleNeighborWithTypeParam) partParam;
ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, partParam);
ILongKeyPartOp split = (ILongKeyPartOp) sampleParam.getIndicesPart();
long[] nodeIds = split.getKeys();
SampleType sampleType = sampleParam.getSampleType();
switch(sampleType) {
case NODE:
case EDGE:
{
Tuple2<Long2ObjectOpenHashMap<long[]>, Long2ObjectOpenHashMap<int[]>> nodeId2SampleNeighbors = SampleUtils.sampleWithType(row, sampleParam.getCount(), nodeIds, sampleType, System.currentTimeMillis());
return new PartSampleNeighborResultWithType(sampleParam.getPartKey().getPartitionId(), nodeId2SampleNeighbors._1, nodeId2SampleNeighbors._2, sampleType);
}
case NODE_AND_EDGE:
{
Tuple3<Long2ObjectOpenHashMap<long[]>, Long2ObjectOpenHashMap<int[]>, Long2ObjectOpenHashMap<int[]>> nodeId2SampleNeighbors = SampleUtils.sampleWithBothType(row, sampleParam.getCount(), nodeIds, System.currentTimeMillis());
return new PartSampleNeighborResultWithType(sampleParam.getPartKey().getPartitionId(), nodeId2SampleNeighbors._1(), nodeId2SampleNeighbors._2(), nodeId2SampleNeighbors._3());
}
default:
{
throw new UnsupportedOperationException("Not support sample type " + sampleType + " now");
}
}
}
use of com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp in project angel by Tencent.
the class Sample method partitionGet.
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
PartSampleParam param = (PartSampleParam) partParam;
KeyPart keyPart = param.getIndicesPart();
int sampleType = param.getSampleType();
long[] nodeIds = ((ILongKeyPartOp) keyPart).getKeys();
Long2IntOpenHashMap nodeIdToSizes = new Long2IntOpenHashMap(nodeIds.length);
for (int i = 0; i < nodeIds.length; i++) {
nodeIdToSizes.addTo(nodeIds[i], 1);
}
ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
Random r = new Random();
long[] distinctNodeIds = new long[nodeIdToSizes.size()];
long[][] samples = new long[nodeIdToSizes.size()][];
ObjectIterator<Entry> iter = nodeIdToSizes.long2IntEntrySet().fastIterator();
int index = 0;
while (iter.hasNext()) {
Entry entry = iter.next();
distinctNodeIds[index] = entry.getLongKey();
TypeNeighborElement element = (TypeNeighborElement) row.get(distinctNodeIds[index]);
samples[index] = element.Sample(sampleType, r, distinctNodeIds[index], entry.getIntValue());
index++;
}
return new PartGetLongsResult(distinctNodeIds, samples);
}
use of com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp in project angel by Tencent.
the class InitHyperLogLog method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
InitHyperLogLogPartParam param = (InitHyperLogLogPartParam) partParam;
ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
// Get nodes and features
ILongKeyPartOp split = (ILongKeyPartOp) param.getNodes();
long[] nodes = split.getKeys();
int p = param.getP();
int sp = param.getSp();
long seed = param.getSeed();
row.startWrite();
try {
for (int i = 0; i < nodes.length; i++) {
row.set(nodes[i], new HyperLogLogPlusElement(nodes[i], p, sp, seed));
}
} finally {
row.endWrite();
}
}
use of com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp in project angel by Tencent.
the class GetClosenessAndCardinality method partitionGet.
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
GetHyperLogLogPartParam param = (GetHyperLogLogPartParam) partParam;
ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
ILongKeyPartOp keyPart = (ILongKeyPartOp) param.getNodes();
long[] nodes = keyPart.getKeys();
long n = param.getN();
boolean isDirected = param.isDirected();
Long2ObjectOpenHashMap<Tuple3<Double, Long, Long>> closenesses = new Long2ObjectOpenHashMap<>();
for (int i = 0; i < nodes.length; i++) {
HyperLogLogPlusElement hllElem = (HyperLogLogPlusElement) row.get(nodes[i]);
if (isDirected) {
if (hllElem.getCloseness() < n) {
closenesses.put(nodes[i], new Tuple3<>(0d, hllElem.getCardinality(), hllElem.getCloseness()));
} else {
closenesses.put(nodes[i], new Tuple3<>(((double) n / (double) hllElem.getCloseness()), hllElem.getCardinality(), hllElem.getCloseness()));
}
} else {
closenesses.put(nodes[i], new Tuple3<>(((double) hllElem.getCardinality() / (double) hllElem.getCloseness()), hllElem.getCardinality(), hllElem.getCloseness()));
}
}
return new GetClosenessAndCardinalityPartResult(closenesses);
}
Aggregations