use of com.tencent.angel.ml.matrix.RowType in project angel by Tencent.
the class IndexGet method partitionGet.
/**
* Each server partition execute this function and return values of specified index.
*
* @param partParam the partition parameter
* @return values of specified index
*/
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
long startTs = System.currentTimeMillis();
RowBasedPartition part = (RowBasedPartition) psContext.getMatrixStorageManager().getPart(partParam.getMatrixId(), partParam.getPartKey().getPartitionId());
PartitionGetResult result = null;
if (part != null) {
int rowId = ((IndexPartGetParam) partParam).getRowId();
int[] indexes = ((IndexPartGetParam) partParam).getIndexes();
ServerRow row = part.getRow(rowId);
RowType rowType = row.getRowType();
switch(rowType) {
case T_DOUBLE_DENSE:
case T_DOUBLE_SPARSE:
case T_DOUBLE_DENSE_COMPONENT:
case T_DOUBLE_SPARSE_COMPONENT:
{
result = new IndexPartGetDoubleResult(partParam.getPartKey(), ((ServerIntDoubleRow) row).get(indexes));
break;
}
case T_FLOAT_DENSE:
case T_FLOAT_SPARSE:
case T_FLOAT_DENSE_COMPONENT:
case T_FLOAT_SPARSE_COMPONENT:
{
result = new IndexPartGetFloatResult(partParam.getPartKey(), ((ServerIntFloatRow) row).get(indexes));
break;
}
case T_INT_DENSE:
case T_INT_SPARSE:
case T_INT_DENSE_COMPONENT:
case T_INT_SPARSE_COMPONENT:
{
result = new IndexPartGetIntResult(partParam.getPartKey(), ((ServerIntIntRow) row).get(indexes));
break;
}
case T_LONG_DENSE:
case T_LONG_SPARSE:
case T_LONG_DENSE_COMPONENT:
case T_LONG_SPARSE_COMPONENT:
{
result = new IndexPartGetLongResult(partParam.getPartKey(), ((ServerIntLongRow) row).get(indexes));
break;
}
default:
throw new UnsupportedOperationException("Unsupport operation: update " + rowType + " to " + this.getClass().getName());
}
}
LOG.debug("Partition get use time=" + (System.currentTimeMillis() - startTs) + " ms");
return result;
}
use of com.tencent.angel.ml.matrix.RowType in project angel by Tencent.
the class PartitionGetRowResult method deserialize.
@Override
public void deserialize(ByteBuf buf) {
if (buf.readableBytes() == 0) {
rowSplit = null;
return;
}
RowType type = RowType.valueOf(buf.readInt());
rowSplit = ServerRowFactory.createEmptyServerRow(type);
rowSplit.deserialize(buf);
}
use of com.tencent.angel.ml.matrix.RowType in project angel by Tencent.
the class PartitionGetRowsResult method deserialize.
@Override
public void deserialize(ByteBuf buf) {
int size = buf.readInt();
rowSplits = new ArrayList<ServerRow>(size);
for (int i = 0; i < size; i++) {
RowType type = RowType.valueOf(buf.readInt());
ServerRow rowSplit = ServerRowFactory.createEmptyServerRow(type);
rowSplit.deserialize(buf);
rowSplits.add(rowSplit);
}
}
use of com.tencent.angel.ml.matrix.RowType in project angel by Tencent.
the class MatrixClientImpl method generateEmptyVec.
private Vector generateEmptyVec(int rowId) {
MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
RowType rowType = matrixMeta.getRowType();
Vector vector;
if (rowType.isInt()) {
if (rowType.isLongKey())
vector = VFactory.sparseLongKeyIntVector(0, 0);
else
vector = VFactory.sparseIntVector(0, 0);
} else if (rowType.isLong()) {
if (rowType.isLongKey())
vector = VFactory.sparseLongKeyLongVector(0, 0);
else
vector = VFactory.sparseLongVector(0, 0);
} else if (rowType.isFloat()) {
if (rowType.isLongKey())
vector = VFactory.sparseLongKeyFloatVector(0, 0);
else
vector = VFactory.sparseFloatVector(0, 0);
} else if (rowType.isDouble()) {
if (rowType.isLongKey())
vector = VFactory.sparseLongKeyDoubleVector(0, 0);
else
vector = VFactory.sparseDoubleVector(0, 0);
} else {
throw new AngelException("Unsupport row type");
}
vector.setRowId(rowId);
vector.setMatrixId(matrixId);
return vector;
}
use of com.tencent.angel.ml.matrix.RowType in project angel by Tencent.
the class VectorStorageUtils method deserialize.
public static Vector deserialize(ByteBuf buf) {
// Row type
RowType rowType = RowType.valueOf(buf.readInt());
// Storage method
StorageMethod storageMethod = StorageMethod.valuesOf(buf.readInt());
// Key type
BasicType keyType = BasicType.valuesOf(buf.readInt());
// Value type
BasicType valueType = BasicType.valuesOf(buf.readInt());
// Vector dim
long dim = buf.readLong();
// Vector length
long len = buf.readLong();
// Init the vector
Vector vector = VectorFactory.getVector(rowType, storageMethod, keyType, valueType, dim, len);
// Vector data
deserializeVector(buf, vector);
return vector;
}
Aggregations