use of com.tencent.angel.exception.InvalidParameterException in project angel by Tencent.
the class GetNeighbors 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<long[]> nodeIdToNeighbors = new Long2ObjectOpenHashMap<>(nodeIds.length);
for (long nodeId : nodeIds) {
if (row.get(nodeId) == null) {
// If node not exist, just skip
continue;
}
long[] neighbors = ((GraphNode) (row.get(nodeId))).getNeighbors();
if (neighbors != null) {
nodeIdToNeighbors.put(nodeId, neighbors);
}
}
return new PartGetNeighborsResult(param.getPartKey().getPartitionId(), nodeIdToNeighbors);
}
default:
{
// TODO: support String, Int, and Any type node id
throw new InvalidParameterException("Unsupport index type " + keyPart.getKeyType());
}
}
}
use of com.tencent.angel.exception.InvalidParameterException in project angel by Tencent.
the class GetLabels 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();
ServerLongFloatRow row = (ServerLongFloatRow) psContext.getMatrixStorageManager().getRow(param.getPartKey(), 0);
LongArrayList keys = new LongArrayList();
FloatArrayList vals = new FloatArrayList();
for (int i = 0; i < nodeIds.length; i++) {
if (row.exist(nodeIds[i])) {
keys.add(nodeIds[i]);
vals.add(row.get(nodeIds[i]));
}
}
return new GetLabelsPartResult(keys.toLongArray(), vals.toFloatArray());
}
default:
{
// TODO: support String, Int, and Any type node id
throw new InvalidParameterException("Unsupport index type " + keyPart.getKeyType());
}
}
}
use of com.tencent.angel.exception.InvalidParameterException in project angel by Tencent.
the class ModelContextUtils method createMatrixContext.
public static MatrixContext createMatrixContext(ModelContext context, String name, RowType rowType, Class<? extends IElement> elemClass, int rowNum) {
if (rowType.isComplexValue() && elemClass == null) {
throw new InvalidParameterException("Complex value type must set element class type");
}
MatrixContext mc = new MatrixContext();
mc.setName(name);
mc.setRowNum(rowNum);
mc.setRowType(rowType);
mc.setPartitionNum(context.getPartitionNum());
mc.setValidIndexNum(context.getNodeNum());
if (elemClass != null) {
mc.setValueType(elemClass);
}
if (context.isUseHashPartition()) {
mc.setPartitionerClass(HashPartitioner.class);
} else {
mc.setIndexStart(context.getMinNodeId());
mc.setIndexEnd(context.getMaxNodeId());
mc.setPartitionerClass(ColumnRangePartitioner.class);
if (context.getPartitionNum() > 0) {
mc.setMaxRowNumInBlock(1);
mc.setMaxColNumInBlock((context.getMaxNodeId() - context.getMinNodeId()) / context.getPartitionNum());
}
}
return mc;
}
use of com.tencent.angel.exception.InvalidParameterException in project angel by Tencent.
the class ModelContextUtils method createMatrixContext.
public static MatrixContext createMatrixContext(ModelContext context, RowType rowType, Class<? extends IElement> elemClass, int rowNum) {
if (rowType.isComplexValue() && elemClass == null) {
throw new InvalidParameterException("Complex value type must set element class type");
}
MatrixContext mc = new MatrixContext();
mc.setName(context.getModelName());
mc.setRowNum(rowNum);
mc.setRowType(rowType);
mc.setPartitionNum(context.getPartitionNum());
mc.setValidIndexNum(context.getNodeNum());
if (elemClass != null) {
mc.setValueType(elemClass);
}
if (context.isUseHashPartition()) {
mc.setPartitionerClass(HashPartitioner.class);
} else {
mc.setIndexStart(context.getMinNodeId());
mc.setIndexEnd(context.getMaxNodeId());
mc.setPartitionerClass(ColumnRangePartitioner.class);
if (context.getPartitionNum() > 0) {
mc.setMaxRowNumInBlock(rowNum);
mc.setMaxColNumInBlock((context.getMaxNodeId() - context.getMinNodeId()) / context.getPartitionNum());
}
}
return mc;
}
use of com.tencent.angel.exception.InvalidParameterException in project angel by Tencent.
the class MatrixClientFactory method get.
/**
* Get a matrix client.
*
* @param matrixId matrix id
* @param taskId task id
* @return MatrixClient matrix client
* @throws InvalidParameterException matrix does not exist
*/
public static MatrixClient get(int matrixId, int taskId) throws InvalidParameterException {
if (!PSAgentContext.get().getMatrixMetaManager().exist(matrixId)) {
throw new InvalidParameterException("matrix with id " + matrixId + " does not exist.");
}
Key key = new Key(matrixId, taskId);
MatrixClient client = cacheClients.get(key);
if (client == null) {
try {
cacheClients.putIfAbsent(key, buildClient(matrixId, taskId, type));
} catch (Exception x) {
throw new InvalidParameterException("Invalid matrix client type:" + type.getClass().getName() + ", " + x.getMessage());
}
client = cacheClients.get(key);
}
return client;
}
Aggregations